From 7cfd8f2ccadc17b87a29428babf1ee5320efbc71 Mon Sep 17 00:00:00 2001 From: jack11wagner Date: Fri, 14 Jan 2022 13:54:03 -0500 Subject: [PATCH 1/7] Changes to hue_sms python files --- requirements.txt | 3 ++- src/hue_flask.py | 60 +++++++++++++++++++++++++++++++++------------- src/plotlydash.py | 53 ++++++++++++++++++++++------------------ src/qr_code.jpg | Bin 0 -> 18930 bytes 4 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 src/qr_code.jpg diff --git a/requirements.txt b/requirements.txt index 3046fcd..ede9d23 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ dash_html_components datetime pandas Dynaconf -thefuzz[speedup] \ No newline at end of file +thefuzz[speedup] +Pillow \ No newline at end of file diff --git a/src/hue_flask.py b/src/hue_flask.py index 6e395c9..420bb9d 100644 --- a/src/hue_flask.py +++ b/src/hue_flask.py @@ -2,26 +2,36 @@ from rgbxy import Converter from twilio.twiml.messaging_response import MessagingResponse from flask import Flask, request - from getRedisColor import getColor from hue_controller import HueController from name_converter import clean_name -from data_writer import writeFile,color_percent,mostRecentColors,numOfEachColor,invalidColors,first_entry_date -import random -import logging -import redis +from data_writer import writeFile, color_percent, mostRecentColors, numOfEachColor, invalidColors, first_entry_date +import random, logging, redis from fuzzyColors import getFuzzyColor +from PIL import ImageColor -logging.basicConfig(level=logging.INFO,filename="hue_log.log", - format="%(asctime)s:%(levelname)s:%(message)s" ) +logging.basicConfig(level=logging.INFO, filename="hue_log.log", + format="%(asctime)s:%(levelname)s:%(message)s") app = Flask(__name__) controller = HueController() file = "data.csv" +def HEX_to_RGB(hexcode_color): + try: + r, g, b = ImageColor.getcolor(hexcode_color, 'RGB') + rgb_string = str(r) + ',' + str(g) + ',' + str(b) + return rgb_string + except ValueError: + return None + + def convert(rgb_values): - (r, g, b) = rgb_values.decode("utf-8").split(',') + if type(rgb_values) != str: + (r, g, b) = rgb_values.decode("utf-8").split(',') + else: + (r, g, b) = rgb_values.split(',') r = int(r) g = int(g) b = int(b) @@ -38,20 +48,28 @@ def convert(rgb_values): return x, y, saturation_val +def get_colors_list_from_redis(database): + list_of_colors = [] + for color in database.hgetall('color_totals').keys(): + color = color.decode('utf-8') + list_of_colors.append(color) + return list_of_colors + + @app.route('/', methods=['POST', 'GET']) def set_color(): is_random = False is_Fuzzy = False + is_Hex = False database = redis.Redis(host='localhost', port=6379, db=0) - list_of_colors = [] - for color in database.hgetall('color_totals').keys(): - color = color.decode('utf-8') - list_of_colors.append(color) + list_of_colors = get_colors_list_from_redis(database) phone_number = request.values.get('From', None) - color_name = request.values.get('Body', None) - color_name = clean_name(color_name) + unclean_color_name = request.values.get('Body', None) + if unclean_color_name.startswith("#"): + is_Hex = True + color_name = clean_name(unclean_color_name) if color_name == "black": response = MessagingResponse() @@ -85,7 +103,6 @@ def set_color(): color_sum = int(database.get('color_sum').decode('utf-8'), base=10) random_int = random.randint(1, color_sum) color_name = list_of_colors[random_int] - database.hincrby('color_totals', 'random', 1) database.incr('total', 1) else: @@ -100,7 +117,11 @@ def set_color(): database.hincrby('color_totals', color_name, 1) database.incr('total', 1) - rgb_values = getColor(color_name) + if is_Hex: + rgb_values = HEX_to_RGB(unclean_color_name) + + else: + rgb_values = getColor(color_name) if rgb_values is None: logging.info("Color " + color_name + " was not recognized") @@ -120,6 +141,9 @@ def set_color(): elif is_Fuzzy: message = "We found a color similar to what you requested... The light was changed to the color \"{}\"".format( clean_name(color_name)) + elif is_Hex: + message = "You requested a Hex Color... The light was changed to the Hex \"{}\"".format( + unclean_color_name) else: message = "The light was changed to the color \"{}\"." \ .format(clean_name(color_name)) @@ -131,6 +155,10 @@ def set_color(): if is_random: color_name = 'random' + if is_Hex: + response = MessagingResponse() + response.message(message) + return str(response) percent = color_percent(color_name) writeFile(file, str(phone_number), str(color_name), str(message)) diff --git a/src/plotlydash.py b/src/plotlydash.py index 0eb5b67..dd4fb2f 100644 --- a/src/plotlydash.py +++ b/src/plotlydash.py @@ -1,12 +1,14 @@ import dash -import dash_core_components as dcc -import dash_html_components as html +from dash import dcc +from dash import html import plotly.express as px import redis from dash.dependencies import Input, Output import pandas as pd from datetime import datetime import plotly.graph_objects as go +from PIL import Image + external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] @@ -63,15 +65,15 @@ def setup(): labels, sizes, colors = [], [], [] for key in color_totals_dict: - if color_totals_dict[key] > 0: + if color_totals_dict[key] > 2: ## I originally had this at 0 but we have too many color responses at just 1 response, this overcrowds our graph labels.append(key.title()) sizes.append(color_totals_dict[key]) colors.append(key.title()) - fig = px.pie(names=labels, values=sizes, color=labels, color_discrete_map=color_RGB_dict, width=1200, height=600) - + fig = px.pie(names=labels, values=sizes, color=labels, color_discrete_map=color_RGB_dict, width=1750, height=700) df = pd.DataFrame(get_responsesDict('data.csv')) layout = go.Layout( + autosize = True, width=1000, height=1000, ) @@ -82,25 +84,22 @@ def setup(): align='left' ), cells=dict( - values=[df.Time, df['Last 4 Digits'], df.Color] - - )) + values=[df['Time'], df['Last 4 Digits'], df['Color']])) ], layout=layout) app.layout = html.Div(children=[ html.Div([ html.Div([html.H1(children='Moravian Color Choices'), - html.Div(children=''' - Text a color to the number 857-320-3440 and the light will change - ''', style={'color': 'black', 'fontSize': 22} + html.Div(children='''Text a color to the number 484-895-1386 or scan the QR Code below and the light will change''', + style={'color': 'black', 'fontSize': 24} ), - html.Div(children='''* Text 'options' for all hue light functions - ''', style={'color': 'black', 'fontSize': 18}), - html.Div(children='''* Text 'colors list' for all crayola colors - ''', style={'color': 'black', 'fontSize': 18}), - html.Div(children='''* Text 'random' for random color - ''', style={'color': 'black', 'fontSize': 18}), + html.Div(children='''* Text 'options' for all hue light functions''', + style={'color': 'black', 'fontSize': 20}), + html.Div(children='''* Text 'colors list' for all crayola colors''', + style={'color': 'black', 'fontSize': 20}), + html.Div(children='''* Text 'random' for random color''', + style={'color': 'black', 'fontSize': 20}), dcc.Graph( id='colors-graph', figure=fig @@ -144,7 +143,7 @@ def update_graph_live(n): labels, sizes, colors = [], [], [] for key in color_totals_dict: - if (color_totals_dict[key] > 0): + if color_totals_dict[key] > 0: ## I originally had this at 0 but we have too many color responses at just 1 response, this overcrowds our graph labels.append(key.title()) sizes.append(color_totals_dict[key]) colors.append(key.title()) @@ -161,6 +160,7 @@ def update_graph_live(n): Input('table-interval', 'n_intervals')) def update_table_live(n): df = pd.DataFrame(get_responsesDict('data.csv')) + qr_image = Image.open("qr_code.jpg") table = go.Figure(data=[go.Table( header=dict( values=["Time", "Last 4 Digits", "Color"], @@ -170,20 +170,27 @@ def update_table_live(n): values=[df.Time, df['Last 4 Digits'], df.Color], # change column cell height 30 for Monitors, default for Computer height = 30 - )) ]) table.update_layout(title='Recent Color Choices', title_x =.5, title_y=.93,font=dict( # change Font size for Table size=15 ), margin = dict(b=1)) + table.add_layout_image( + dict( + source="https://www.moravian.edu/themes/modern/dist/images/logo.svg", + x=.97, y=0.35, + sizex=0.58, sizey=0.4, + xanchor="right", yanchor="bottom", + layer='above' + )) table.add_layout_image( dict( - source="https://www.moravian.edu/themes/modern/dist/images/logo.svg", - x=.75, y=0.3, - sizex=0.5, sizey=0.35, + source=qr_image, + x=.32, y=0.28, + sizex=0.40, sizey=0.30, xanchor="right", yanchor="bottom", - layer='below' + layer='above' ) ) return table diff --git a/src/qr_code.jpg b/src/qr_code.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0dde8376df7dfdcdc8b336914ec323a2131541da GIT binary patch literal 18930 zcmbVUc_3BW+dju!QB(>UO9~BUO^C{n&|pXr6&VwmB2#qLEkz_nLg^}mlm?Zdk~vC} zN{A3;mYHwuz4ku#K2F{H``r77bI#sty~Fc7@3VH8{4m)-;ohpLqe-DsDHJOBk1{zy z5!rO)u=7!CS66E*(F0zh_RiKeE00BB8}nOP5M1$SG{zY(}Ns&+`9UVDdSIhl9F;x`LUy zn8L(EW#*wyzN83%44A1%F0?Opju~t$tdk!p9PsVjJlaRJZR)RGk)&35>^cpLNLBXyRiKI+DN zWUaD3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an 2022 14:15:51 -0500 Subject: [PATCH 2/7] Changes to hue_sms python files --- src/fuzzyColors.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/fuzzyColors.py b/src/fuzzyColors.py index 7d70cd6..046b2a2 100644 --- a/src/fuzzyColors.py +++ b/src/fuzzyColors.py @@ -1,14 +1,19 @@ from thefuzz import fuzz, process -import pandas as pd +import redis -colors_list = pd.read_csv('colors.csv', names=['Color', 'R', 'G', 'B']) +redis = redis.Redis(host='localhost', port=6379, db=0) +colors_list = [] +for color in redis.hgetall('color_totals').keys(): + color = color.decode('utf-8') + colors_list.append(color) def getFuzzyColor(color_name): # we want a 85% match for thefuzz - fuzzyMatch = process.extractOne(color_name.title(), colors_list['Color'], scorer=fuzz.token_sort_ratio) + fuzzyMatch = process.extractOne(color_name.title(), colors_list, scorer=fuzz.token_sort_ratio) fuzz_color, percent_match = fuzzyMatch[0], fuzzyMatch[1] if percent_match >= 85: return fuzz_color else: return None + From 86cc994e10a75ad9f089776617d4ddd6bb2305bd Mon Sep 17 00:00:00 2001 From: Jack Wagner Date: Sun, 9 Oct 2022 22:47:40 -0400 Subject: [PATCH 3/7] Added rainbow light show functionality --- src/hue_flask.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/hue_flask.py b/src/hue_flask.py index ca30c0a..d87d16f 100644 --- a/src/hue_flask.py +++ b/src/hue_flask.py @@ -1,3 +1,5 @@ +import time + from phue import PhueException from rgbxy import Converter from twilio.twiml.messaging_response import MessagingResponse @@ -10,8 +12,8 @@ from fuzzyColors import getFuzzyColor from PIL import ImageColor -logging.basicConfig(level=logging.INFO,filename="hue_log.log", - format="%(asctime)s:%(levelname)s:%(message)s" ) +logging.basicConfig(level=logging.INFO, filename="hue_log.log", + format="%(asctime)s:%(levelname)s:%(message)s") app = Flask(__name__) controller = HueController() @@ -61,6 +63,8 @@ def set_color(): is_random = False is_Fuzzy = False is_Hex = False + is_Rainbow = True + database = redis.Redis(host='localhost', port=6379, db=0) list_of_colors = get_colors_list_from_redis(database) @@ -71,6 +75,40 @@ def set_color(): is_Hex = True color_name = clean_name(unclean_color_name) + if color_name == "rainbow": + # Adds short rainbow sequence capability for a few seconds + is_Rainbow = True + total_time = 5 # in seconds + transitionTime = .25 # in seconds + maxHue = 65535 + hueIncrement = maxHue / total_time + try: + controller.connect() + except PhueException: + logging.info("Server unable to connect to the Hue Light") + response = MessagingResponse() + response.message("Server unable to connect to the Hue Light") + return str(response) + light = controller.light + light.transitiontime = transitionTime * 10 + light.brightness = 254 + light.saturation = 254 + # light.on = True # uncomment to turn all lights on + + hue = 0 + currTime = time.time() + elapsed_time = time.time() - currTime + + while elapsed_time < total_time: + light.hue = hue + hue = (hue + hueIncrement) % maxHue + time.sleep(transitionTime) + elapsed_time = time.time() - currTime + + response = MessagingResponse() + response.message("Did you enjoy the rainbow light show?") + return str(response) + if color_name == "black": response = MessagingResponse() response.message("Haha... please use a color that contains light.") @@ -135,6 +173,8 @@ def set_color(): controller.light.xy = (x, y) controller.light.saturation = saturation_val logging.info("The light was changed to the color " + color_name) + if is_Rainbow: + message = "Did you enjoy the rainbow light show?" if is_random: message = "The light was changed to the color \"{}\". Random was used." \ .format(clean_name(color_name)) @@ -144,6 +184,7 @@ def set_color(): elif is_Hex: message = "You requested a Hex Color... The light was changed to the Hex \"{}\"".format( unclean_color_name) + else: message = "The light was changed to the color \"{}\"." \ .format(clean_name(color_name)) From af5db376999d65d5b6f91968459bf8a3768a4403 Mon Sep 17 00:00:00 2001 From: Jack Wagner Date: Sun, 9 Oct 2022 23:01:23 -0400 Subject: [PATCH 4/7] Increased rainbow light show timer to 15 seconds --- src/hue_flask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hue_flask.py b/src/hue_flask.py index 3bc3bbd..967f8c7 100644 --- a/src/hue_flask.py +++ b/src/hue_flask.py @@ -78,7 +78,7 @@ def set_color(): if color_name == "rainbow": # Adds short rainbow sequence capability for a few seconds is_Rainbow = True - total_time = 5 # in seconds + total_time = 15 # in seconds transitionTime = .25 # in seconds maxHue = 65535 hueIncrement = maxHue / total_time From 7b3bc4f05938cff88704d03eb77af3d9357f84b7 Mon Sep 17 00:00:00 2001 From: Jack Wagner Date: Wed, 12 Oct 2022 08:05:43 -0400 Subject: [PATCH 5/7] Small syntax changes --- src/hue_flask.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hue_flask.py b/src/hue_flask.py index 967f8c7..a23124b 100644 --- a/src/hue_flask.py +++ b/src/hue_flask.py @@ -99,7 +99,6 @@ def set_color(): hue = 0 currTime = time.time() elapsed_time = time.time() - currTime - while elapsed_time < total_time: light.hue = hue hue = (hue + hueIncrement) % maxHue From 679a773c17a4a74ba5629ffcdd7cbe81f76848f1 Mon Sep 17 00:00:00 2001 From: Jack Wagner Date: Wed, 12 Oct 2022 08:39:22 -0400 Subject: [PATCH 6/7] Adds rainbow sequence feature to hue light options --- src/fuzzyColors.py | 1 - src/hue_flask.py | 1 - src/plotlydash.py | 35 ++++++++++++++++++++++------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/fuzzyColors.py b/src/fuzzyColors.py index 046b2a2..65039ac 100644 --- a/src/fuzzyColors.py +++ b/src/fuzzyColors.py @@ -16,4 +16,3 @@ def getFuzzyColor(color_name): return fuzz_color else: return None - diff --git a/src/hue_flask.py b/src/hue_flask.py index a23124b..1c8be0e 100644 --- a/src/hue_flask.py +++ b/src/hue_flask.py @@ -1,5 +1,4 @@ import time - from phue import PhueException from rgbxy import Converter from twilio.twiml.messaging_response import MessagingResponse diff --git a/src/plotlydash.py b/src/plotlydash.py index 1c00949..13dd79f 100644 --- a/src/plotlydash.py +++ b/src/plotlydash.py @@ -1,6 +1,6 @@ import dash -from dash import dcc -from dash import html +import dash_core_components as dcc +import dash_html_components as html import plotly.express as px import redis from dash.dependencies import Input, Output @@ -64,15 +64,15 @@ def setup(): labels, sizes, colors = [], [], [] for key in color_totals_dict: - if color_totals_dict[key] > 2: ## I originally had this at 0 but we have too many color responses at just 1 response, this overcrowds our graph + if color_totals_dict[key] > 0: labels.append(key.title()) sizes.append(color_totals_dict[key]) colors.append(key.title()) - fig = px.pie(names=labels, values=sizes, color=labels, color_discrete_map=color_RGB_dict, width=1750, height=700) + fig = px.pie(names=labels, values=sizes, color=labels, color_discrete_map=color_RGB_dict, width=1200, height=600) + df = pd.DataFrame(get_responsesDict('data.csv')) layout = go.Layout( - autosize = True, width=1000, height=1000, ) @@ -83,18 +83,25 @@ def setup(): align='left' ), cells=dict( - values=[df['Time'], df['Last 4 Digits'], df['Color']])) + values=[df.Time, df['Last 4 Digits'], df.Color] + + )) ], layout=layout) app.layout = html.Div(children=[ html.Div([ html.Div([html.H1(children='Moravian Color Choices'), - html.Div(children='''* Text 'options' for all hue light functions''', - style={'color': 'black', 'fontSize': 20}), - html.Div(children='''* Text 'colors list' for all crayola colors''', - style={'color': 'black', 'fontSize': 20}), - html.Div(children='''* Text 'random' for random color''', - style={'color': 'black', 'fontSize': 20}), + + html.Div(children=''' + Text a color to the number 484-895-1386 and the light will change + ''', style={'color': 'black', 'fontSize': 22} + ), + html.Div(children='''* Text 'options' for all hue light functions + ''', style={'color': 'black', 'fontSize': 18}), + html.Div(children='''* Text 'colors list' for all crayola colors + ''', style={'color': 'black', 'fontSize': 18}), + html.Div(children='''* Text 'random' for random color + ''', style={'color': 'black', 'fontSize': 18}), dcc.Graph( id='colors-graph', figure=fig @@ -138,7 +145,7 @@ def update_graph_live(n): labels, sizes, colors = [], [], [] for key in color_totals_dict: - if color_totals_dict[key] > 0: ## I originally had this at 0 but we have too many color responses at just 1 response, this overcrowds our graph + if (color_totals_dict[key] > 0): labels.append(key.title()) sizes.append(color_totals_dict[key]) colors.append(key.title()) @@ -182,6 +189,8 @@ def update_table_live(n): table.add_layout_image( dict( source=qr_image, + x=.38, y=0.28, + sizex=0.4, sizey=0.3, xanchor="right", yanchor="bottom", layer='above' ) From 002a0332535f65526e5821508b0385a5c26ab8be Mon Sep 17 00:00:00 2001 From: Jack Wagner <78323388+jack11wagner@users.noreply.github.com> Date: Wed, 12 Oct 2022 08:42:53 -0400 Subject: [PATCH 7/7] Delete testHue_Flask.py --- tests/testHue_Flask.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 tests/testHue_Flask.py diff --git a/tests/testHue_Flask.py b/tests/testHue_Flask.py deleted file mode 100644 index cb788e8..0000000 --- a/tests/testHue_Flask.py +++ /dev/null @@ -1,11 +0,0 @@ -from hue_flask import HEX_to_RGB - -def testKnownHexConvertsToRGB(): - test_hex_code = '#9C59D1' - - assert '156,89,209' == HEX_to_RGB(test_hex_code) - -def testUnknownHexReturnsNone(): - test_hex_code = "#NONE" - - assert None == HEX_to_RGB(test_hex_code) \ No newline at end of file