diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 824d7332..ccbcf226 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -12,7 +12,7 @@ from bokeh.palettes import Dark2_8 as palette import itertools from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc from bokeh.models import CustomJS,Slider, TextInput,BoxAnnotation -from bokeh.charts import Histogram,HeatMap,Area,BoxPlot +from bokeh.charts import Histogram,HeatMap,Area,BoxPlot,Bar from bokeh.resources import CDN,INLINE from bokeh.embed import components from bokeh.layouts import layout,widgetbox @@ -219,6 +219,63 @@ def interactive_boxchart(datadf,fieldname,extratitle=''): return script,div +def interactive_activitychart(workouts,startdate,enddate): + if len(workouts) == 0: + return "","" + + dates = [] + types = [] + durations = [] + + for w in workouts: + if w.privacy == 'visible': + dd = w.date.strftime('%m/%d') + du = w.duration.hour*60+w.duration.minute + dates.append(dd) + durations.append(du) + types.append(w.workouttype) + + d = startdate + + while d<=enddate: + dates.append(d.strftime('%m/%d')) + durations.append(0) + types.append('rower') + d += datetime.timedelta(days=1) + + + df = pd.DataFrame({ + 'date':dates, + 'duration':durations, + 'type':types, + }) + + p = Bar(df,'date',values='duration',title='Activity', + stack='type', + plot_width=350, + plot_height=250, + toolbar_location = None, + ) + + for legend in p.legend: + new_items = [] + for legend_item in legend.items: + it = legend_item.label['value'] + tot = df[df['type']==it].duration.sum() + if tot != 0: + new_items.append(legend_item) + legend.items = new_items + + + p.legend.location = "top_left" + p.legend.background_fill_alpha = 0.7 + + p.yaxis.axis_label = 'Minutes' + + script, div = components(p) + + return script,div + def interactive_forcecurve(theworkouts,workstrokesonly=False): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair' diff --git a/rowers/templates/list_workouts.html b/rowers/templates/list_workouts.html index 23ac50ca..d2158284 100644 --- a/rowers/templates/list_workouts.html +++ b/rowers/templates/list_workouts.html @@ -135,6 +135,35 @@ {% endif %} +