Skip to content

Commit

Permalink
add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
lephanthuymai committed Feb 6, 2021
1 parent b4b9aff commit deb59b4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions src/python/components/left_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


class left_panel(panel):
"""handle all activities of the left panel"""

def __init__(self, datamodel):
super().__init__("Global", datamodel)

Expand Down Expand Up @@ -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"),
Expand All @@ -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)
Expand All @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions src/python/components/mid_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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})
)
Expand All @@ -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()
Expand Down
22 changes: 22 additions & 0 deletions src/python/components/right_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


class right_panel(panel):
"""handle all activities related to country panel"""

def __init__(self, datamodel):
super().__init__("Country", datamodel)

Expand Down Expand Up @@ -102,13 +104,23 @@ 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(),
value="Canada",
)

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"),
Expand All @@ -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"
Expand Down

0 comments on commit deb59b4

Please sign in to comment.