From 63f1895343d07d34fb9c9aaf1d50d11f2ed9280d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 17 Oct 2017 09:39:30 +0200 Subject: [PATCH] bar charts on team list by rower, not by type --- rowers/interactiveplots.py | 11 +++++++---- rowers/views.py | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 2cc207c0..29675cd0 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -219,12 +219,13 @@ def interactive_boxchart(datadf,fieldname,extratitle=''): return script,div -def interactive_activitychart(workouts,startdate,enddate): +def interactive_activitychart(workouts,startdate,enddate,stack='type'): if len(workouts) == 0: return "","" dates = [] types = [] + rowers = [] durations = [] for w in workouts: @@ -234,6 +235,7 @@ def interactive_activitychart(workouts,startdate,enddate): dates.append(dd) durations.append(du) types.append(w.workouttype) + rowers.append(w.user.user.first_name) try: d = utc.localize(startdate) @@ -250,17 +252,18 @@ def interactive_activitychart(workouts,startdate,enddate): dates.append(d.strftime('%m/%d')) durations.append(0) types.append('rower') + rowers.append('Sander') d += datetime.timedelta(days=1) - df = pd.DataFrame({ 'date':dates, 'duration':durations, 'type':types, + 'rower':rowers, }) p = Bar(df,'date',values='duration',title='Activity', - stack='type', + stack=stack, plot_width=350, plot_height=250, toolbar_location = None, @@ -270,7 +273,7 @@ def interactive_activitychart(workouts,startdate,enddate): new_items = [] for legend_item in legend.items: it = legend_item.label['value'] - tot = df[df['type']==it].duration.sum() + tot = df[df[stack]==it].duration.sum() if tot != 0: new_items.append(legend_item) legend.items = new_items diff --git a/rowers/views.py b/rowers/views.py index 160274bb..208239cc 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -4416,9 +4416,15 @@ def workouts_view(request,message='',successmessage='', "-id" ) + if theteam: + stack='rower' + else: + stack='type' + script,div = interactive_activitychart(g_workouts, activity_startdate, - activity_enddate) + activity_enddate, + stack=stack) messages.info(request,successmessage) messages.error(request,message)