From 91718d4588d957f4128b0ff124d51562bc37d492 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 31 May 2021 13:34:14 +0200 Subject: [PATCH 1/3] activity chart improvements --- rowers/interactiveplots.py | 36 +++++++++++++++++++++++++++++++----- rowers/mytypes.py | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index d8d0c035..339b0bec 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -796,24 +796,38 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l dim_expr = hv.dim('type').categorize(mytypes.color_map) + + df = pd.DataFrame(thedict) + if totaldays>30 and yaxis=='duration': + df['duration'] = df['duration']/60 + elif yaxis == 'TRIMP': + df.drop('duration',inplace=True,axis=columns) + df.drop('rscore',inplace=True,axis=columns) + elif yaxis == 'rScore': + df.drop('duration',inplace=True,axis='columns') + df.drop('trimp',inplace=True,axis='columns' ) + df['color'] = df['type'].apply(lambda x:mapcolors(x)) df.sort_values('date_sorting',inplace=True) + #clrs = hv.Cycle(df['colors'].values) source = ColumnDataSource(df) hv.extension('bokeh') - table = hv.Table(df,[('date','Date'),('type','Workout Type')], - [('duration','Minutes'),('trimp','TRIMP'),('rscore','rScore'),('link','link')]) - - - bars=table.to.bars(['date',stack],[yaxis]) + #table = hv.Table(df,[('date','Date'),('type','Workout Type')], + # [('duration','Minutes'),('trimp','TRIMP'),('rscore','rScore'),('link','link')]) + + types_order = mytypes.workouttypes_ordered + #bars=table.to.bars(['date',stack],[yaxis]) + bars = hv.Bars(df, kdims=['date',stack]).aggregate(function=np.sum) + #print(mytypes.color_map) bars.opts( opts.Bars(cmap=mytypes.color_map, show_legend=True, stacked=True, tools=['tap','hover'], width=550, xrotation=45,padding=(0,(0,.1)), @@ -829,6 +843,18 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l d2 = enddate.strftime("%Y-%m-%d"), ) + p.xaxis.axis_label = 'Period' + if yaxis == 'duration': + p.yaxis.axis_label = 'Duration (min)' + if totaldays>30: + p.yaxis.axis_label = 'Duration (h)' + elif yaxis == 'TRIMP': + p.yaxis.axis_label = 'TRIMP' + else: + p.yaxis.axis_label = 'rScore' + + + p.plot_width=550 p.plot_height=350 p.toolbar_location = toolbar_location diff --git a/rowers/mytypes.py b/rowers/mytypes.py index 881cd311..50ec4541 100644 --- a/rowers/mytypes.py +++ b/rowers/mytypes.py @@ -319,7 +319,7 @@ rowtypes = ( ) -checktypes = [i[0] for i in workouttypes] +checktypes = [i[0] for i in workouttypes_ordered.items()] from bokeh.palettes import Category10,Category20, Category20c From 0320219acb266e1326fe6b710040b60c47fd0e96 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 31 May 2021 13:35:34 +0200 Subject: [PATCH 2/3] bug fix --- rowers/interactiveplots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 339b0bec..adf7724e 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -803,8 +803,8 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l if totaldays>30 and yaxis=='duration': df['duration'] = df['duration']/60 elif yaxis == 'TRIMP': - df.drop('duration',inplace=True,axis=columns) - df.drop('rscore',inplace=True,axis=columns) + df.drop('duration',inplace=True,axis='columns') + df.drop('rscore',inplace=True,axis='columns') elif yaxis == 'rScore': df.drop('duration',inplace=True,axis='columns') df.drop('trimp',inplace=True,axis='columns' ) From 8099686ca45d74790f3cb1e55d398edeef99d56f Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 31 May 2021 15:45:36 +0200 Subject: [PATCH 3/3] some coverage --- rowers/interactiveplots.py | 8 ++++---- rowers/tasks.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index adf7724e..f279ae32 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -800,12 +800,12 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l df = pd.DataFrame(thedict) - if totaldays>30 and yaxis=='duration': + if totaldays>30 and yaxis=='duration': # pragma: no cover df['duration'] = df['duration']/60 elif yaxis == 'TRIMP': df.drop('duration',inplace=True,axis='columns') df.drop('rscore',inplace=True,axis='columns') - elif yaxis == 'rScore': + elif yaxis == 'rScore': # pragma: no cover df.drop('duration',inplace=True,axis='columns') df.drop('trimp',inplace=True,axis='columns' ) @@ -846,11 +846,11 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l p.xaxis.axis_label = 'Period' if yaxis == 'duration': p.yaxis.axis_label = 'Duration (min)' - if totaldays>30: + if totaldays>30: # pragma: no cover p.yaxis.axis_label = 'Duration (h)' elif yaxis == 'TRIMP': p.yaxis.axis_label = 'TRIMP' - else: + else: # pragma: no cover p.yaxis.axis_label = 'rScore' diff --git a/rowers/tasks.py b/rowers/tasks.py index 427ce4b9..c1e2c228 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -3045,7 +3045,7 @@ def df_from_summary(data): try: splits = data['workout']['splits'] - except KeyError: + except KeyError: # pragma: no cover splits = [0] time = starttimeunix elapsed_distance = 0 @@ -3053,7 +3053,7 @@ def df_from_summary(data): distances = [0] try: spms = [splits[0]['stroke_rate']] - except KeyError: + except KeyError: # pragma: no cover spms = [0] try: hrs = [splits[0]['heart_rate']['average']]