From 95448f50fc840e7f5b33a83c8c5c6a21c0ac8eb6 Mon Sep 17 00:00:00 2001 From: Yi Heng Joshua Wu Date: Wed, 1 Jun 2022 13:52:30 -0700 Subject: [PATCH 01/11] Resolve Issue #1064 to keep Request Type Color consistent across dashboards --- server/dash/dashboards/neighborhood.py | 2 ++ server/dash/dashboards/neighborhood_recent.py | 5 +++- server/dash/dashboards/overview.py | 28 +++++++++++++++++-- server/dash/dashboards/recent.py | 5 +++- server/dash/design.py | 20 ++++++++++++- 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/server/dash/dashboards/neighborhood.py b/server/dash/dashboards/neighborhood.py index 3dd670d1b..a6a1fff79 100644 --- a/server/dash/dashboards/neighborhood.py +++ b/server/dash/dashboards/neighborhood.py @@ -12,6 +12,7 @@ from design import apply_figure_style from design import CONFIG_OPTIONS from design import DISCRETE_COLORS +from design import DISCRETE_COLORS_MAP from design import LABELS @@ -90,6 +91,7 @@ def update_council_figure(selected_council): y="counts", color="type_name", color_discrete_sequence=DISCRETE_COLORS, + color_discrete_map = DISCRETE_COLORS_MAP, labels=LABELS, title="Request type trend for " + selected_council ) diff --git a/server/dash/dashboards/neighborhood_recent.py b/server/dash/dashboards/neighborhood_recent.py index ffb6414ac..9ece97e37 100644 --- a/server/dash/dashboards/neighborhood_recent.py +++ b/server/dash/dashboards/neighborhood_recent.py @@ -9,7 +9,7 @@ from app import app, batch_get_data from config import API_HOST from dash.dependencies import Input, Output -from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style +from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style, DISCRETE_COLORS_MAP from flask import request pretty_columns = { @@ -66,6 +66,7 @@ def populate_options(): y="srnumber", color="typeName", color_discrete_sequence=DISCRETE_COLORS, + color_discrete_map = DISCRETE_COLORS_MAP, labels=LABELS, ) @@ -83,7 +84,9 @@ def populate_options(): figure_df, names="typeName", values="srnumber", + color = 'typeName', color_discrete_sequence=DISCRETE_COLORS, + color_discrete_map = DISCRETE_COLORS_MAP, labels=LABELS, hole=.3, ) diff --git a/server/dash/dashboards/overview.py b/server/dash/dashboards/overview.py index cf3c2e449..04e20bc28 100644 --- a/server/dash/dashboards/overview.py +++ b/server/dash/dashboards/overview.py @@ -1,7 +1,9 @@ import textwrap + import dash_core_components as dcc import dash_html_components as html +# from dash import Dash, html, dcc import pandas as pd import plotly.express as px import plotly.graph_objects as go @@ -11,6 +13,13 @@ from design import CONFIG_OPTIONS from design import DISCRETE_COLORS from design import LABELS +from design import DISCRETE_COLORS_MAP + + + +#TODO: Remove this after testing +# app = Dash(__name__) + # TITLE @@ -88,13 +97,18 @@ print(" * Downloading data for dataframe") query_string = "/reports?field=type_name&filter=created_date>=2016-01-01" df3 = pd.read_json(API_HOST + query_string) -df3 = df3.groupby(['type_name'])['counts'].sum().to_frame() -df3.index = df3.index.map(lambda x: '
'.join(textwrap.wrap(x, width=16))) +df3 = df3.groupby(['type_name'], as_index=False)['counts'].sum() +#df3 = df3.groupby(['type_name'])['counts'].sum().to_frame() +#df3.index = df3.index.map(lambda x: '
'.join(textwrap.wrap(x, width=16))) +print(df3['type_name']) +print(" * TESTING IF CHANGES ARE ACTUALLY DEPLOYED ON DOCKER") fig3 = px.pie( df3, - names=df3.index, + names='type_name', values='counts', color_discrete_sequence=DISCRETE_COLORS, + color = 'type_name', + color_discrete_map = DISCRETE_COLORS_MAP, labels=LABELS, hole=.3, title="Total Requests by Type", @@ -134,7 +148,12 @@ apply_figure_style(fig5) apply_figure_style(fig6) + +## CHANGE THIS BACK TO just "layout = html.Div" or layout = html.Div([ + + # LAYOUT +# app.layout = html.Div([ layout = html.Div([ html.H1(title), html.P("The figures below represent the total number of 311 requests made across LA County from 2016-2021. In 2020, we saw an all-time high with more than 1.4 million requests.", style={'padding':'20px', 'font-size':'18px', 'font-style':'italic'}), @@ -186,3 +205,6 @@ responsive=True, ), ]) + +# if __name__ == '__main__': +# app.run_server(debug=True) \ No newline at end of file diff --git a/server/dash/dashboards/recent.py b/server/dash/dashboards/recent.py index c10feedfe..ff98baa64 100644 --- a/server/dash/dashboards/recent.py +++ b/server/dash/dashboards/recent.py @@ -8,7 +8,7 @@ import plotly.graph_objects as go from config import API_HOST -from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style +from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style, DISCRETE_COLORS_MAP # TITLE title = "RECENT 311 REQUESTS" @@ -33,6 +33,7 @@ y="counts", color="type_name", color_discrete_sequence=DISCRETE_COLORS, + color_discrete_map = DISCRETE_COLORS_MAP, labels=LABELS, ) @@ -50,7 +51,9 @@ pie_df, names="type_name", values="counts", + color='type_name', color_discrete_sequence=DISCRETE_COLORS, + color_discrete_map = DISCRETE_COLORS_MAP, labels=LABELS, hole=.3, ) diff --git a/server/dash/design.py b/server/dash/design.py index 11d2482ac..8e8ae4d6c 100644 --- a/server/dash/design.py +++ b/server/dash/design.py @@ -47,6 +47,24 @@ } +# TODO: Fixing multiple streetlights and waterwaste color +# Need to add another discrete color +DISCRETE_COLORS_MAP = { + "Graffiti":"#BF82BA", + "Homeless Encampment":"#11975F", + "Animal Remains":"#267370", + "Bulky Items": "#D05F4E", + "Electronic Waste": "#AE3D51", + "Illegal Dumping": "#685DB1", + "Metal/Appliances": "#8B508B", + "Single Streetlight": "#79B74E", + "Multiple Streetlights": "#EDAD08", + "Water Waste": "#EDAD08", + "Other": "#1D6996", + "Feedback": "#E17C05" +} + + def apply_figure_style(fig): fig.update_layout( @@ -57,7 +75,7 @@ def apply_figure_style(fig): title_yanchor='top', font_family="Roboto, Arial", font_color="#ECECEC", - colorway=DISCRETE_COLORS, + #colorway=DISCRETE_COLORS, margin_l=10, margin_r=10, legend_font_size=11, From 445fbc509e0b51e2a58229ed9d5901c82266f102 Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:22:12 -0700 Subject: [PATCH 02/11] Update server/dash/dashboards/neighborhood_recent.py Co-authored-by: Nicholas Kwon --- server/dash/dashboards/neighborhood_recent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/dash/dashboards/neighborhood_recent.py b/server/dash/dashboards/neighborhood_recent.py index 9ece97e37..9dea66364 100644 --- a/server/dash/dashboards/neighborhood_recent.py +++ b/server/dash/dashboards/neighborhood_recent.py @@ -9,7 +9,7 @@ from app import app, batch_get_data from config import API_HOST from dash.dependencies import Input, Output -from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style, DISCRETE_COLORS_MAP +from design import CONFIG_OPTIONS, DISCRETE_COLORS, DISCRETE_COLORS_MAP, LABELS, apply_figure_style from flask import request pretty_columns = { From 7076ae3b31e4e6baef63dc79c9c0708c08148f91 Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:43:42 -0700 Subject: [PATCH 03/11] Resolve code style consistency issues --- server/dash/dashboards/recent.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/dash/dashboards/recent.py b/server/dash/dashboards/recent.py index ff98baa64..14307828c 100644 --- a/server/dash/dashboards/recent.py +++ b/server/dash/dashboards/recent.py @@ -8,7 +8,7 @@ import plotly.graph_objects as go from config import API_HOST -from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style, DISCRETE_COLORS_MAP +from design import CONFIG_OPTIONS, DISCRETE_COLORS, DISCRETE_COLORS_MAP, LABELS, apply_figure_style # TITLE title = "RECENT 311 REQUESTS" @@ -33,7 +33,7 @@ y="counts", color="type_name", color_discrete_sequence=DISCRETE_COLORS, - color_discrete_map = DISCRETE_COLORS_MAP, + color_discrete_map=DISCRETE_COLORS_MAP, labels=LABELS, ) @@ -51,9 +51,9 @@ pie_df, names="type_name", values="counts", - color='type_name', + color="type_name", color_discrete_sequence=DISCRETE_COLORS, - color_discrete_map = DISCRETE_COLORS_MAP, + color_discrete_map=DISCRETE_COLORS_MAP, labels=LABELS, hole=.3, ) From 30a9e7f16e66af3f8a66a2e653424934a473bf5d Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:50:51 -0700 Subject: [PATCH 04/11] Update overview.py to maintain style consistency --- server/dash/dashboards/overview.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/server/dash/dashboards/overview.py b/server/dash/dashboards/overview.py index 04e20bc28..a2e662d80 100644 --- a/server/dash/dashboards/overview.py +++ b/server/dash/dashboards/overview.py @@ -1,9 +1,7 @@ import textwrap - import dash_core_components as dcc import dash_html_components as html -# from dash import Dash, html, dcc import pandas as pd import plotly.express as px import plotly.graph_objects as go @@ -16,12 +14,6 @@ from design import DISCRETE_COLORS_MAP - -#TODO: Remove this after testing -# app = Dash(__name__) - - - # TITLE title = "311 DATA OVERVIEW" @@ -104,11 +96,11 @@ print(" * TESTING IF CHANGES ARE ACTUALLY DEPLOYED ON DOCKER") fig3 = px.pie( df3, - names='type_name', - values='counts', + names="type_name", + values="counts", color_discrete_sequence=DISCRETE_COLORS, - color = 'type_name', - color_discrete_map = DISCRETE_COLORS_MAP, + color="type_name", + color_discrete_map=DISCRETE_COLORS_MAP, labels=LABELS, hole=.3, title="Total Requests by Type", @@ -153,7 +145,6 @@ # LAYOUT -# app.layout = html.Div([ layout = html.Div([ html.H1(title), html.P("The figures below represent the total number of 311 requests made across LA County from 2016-2021. In 2020, we saw an all-time high with more than 1.4 million requests.", style={'padding':'20px', 'font-size':'18px', 'font-style':'italic'}), @@ -205,6 +196,3 @@ responsive=True, ), ]) - -# if __name__ == '__main__': -# app.run_server(debug=True) \ No newline at end of file From 6e2d894d5971777557866f4a98b81a30d00333be Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:54:40 -0700 Subject: [PATCH 05/11] Update neighborhood.py to resolve stylistic issues --- server/dash/dashboards/neighborhood.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/dash/dashboards/neighborhood.py b/server/dash/dashboards/neighborhood.py index a6a1fff79..f7ec9a2cf 100644 --- a/server/dash/dashboards/neighborhood.py +++ b/server/dash/dashboards/neighborhood.py @@ -91,7 +91,7 @@ def update_council_figure(selected_council): y="counts", color="type_name", color_discrete_sequence=DISCRETE_COLORS, - color_discrete_map = DISCRETE_COLORS_MAP, + color_discrete_map=DISCRETE_COLORS_MAP, labels=LABELS, title="Request type trend for " + selected_council ) From ab0f2cf947f117763ccda3b7f3a9f3eed1b75b2e Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:55:43 -0700 Subject: [PATCH 06/11] Update neighborhood_recent.py to resolve style issues --- server/dash/dashboards/neighborhood_recent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/dash/dashboards/neighborhood_recent.py b/server/dash/dashboards/neighborhood_recent.py index 9dea66364..564e0f4a7 100644 --- a/server/dash/dashboards/neighborhood_recent.py +++ b/server/dash/dashboards/neighborhood_recent.py @@ -84,9 +84,9 @@ def populate_options(): figure_df, names="typeName", values="srnumber", - color = 'typeName', + color="typeName", color_discrete_sequence=DISCRETE_COLORS, - color_discrete_map = DISCRETE_COLORS_MAP, + color_discrete_map=DISCRETE_COLORS_MAP, labels=LABELS, hole=.3, ) From 3a53fe4d6998f66a81d68b189e2442e07478eadb Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:58:30 -0700 Subject: [PATCH 07/11] Update design.py to remove test conditions --- server/dash/design.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/dash/design.py b/server/dash/design.py index 8e8ae4d6c..525d8bad6 100644 --- a/server/dash/design.py +++ b/server/dash/design.py @@ -75,7 +75,7 @@ def apply_figure_style(fig): title_yanchor='top', font_family="Roboto, Arial", font_color="#ECECEC", - #colorway=DISCRETE_COLORS, + colorway=DISCRETE_COLORS, margin_l=10, margin_r=10, legend_font_size=11, From cf5475f439d3c534287d71c947bacf3fbef4ec80 Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 16:07:40 -0700 Subject: [PATCH 08/11] Update neighborhood_recent.py for stylistic issues --- server/dash/dashboards/neighborhood_recent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/dash/dashboards/neighborhood_recent.py b/server/dash/dashboards/neighborhood_recent.py index 564e0f4a7..1912a7f62 100644 --- a/server/dash/dashboards/neighborhood_recent.py +++ b/server/dash/dashboards/neighborhood_recent.py @@ -66,7 +66,7 @@ def populate_options(): y="srnumber", color="typeName", color_discrete_sequence=DISCRETE_COLORS, - color_discrete_map = DISCRETE_COLORS_MAP, + color_discrete_map=DISCRETE_COLORS_MAP, labels=LABELS, ) From 5d68fd787a5c84f4d4b32d2763c5deadcd6c60f9 Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 16:08:47 -0700 Subject: [PATCH 09/11] Update overview.py to remove comments --- server/dash/dashboards/overview.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/dash/dashboards/overview.py b/server/dash/dashboards/overview.py index a2e662d80..795df79ac 100644 --- a/server/dash/dashboards/overview.py +++ b/server/dash/dashboards/overview.py @@ -140,10 +140,6 @@ apply_figure_style(fig5) apply_figure_style(fig6) - -## CHANGE THIS BACK TO just "layout = html.Div" or layout = html.Div([ - - # LAYOUT layout = html.Div([ html.H1(title), From 360961ad7e3d8d5a5dba2a49a6ef7464da099e0c Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 17:49:53 -0700 Subject: [PATCH 10/11] Update overview.py to remove test code --- server/dash/dashboards/overview.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/dash/dashboards/overview.py b/server/dash/dashboards/overview.py index 795df79ac..e4649be46 100644 --- a/server/dash/dashboards/overview.py +++ b/server/dash/dashboards/overview.py @@ -90,10 +90,6 @@ query_string = "/reports?field=type_name&filter=created_date>=2016-01-01" df3 = pd.read_json(API_HOST + query_string) df3 = df3.groupby(['type_name'], as_index=False)['counts'].sum() -#df3 = df3.groupby(['type_name'])['counts'].sum().to_frame() -#df3.index = df3.index.map(lambda x: '
'.join(textwrap.wrap(x, width=16))) -print(df3['type_name']) -print(" * TESTING IF CHANGES ARE ACTUALLY DEPLOYED ON DOCKER") fig3 = px.pie( df3, names="type_name", From 722d3bdf3773bc1b174c1f2e026089472a4b7330 Mon Sep 17 00:00:00 2001 From: joshuayhwu <77765986+joshuayhwu@users.noreply.github.com> Date: Wed, 1 Jun 2022 17:51:05 -0700 Subject: [PATCH 11/11] Update design.py to include type colors --- server/dash/design.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/dash/design.py b/server/dash/design.py index 525d8bad6..5d3d25974 100644 --- a/server/dash/design.py +++ b/server/dash/design.py @@ -48,6 +48,7 @@ # TODO: Fixing multiple streetlights and waterwaste color +# Request Type Color Hex Code Reference: https://github.com/hackforla/311-data/blob/b0717ad25eab4ef25a2f26da187d9d8905ab5f77/server/api/alembic/seeds/types.csv # Need to add another discrete color DISCRETE_COLORS_MAP = { "Graffiti":"#BF82BA",