From deb59b4d57df4eeae5108f41141cc898fe21da15 Mon Sep 17 00:00:00 2001 From: Mai Le Date: Sat, 6 Feb 2021 14:23:45 +0700 Subject: [PATCH] add docstrings --- src/python/app.py | 3 +++ src/python/components/left_panel.py | 21 +++++++++++++++++++++ src/python/components/mid_panel.py | 13 +++++++------ src/python/components/right_panel.py | 22 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/python/app.py b/src/python/app.py index a0df446..2d7e080 100644 --- a/src/python/app.py +++ b/src/python/app.py @@ -87,6 +87,7 @@ Input("rp_btn_new", "n_clicks"), ) def update_right_panel(country, total_click, new_click): + """update the right panel when changes triggered by its controls""" ctx = dash.callback_context if not ctx.triggered: ntype = "Total" @@ -110,6 +111,7 @@ def update_right_panel(country, total_click, new_click): Input("btn_recovered", "n_clicks"), ) def update_left_panel(active, confirmed, death, recovered): + """update all components on the left panel upon callback""" ctx = dash.callback_context if not ctx.triggered: ctype = "confirmed" @@ -135,6 +137,7 @@ def update_left_panel(active, confirmed, death, recovered): Input("wm_recovered", "n_clicks"), ) def update_mid_panel(confirmed, death, recovered): + """update all controls on mid panel upon callback""" ctx = dash.callback_context if not ctx.triggered: ctype = "confirmed" diff --git a/src/python/components/left_panel.py b/src/python/components/left_panel.py index 18fb21a..7fc07e1 100644 --- a/src/python/components/left_panel.py +++ b/src/python/components/left_panel.py @@ -20,6 +20,8 @@ class left_panel(panel): + """handle all activities of the left panel""" + def __init__(self, datamodel): super().__init__("Global", datamodel) @@ -76,6 +78,11 @@ def refresh(self, chart_type="confirmed"): return chart def __create_button_groups(self): + """create buttons Confirmed/Death/Recovered/Active + + Returns: + dbc.ButtonGroup + """ button_groups = dbc.ButtonGroup( [ dbc.Button("Confirmed", active=True, id="btn_confirmed"), @@ -89,6 +96,11 @@ def __create_button_groups(self): return button_groups def __create_total_statistics(self): + """retrieve global statistics + + Returns: + html: all statistics + """ data = self.data_reader.cumulative_filter() confirmed_cases = panel.format_number(data.Confirmed) active_cases = panel.format_number(data.Active) @@ -106,6 +118,15 @@ def __create_total_statistics(self): return content def __create_ranking_bar_chart(self, data, type): + """create bar chart to rank countries by case type + + Args: + data (dataframe): dataset + type (string): "confirmed", "death", "recovered + + Returns: + altair barchart + """ chart = ( alt.Chart( data, diff --git a/src/python/components/mid_panel.py b/src/python/components/mid_panel.py index aa5e592..f6e538c 100644 --- a/src/python/components/mid_panel.py +++ b/src/python/components/mid_panel.py @@ -21,6 +21,8 @@ class mid_panel(panel): + """handle all activities related to world map panel""" + def __init__(self, datamodel): super().__init__("World Map", datamodel) @@ -92,11 +94,11 @@ def refresh(self, chart_type="confirmed", ntype="Total"): return world_map, trend_chart def __create_button_groups(self): - """Create button + """Create button Returns: buttons for three cases - """ + """ button_groups = dbc.ButtonGroup( [ dbc.Button("Confirmed", active=True, id="wm_confirmed"), @@ -125,7 +127,7 @@ def __create_world_map_chart(self, data, type): base = ( alt.Chart(source, title="") .mark_geoshape(fill="lightgray", stroke="white") - .properties(width=860, height=450 ) + .properties(width=860, height=450) .project("equirectangular") # .padding({"left": 0, "right": 0, "bottom": 1, "top":1}) ) @@ -151,9 +153,8 @@ def __create_world_map_chart(self, data, type): ) chart = base + points - chart = ( - chart.configure_legend(orient="bottom") - .configure_view(strokeWidth=0, ) + chart = chart.configure_legend(orient="bottom").configure_view( + strokeWidth=0, ) return chart.to_html() diff --git a/src/python/components/right_panel.py b/src/python/components/right_panel.py index 4d6c05a..13b8631 100644 --- a/src/python/components/right_panel.py +++ b/src/python/components/right_panel.py @@ -19,6 +19,8 @@ class right_panel(panel): + """handle all activities related to country panel""" + def __init__(self, datamodel): super().__init__("Country", datamodel) @@ -102,6 +104,11 @@ def refresh(self, country, ntype="Total"): return confirmed, recovered, deaths, c_chart, d_chart def __create_country_dropdown(self): + """create a dropdown list to select country + + Returns: + dcc.Dropdown + """ return dcc.Dropdown( id="dd_country", options=self.data_reader.get_country_options(), @@ -109,6 +116,11 @@ def __create_country_dropdown(self): ) def __create_button_groups(self): + """create Total | New buttons + + Returns: + dbc.ButtonGroup: group of buttons + """ button_groups = dbc.ButtonGroup( [ dbc.Button("Total", active=True, id="rp_btn_total"), @@ -120,6 +132,16 @@ def __create_button_groups(self): return button_groups def __create_timeserie_chart(self, country, case_type=1, ntype="Total"): + """create trend chart showing cases of a country + + Args: + country (string): country name + case_type (int, optional): 1: confirmed, 2: death, 3: recovered. Defaults to 1. + ntype (str, optional): "Total" or "New". Defaults to "Total". + + Returns: + chart: altair chart object + """ data = self.data_reader.get_timeserie_data_by_country(country, case_type) if case_type == 1: chart_title = "Cases over time"