From c0042445068d93d8fa3a71b98f748e1e90c19f55 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 28 Mar 2024 18:30:38 +0100 Subject: [PATCH] v1 activity_chart --- rowers/interactiveplots.py | 50 +++++++++++++++++++++++++++++------ rowers/templates/history.html | 2 ++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 728f8219..e915de3b 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -373,7 +373,7 @@ def interactive_workouttype_piechart(workouts): } - script, div = get_chart("/workouttypepie", chart_data, debug=True) + script, div = get_chart("/workouttypepie", chart_data, debug=False) return script, div @@ -567,6 +567,9 @@ def interactive_activitychart(workouts, startdate, enddate, stack='type', toolba df.sort_values('date_sorting', inplace=True) + data_dict = df.to_dict("records") + + hv.extension('bokeh') if stack == 'type': @@ -706,12 +709,9 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolb while d <= enddate: dd = d.strftime('%d') - if totaldays <= 30: - dates.append(d.strftime('%m/%d')) - dates_sorting.append(d.strftime('%Y/%m/%d')) - else: - dates.append(d.strftime('%Y/%m')) - dates_sorting.append(d.strftime('%Y/%m')) + dates.append(d.strftime('%Y-%m-%d')) + dates_sorting.append(d.strftime('%Y/%m/%d')) + durations.append(0) trimps.append(0) rscores.append(0) @@ -743,6 +743,41 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolb df = pd.DataFrame(thedict) + data_dict = df.to_dict("records") + + if totaldays < 30: + datebin = "day" + elif totaldays < 50: + datebin = "week" + else: + datebin = "month" + + stacknames = { + 'TRIMP': 'trimp', + 'distance': 'distance', + 'time': 'duration', + 'rScore': 'rscore', + 'duration': 'duration', + } + + chart_data = { + 'data': data_dict, + 'title': 'Activity {d1} to {d2}'.format( + d1=startdate.strftime("%Y-%m-%d"), + d2=enddate.strftime("%Y-%m-%d"), + ), + 'datebin': datebin, + 'colorby': 'type', + 'stackby': stacknames[yaxis], + 'doreduce': True, + 'dosort': True, + 'colors': mytypes.color_map, + } + + script, div = get_chart("/activity_bar", chart_data, debug=True) + + return script, div + if totaldays > 30 and yaxis == 'duration': # pragma: no cover df['duration'] = df['duration']/60 elif yaxis == 'TRIMP': @@ -4739,7 +4774,6 @@ def get_zones_report(rower, startdate, enddate, trainingzones='hr', date_agg='we 'hours': hours, } - # print(pd.DataFrame(data).head()) return data diff --git a/rowers/templates/history.html b/rowers/templates/history.html index 55ddbb5b..28635bc5 100644 --- a/rowers/templates/history.html +++ b/rowers/templates/history.html @@ -166,6 +166,8 @@ $("#total_maxhr").append(totalsdict.hrmax); $("#total_power").append(totalsdict.powermean); $("#total_maxpower").append(totalsdict.powermax); + $("#selectors").hide(); + listofdicts.forEach(function(item){ var id = "#"+item.id+"_hr"; $(id).append(item.hrmean);