diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 8987651c..f71d7e45 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -8,6 +8,8 @@ from rowingdata import rowingdata as rrdata from django.utils import timezone +from bokeh.palettes import Dark2_8 as palette +import itertools from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc from bokeh.models import CustomJS,Slider from bokeh.charts import Histogram,HeatMap @@ -1579,7 +1581,8 @@ def interactive_bar_chart(id=0,promember=0): return [script,div] -def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line'): +def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', + promember=0): columns = [xparam,yparam, 'ftime','distance','fpace', 'power','hr','spm', @@ -1590,9 +1593,9 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line'): yparamname = axlabels[yparam] - datadf = datadf[datadf[yparam] > 0] + #datadf = datadf[datadf[yparam] > 0] - datadf = datadf[datadf[xparam] > 0] + #datadf = datadf[datadf[xparam] > 0] # check if dataframe not empty if datadf.empty: @@ -1617,15 +1620,63 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line'): else: TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair' + if yparam == 'pace': + y_axis_type = 'datetime' + yaxmax = 90. + yaxmin = 150. + + if xparam == 'time': + x_axis_type = 'datetime' + + if xparam != 'time': + xvals = xaxmin+np.arange(100)*(xaxmax-xaxmin)/100. + else: + xvals = np.arange(100) + plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type, tools=TOOLS, toolbar_location="above", toolbar_sticky=False) + colors = itertools.cycle(palette) - for key,grp in datadf.groupby(['workoutid']): - print key - + for id,color in itertools.izip(ids,colors): + group = datadf[datadf['workoutid']==int(id)].copy() + group.sort_values(by='time',ascending=True,inplace=True) + group['x'] = group[xparam] + group['y'] = group[yparam] + source = ColumnDataSource( + group + ) + plot.line('x','y',source=source,color=color,legend=str(id)) + + plot.legend.location='top_left' + plot.xaxis.axis_label = axlabels[xparam] + plot.yaxis.axis_label = axlabels[yparam] + + if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): + xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam]) + plot.x_range = xrange1 + + if xparam == 'time': + xrange1 = Range1d(start=xaxmin,end=xaxmax) + plot.x_range = xrange1 + plot.xaxis[0].formatter = DatetimeTickFormatter( + hours = ["%H"], + minutes = ["%M"], + seconds = ["%S"], + days = ["0"], + months = [""], + years = [""] + ) + + + if yparam == 'pace': + plot.yaxis[0].formatter = DatetimeTickFormatter( + seconds = ["%S"], + minutes = ["%M"] + ) + script, div = components(plot) diff --git a/rowers/templates/multicompare.html b/rowers/templates/multicompare.html new file mode 100644 index 00000000..14751e7f --- /dev/null +++ b/rowers/templates/multicompare.html @@ -0,0 +1,49 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block title %}View Comparison {% endblock %} + +{% block content %} + + + + + {{ interactiveplot |safe }} + + + + + +