Private
Public Access
1
0

added activity chart

This commit is contained in:
Sander Roosendaal
2017-07-29 12:44:23 +02:00
parent f04f55334e
commit 51e8b888b4
3 changed files with 94 additions and 2 deletions

View File

@@ -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'