diff --git a/rowers/forms.py b/rowers/forms.py index ff61a245..30c6836b 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -25,6 +25,12 @@ import datetime from django.forms import formset_factory from rowers.utils import landingpages from rowers.metrics import axes +from rowers.metrics import axlabels + +formaxlabels = axlabels.copy() +formaxlabels.pop('None') +parchoices = list(sorted(formaxlabels.items(), key = lambda x:x[1])) + class FlexibleDecimalField(forms.DecimalField): @@ -710,6 +716,12 @@ class DataFrameColumnsForm(forms.Form): cols = forms.MultipleChoiceField(choices=colchoices, label='Table Columns') +class HistoForm(forms.Form): + includereststrokes = forms.BooleanField(initial=False,label='Include Rest Strokes',required=False) + histoparam = forms.ChoiceField(choices=parchoices,initial='power', + label='Metric') + + # form to select modality and boat type for trend flex class TrendFlexModalForm(forms.Form): modality = forms.ChoiceField(choices=workouttypes, @@ -797,12 +809,6 @@ class PlannedSessionMultipleCloneForm(forms.Form): label='Planned Sessions' ) -from rowers.metrics import axlabels - -formaxlabels = axlabels.copy() -formaxlabels.pop('None') -parchoices = list(sorted(formaxlabels.items(), key = lambda x:x[1])) - class BoxPlotChoiceForm(forms.Form): yparam = forms.ChoiceField(choices=parchoices,initial='spm', diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index e1207fb6..141bc9f0 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1214,12 +1214,13 @@ def fitnessmetric_chart(fitnessmetrics,user,workoutmode='rower',startdate=None, return [script,div] -def interactive_histoall(theworkouts): +def interactive_histoall(theworkouts,histoparam,includereststrokes): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' ids = [int(w.id) for w in theworkouts] - rowdata = dataprep.getsmallrowdata_db(['power'],ids=ids,doclean=True) + workstrokesonly = not includereststrokes + rowdata = dataprep.getsmallrowdata_db([histoparam],ids=ids,doclean=True,workstrokesonly=workstrokesonly) rowdata.dropna(axis=0,how='any',inplace=True) @@ -1227,16 +1228,16 @@ def interactive_histoall(theworkouts): return "","No Valid Data Available","","" try: - histopwr = rowdata['power'].values + histopwr = rowdata[histoparam].values except KeyError: - return "","No power data","","" + return "","No data","","" if len(histopwr) == 0: return "","No valid data available","","" # throw out nans histopwr = histopwr[~np.isinf(histopwr)] - histopwr = histopwr[histopwr > 25] - histopwr = histopwr[histopwr < 1000] + histopwr = histopwr[histopwr > yaxminima[histoparam]] + histopwr = histopwr[histopwr < yaxmaxima[histoparam]] plot = Figure(tools=TOOLS,plot_width=900, toolbar_sticky=False, @@ -1289,7 +1290,7 @@ def interactive_histoall(theworkouts): # plot.quad(top='hist_norm',bottom=0,left=edges[:-1],right=edges[1:]) plot.quad(top='hist_norm',bottom=0,left='left',right='right',source=source) - plot.xaxis.axis_label = "Power (W)" + plot.xaxis.axis_label = axlabels[histoparam] plot.yaxis.axis_label = "% of strokes" plot.y_range = Range1d(0,1.05*max(hist_norm)) @@ -1297,7 +1298,7 @@ def interactive_histoall(theworkouts): hover = plot.select(dict(type=HoverTool)) hover.tooltips = OrderedDict([ - ('Power(W)','@left{int}'), + (axlabels[histoparam],'@left{int}'), ('% of strokes','@hist_norm'), ('Cumulative %','@histsum{int}'), ]) @@ -1311,12 +1312,36 @@ def interactive_histoall(theworkouts): axis_label="Cumulative % of strokes"),'right') plot.sizing_mode = 'scale_width' + + annolabel = Label(x=50,y=450,x_units='screen',y_units='screen', + text='', + background_fill_alpha=0.7, + background_fill_color='white', + text_color='black', + ) + + plot.add_layout(annolabel) + + callback = CustomJS(args = dict( + annolabel=annolabel, + ), code=""" + var annotation = annotation.value + annolabel.text = annotation + """) + + annotation = TextInput(title="Type your plot notes here", value="", + callback=callback) + callback.args["annotation"] = annotation + + layout = layoutcolumn([annotation,plot]) + try: - script, div = components(plot) + script, div = components(layout) except ValueError: script = '' div = '' - + + return [script,div] def course_map(course): @@ -3889,7 +3914,7 @@ def interactive_flex_chart2(id=0,promember=0, """) annotation = TextInput(title="Type your plot notes here", value="", - callback=callback) + callback=callback) callback.args["annotation"] = annotation slider_spm_min = Slider(start=15.0, end=55,value=15.0, step=.1, diff --git a/rowers/templates/analysis.html b/rowers/templates/analysis.html index d598c144..aca799ec 100644 --- a/rowers/templates/analysis.html +++ b/rowers/templates/analysis.html @@ -40,14 +40,14 @@
- Plot a power histogram of all your strokes over a date range. + Plot a histogram chart of one metric for all your strokes over a date range.