From a109630be7a2cafbf9862c99d19166093171fc75 Mon Sep 17 00:00:00 2001 From: Lisa Yii Date: Thu, 9 Dec 2021 22:58:40 +0000 Subject: [PATCH] Merge and fix country listing + lower case invalid input in LM_user_data --- LM_geomap_plot.py | 1 + LM_line_datafields.py | 1 + LM_line_life_expectancy.py | 1 + LM_submit_social.py | 9 +++++---- LM_user_algo.py | 35 +++++++++++++++++------------------ LM_user_data.py | 25 +++++++++++++++++++++---- 6 files changed, 46 insertions(+), 26 deletions(-) diff --git a/LM_geomap_plot.py b/LM_geomap_plot.py index 43fd261..923a16a 100644 --- a/LM_geomap_plot.py +++ b/LM_geomap_plot.py @@ -42,6 +42,7 @@ df = df[df["Year"] >= 2000] countries = list(df.index.unique()) +countries.sort() country_options = [{"label": str(val), "value": str(val)} for val in countries] diff --git a/LM_line_datafields.py b/LM_line_datafields.py index 8f9ac55..a80a564 100644 --- a/LM_line_datafields.py +++ b/LM_line_datafields.py @@ -42,6 +42,7 @@ df = df[df["Year"] >= 2000] countries = list(df.index.unique()) +countries.sort() country_options = [{"label": str(val), "value": str(val)} for val in countries] # Year/range slider diff --git a/LM_line_life_expectancy.py b/LM_line_life_expectancy.py index e6031b7..b3144b1 100644 --- a/LM_line_life_expectancy.py +++ b/LM_line_life_expectancy.py @@ -41,6 +41,7 @@ df = df[df["Year"] >= 2000] countries = list(df.index.unique()) +countries.sort() country_options = [{"label": str(val), "value": str(val)} for val in countries] diff --git a/LM_submit_social.py b/LM_submit_social.py index aab8c87..1da0d53 100644 --- a/LM_submit_social.py +++ b/LM_submit_social.py @@ -208,10 +208,11 @@ def mastodon(n_clicks, summary): if n_clicks is None or n_clicks == 0: raise PreventUpdate - - # pass - status_code = post_to_mastodon(toot, tags) - app.logger.info("Tried posting, code = {}".format(status_code)) + else: + #pass + status_code = post_to_mastodon(toot, tags) + app.logger.info("Tried posting, code = {}".format(status_code)) + webbrowser.open(url="https://botsin.space/@deadlineproject",new=2, autoraise=True) return None diff --git a/LM_user_algo.py b/LM_user_algo.py index ce9118c..b71390b 100644 --- a/LM_user_algo.py +++ b/LM_user_algo.py @@ -215,23 +215,22 @@ def generate_stats(dfc, dfu): def start_countdown(target_date): countdown = target_date - datetime.now() +def summarize_data(user_data_local): + # app.logger.info("========user_data_local=====") + # app.logger.info(user_data_local) + # app.logger.info("===========================") + df2 = pd.DataFrame({ + "name": [user_data_local[0]], + "age": [user_data_local[1]], + "birthplace": [user_data_local[2]], + "residence": [user_data_local[3]], + "sex": [user_data_local[4]], + "veggie": [user_data_local[5]], + "driver": [user_data_local[6]], + "smoker": [user_data_local[7]], + },) + -def summarize_data(user_data_local): - app.logger.info("========user_data_local=====") - app.logger.info(user_data_local) - app.logger.info("===========================") - df2 = pd.DataFrame( - { - "name": [user_data_local[0]], - "age": [user_data_local[1]], - "birthplace": [user_data_local[2]], - "residence": [user_data_local[3]], - "sex": [user_data_local[4]], - "veggie": [user_data_local[5]], - "driver": [user_data_local[6]], - "smoker": [user_data_local[7]], - }, - ) data = generate_stats(df1, df2) @@ -422,8 +421,8 @@ def trigger_stats_generation(user_data): Output(component_id="div_submit", component_property="children"), [Input("dccstore_summary", "data"), Input("url", "pathname")], ) -def update_display_summary(summary, urlpath): - app.logger.info(urlpath) +def update_display_summary(summary,urlpath): + # app.logger.info(urlpath) # dynamically add restart/submit based on whether data exists restart = ( dbc.Button( diff --git a/LM_user_data.py b/LM_user_data.py index 42eb830..1c2fe66 100644 --- a/LM_user_data.py +++ b/LM_user_data.py @@ -40,7 +40,9 @@ # leading to nulls everywhere except the last 15 years or so for most cols df = df[df["Year"] >= 2000] + countries = list(df.index.unique()) +countries.sort() country_options = [{"label": str(val), "value": str(val)} for val in countries] # app.logger.info(country_options) @@ -177,6 +179,7 @@ ], ), html.Br(), + html.Div(id="my-output", style={"color":"red", "textAlign":"center"}), html.Div( dbc.Button( id="submit-button-state", @@ -191,11 +194,10 @@ children="Submit", color="Primary", className="me-1", - href="/page1", + href="/page1" ), className="d-grip gap-2 d-md-flex justify-content-md-end", ), - html.Div(id="my-output"), html.Div(id="output_graph"), html.Div(id="output_text", style={"textAlign": "center", "color": "blue"}), ], @@ -208,14 +210,14 @@ def update_options_b(search_value): if not search_value: raise PreventUpdate - return [o for o in country_options if search_value in o["label"]] + return [o for o in country_options if search_value.lower() in o["label"].lower()] @app.callback(Output("residence", "options"), Input("residence", "search_value")) def update_options_r(search_value): if not search_value: raise PreventUpdate - return [o for o in country_options if search_value in o["label"]] + return [o for o in country_options if search_value.lower() in o["label"].lower()] # every selection change will update our dccstore. @@ -258,3 +260,18 @@ def sel_user_data( user_data_local[7] = smoker app.logger.info(user_data_local) return user_data_local + +# @app.callback( +# Output(component_id="my-output", component_property="children"), +# [ +# Input(component_id="submit-button-state", component_property="n_clicks"), +# ], +# ) +# def submit_user_details(n_clicks): +# # if n_clicks == 0: +# # raise PreventUpdate + +# if '' in user_data_local: +# return "Please make sure all fields have been keyed in." +# else: +# return dcc.Location(pathname="/page5", id="my-output")