mirror of
https://github.com/Cronocide/fitbit-web-ui-app.git
synced 2025-01-22 11:29:03 +00:00
Weekly walk heatmap added
This commit is contained in:
parent
756cf96e8a
commit
1dc6f6e6be
18
src/app.py
18
src/app.py
@ -71,6 +71,12 @@ app.layout = html.Div(children=[
|
||||
config= {'displaylogo': False}
|
||||
),
|
||||
|
||||
dcc.Graph(
|
||||
id='graph_steps_heatmap',
|
||||
figure=px.bar(),
|
||||
config= {'displaylogo': False}
|
||||
),
|
||||
|
||||
dcc.Graph(
|
||||
id='graph_activity_minutes',
|
||||
figure=px.bar(),
|
||||
@ -105,7 +111,7 @@ def disable_button_and_calculate(n_clicks):
|
||||
return True, True, True
|
||||
|
||||
# fetch data and update graphs on click of submit
|
||||
@app.callback(Output('report-title', 'children'), Output('date-range-title', 'children'), Output('generated-on-title', 'children'), Output('graph_RHR', 'figure'), Output('graph_steps', 'figure'), Output('graph_activity_minutes', 'figure'), Output('graph_weight', 'figure'), Output('graph_spo2', 'figure'), Output("loading-output-1", "children"),
|
||||
@app.callback(Output('report-title', 'children'), Output('date-range-title', 'children'), Output('generated-on-title', 'children'), Output('graph_RHR', 'figure'), Output('graph_steps', 'figure'), Output('graph_steps_heatmap', 'figure'), Output('graph_activity_minutes', 'figure'), Output('graph_weight', 'figure'), Output('graph_spo2', 'figure'), Output("loading-output-1", "children"),
|
||||
Input('submit-button', 'disabled'),
|
||||
State('input-on-submit', 'value'), State('my-date-picker-range', 'start_date'), State('my-date-picker-range', 'end_date'),
|
||||
prevent_initial_call=True
|
||||
@ -129,7 +135,7 @@ def update_output(n_clicks, value, start_date, end_date):
|
||||
response_spo2 = requests.get("https://api.fitbit.com/1/user/-/spo2/date/"+ start_date +"/"+ end_date +".json", headers=headers).json()
|
||||
|
||||
# Processing data-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
days_name_list = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday')
|
||||
report_title = "Wellness report - " + user_profile["user"]["firstName"] + " " + user_profile["user"]["lastName"]
|
||||
report_dates_range = datetime.fromisoformat(start_date).strftime("%d %B, %Y") + " – " + datetime.fromisoformat(end_date).strftime("%d %B, %Y")
|
||||
generated_on_date = "Report Generated :" + datetime.today().date().strftime("%d %B, %Y")
|
||||
@ -185,7 +191,9 @@ def update_output(n_clicks, value, start_date, end_date):
|
||||
steps_avg = {'overall': round(non_zero_steps_df["Steps Count"].mean(),0), '30d': round(non_zero_steps_df["Steps Count"].tail(30).mean(),0)}
|
||||
weight_avg = {'overall': round(df_merged["weight"].mean(),1), '30d': round(df_merged["weight"].tail(30).mean(),1)}
|
||||
active_mins_avg = {'overall': round(df_merged["Total Active Minutes"].mean(),2), '30d': round(df_merged["Total Active Minutes"].tail(30).mean(),2)}
|
||||
|
||||
weekly_steps_array = np.array([0]*days_name_list.index(datetime.fromisoformat(start_date).strftime('%A')) + df_merged["Steps Count"].to_list() + [0]*(6 - days_name_list.index(datetime.fromisoformat(end_date).strftime('%A'))))
|
||||
weekly_steps_array = np.transpose(weekly_steps_array.reshape((int(len(weekly_steps_array)/7), 7)))
|
||||
weekly_steps_array = pd.DataFrame(weekly_steps_array, index=days_name_list)
|
||||
# Plotting data-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
fig_rhr = px.line(df_merged, x="Date", y="Resting Heart Rate", line_shape="spline", color_discrete_sequence=["#d30f1c"], title=f"<b>Daily Resting Heart Rate<br><br><sup>Overall average : {rhr_avg['overall']} bpm | Last 30d average : {rhr_avg['30d']} bpm</sup></b><br><br><br>")
|
||||
@ -197,6 +205,8 @@ def update_output(n_clicks, value, start_date, end_date):
|
||||
fig_steps.add_annotation(x=df_merged.iloc[df_merged["Steps Count"].idxmax()]["Date"], y=df_merged["Steps Count"].max(), text=str(df_merged["Steps Count"].max())+" steps", showarrow=False, arrowhead=0, bgcolor="#5f040a", opacity=0.80, yshift=15, borderpad=5, font=dict(family="Helvetica, monospace", size=12, color="#ffffff"), )
|
||||
fig_steps.add_annotation(x=non_zero_steps_df.iloc[non_zero_steps_df["Steps Count"].idxmin()]["Date"], y=non_zero_steps_df["Steps Count"].min(), text=str(non_zero_steps_df["Steps Count"].min())+" steps", showarrow=False, arrowhead=0, bgcolor="#0b2d51", opacity=0.80, yshift=-15, borderpad=5, font=dict(family="Helvetica, monospace", size=12, color="#ffffff"), )
|
||||
fig_steps.add_hline(y=non_zero_steps_df["Steps Count"].mean(), line_dash="dot",annotation_text="Average : " + str(round(df_merged["Steps Count"].mean(), 1)), annotation_position="bottom right", annotation_bgcolor="#6b3908", annotation_opacity=0.8, annotation_borderpad=5, annotation_font=dict(family="Helvetica, monospace", size=14, color="#ffffff"))
|
||||
fig_steps_heatmap = px.imshow(weekly_steps_array, color_continuous_scale='YLGn', origin='lower', title="<b>Weekly Steps Heatmap</b>", labels={'x':"Week Number", 'y': "Day of the Week"}, height=350, aspect='equal')
|
||||
fig_steps_heatmap.update_traces(colorbar_orientation='h', selector=dict(type='heatmap'))
|
||||
fig_activity_minutes = px.bar(df_merged, x="Date", y=["Fat Burn Minutes", "Cardio Minutes", "Peak Minutes"], title=f"<b>Activity Minutes<br><br><sup>Overall average : {active_mins_avg['overall']} minutes | Last 30d average : {active_mins_avg['30d']} minutes</sup></b><br><br><br>")
|
||||
fig_activity_minutes.update_layout(yaxis_title='Active Minutes', legend=dict(orientation="h",yanchor="bottom", y=1.02, xanchor="right", x=1, title_text=''))
|
||||
fig_weight = px.line(df_merged, x="Date", y="weight", line_shape="spline", color_discrete_sequence=["#6b3908"], title=f"<b>Weight<br><br><sup>Overall average : {weight_avg['overall']} Unit | Last 30d average : {weight_avg['30d']} Unit</sup></b><br><br><br>")
|
||||
@ -206,7 +216,7 @@ def update_output(n_clicks, value, start_date, end_date):
|
||||
fig_spo2 = px.bar(df_merged, x="Date", y="SPO2", title="<b>SPO2 Percentage</b>", range_y=(80,100))
|
||||
|
||||
|
||||
return report_title, report_dates_range, generated_on_date, fig_rhr, fig_steps, fig_activity_minutes, fig_weight, fig_spo2, ""
|
||||
return report_title, report_dates_range, generated_on_date, fig_rhr, fig_steps, fig_steps_heatmap, fig_activity_minutes, fig_weight, fig_spo2, ""
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run_server(debug=True)
|
||||
|
Loading…
Reference in New Issue
Block a user