diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 6d4915a1..2e130d05 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -853,7 +853,7 @@ def getrowdata_db(id=0,doclean=False): def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True): prepmultipledata(ids) data = read_cols_df_sql(ids,columns) - + if 'peakforce' in columns: data['peakforce'] = data['peakforce']*lbstoN if 'averageforce' in columns: @@ -862,7 +862,7 @@ def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True): if doclean: data = clean_df_stats(data,ignorehr=True, workstrokesonly=workstrokesonly) - + return data # Fetch both the workout and the workout stroke data (from CSV file) @@ -921,7 +921,7 @@ def prepmultipledata(ids,verbose=False): def read_cols_df_sql(ids,columns): # drop columns that are not in offical list # axx = [ax[0] for ax in axes] - axx = StrokeData._meta.get_all_field_names() + axx = [f.name for f in StrokeData._meta.get_fields()] for c in columns: if not c in axx: columns.remove(c) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index f8bcb218..823ae3bf 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -889,12 +889,14 @@ def interactive_chart(id=0,promember=0): def interactive_cum_flex_chart2(theworkouts,promember=0, xparam='spm', yparam1='power', - yparam2='spm'): + yparam2='spm', + workstrokesonly=False): # datadf = dataprep.smalldataprep(theworkouts,xparam,yparam1,yparam2) ids = [int(w.id) for w in theworkouts] columns = [xparam,yparam1,yparam2,'spm','driveenergy','distance'] - datadf = dataprep.getsmallrowdata_db(columns,ids=ids,doclean=False) + datadf = dataprep.getsmallrowdata_db(columns,ids=ids,doclean=False, + workstrokesonly=workstrokesonly) try: tests = datadf[yparam2] @@ -1176,7 +1178,6 @@ def interactive_flex_chart2(id=0,promember=0, workstrokesonly=False): - #rowdata,row = dataprep.getrowdata_db(id=id) columns = [xparam,yparam1,yparam2, 'ftime','distance','fpace', diff --git a/rowers/templates/cum_flex.html b/rowers/templates/cum_flex.html index 7a43c0b9..50bed044 100644 --- a/rowers/templates/cum_flex.html +++ b/rowers/templates/cum_flex.html @@ -6,150 +6,153 @@ {% block content %} - {{ js_res | safe }} - {{ css_res| safe }} +{{ js_res | safe }} +{{ css_res| safe }} - - - + + + - {{ interactiveplot |safe }} +{{ interactiveplot |safe }} - +
-

Indoor Rower Stroke Analysis

+

Indoor Rower Stroke Analysis

-
- - - -

Summary for {{ theuser.first_name }} {{ theuser.last_name }} - between {{ startdate|date }} and {{ enddate|date }}

- - -
- - - - - - -
-
-

 

-

Warning: Large date ranges may take a long time to load. Huge date ranges may crash your browser.

-
-
-
-

Use this form to select a different date range:

-

- Select start and end date for a date range: -

- -
- - - {{ form.as_table }} -
- {% csrf_token %} -
-
+
+
+

Warning: Large date ranges may take a long time to load. Huge date ranges may crash your browser.

+ + {% csrf_token %} +
+ + {{ optionsform.as_table }} +
+
+
+ + +
+ +
+
+

Use this form to select a different date range:

+

+ Select start and end date for a date range: +

+ +
+ + + {{ form.as_table }} +
+ {% csrf_token %} +
+
-
-
-
- Or use the last {{ deltaform }} days. -
-
- {% csrf_token %} +
+
+ + Or use the last {{ deltaform }} days. +
+
+ {% csrf_token %} - -
+ +
+
+
+ +

Summary for {{ theuser.first_name }} {{ theuser.last_name }} + between {{ startdate|date }} and {{ enddate|date }}

+ + +
+ + + + + + +
+ + @@ -159,7 +162,7 @@
{{ the_div|safe }} - +
{% endblock %} diff --git a/rowers/views.py b/rowers/views.py index 845fbff2..1a193896 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -2096,8 +2096,21 @@ def cum_flex(request,theuser=0, enddate=timezone.now()+datetime.timedelta(days=1), deltadays=-1, startdatestring="", - enddatestring=""): + enddatestring="", + options={ + 'includereststrokes':False, + 'workouttypes':['rower','dynamic','slides'] + }): + if 'options' in request.session: + options = request.session['options'] + + workouttypes = options['workouttypes'] + includereststrokes = options['includereststrokes'] + workstrokesonly = not includereststrokes + checktypes = ['water','rower','dynamic','slides','skierg', + 'paddle','snow','other'] + if deltadays>0: startdate = enddate-datetime.timedelta(days=int(deltadays)) @@ -2131,6 +2144,7 @@ def cum_flex(request,theuser=0, if request.method == 'POST' and "daterange" in request.POST: form = DateRangeForm(request.POST) deltaform = DeltaDaysForm(request.POST) + optionsform = StatsOptionsForm() if form.is_valid(): startdate = form.cleaned_data['startdate'] enddate = form.cleaned_data['enddate'] @@ -2140,9 +2154,10 @@ def cum_flex(request,theuser=0, startdate = s elif request.method == 'POST' and "datedelta" in request.POST: deltaform = DeltaDaysForm(request.POST) + optionsform = StatsOptionsForm() if deltaform.is_valid(): deltadays = deltaform.cleaned_data['deltadays'] - if deltadays != 0: + if deltadays != 0 and isinstance(deltadays, Number): enddate = timezone.now() startdate = enddate-datetime.timedelta(days=deltadays) if startdate > enddate: @@ -2153,23 +2168,50 @@ def cum_flex(request,theuser=0, 'startdate': startdate, 'enddate': enddate, }) + else: + form = DateRangeForm() + optionsform = StatsOptionsForm() + elif request.method == 'POST' and 'options' in request.POST: + optionsform = StatsOptionsForm(request.POST) + if optionsform.is_valid(): + includereststrokes = optionsform.cleaned_data['includereststrokes'] + workstrokesonly = not includereststrokes + workouttypes = [] + for type in checktypes: + if optionsform.cleaned_data[type]: + workouttypes.append(type) + options = { + 'includereststrokes':includereststrokes, + 'workouttypes':workouttypes, + } + form = DateRangeForm(initial={ + 'startdate': startdate, + 'enddate': enddate, + }) + deltaform = DeltaDaysForm() + else: + form = DateRangeForm(initial={ + 'startdate': startdate, + 'enddate': enddate, + }) + deltaform = DeltaDaysForm() else: form = DateRangeForm(initial={ 'startdate': startdate, 'enddate': enddate, }) deltaform = DeltaDaysForm() - + optionsform = StatsOptionsForm() try: r2 = Rower.objects.get(user=theuser) - allergworkouts = Workout.objects.filter(user=r2, - workouttype__in=['rower','dynamic','slides'], - startdatetime__gte=startdate, - startdatetime__lte=enddate) + allworkouts = Workout.objects.filter(user=r2, + workouttype__in=workouttypes, + startdatetime__gte=startdate, + startdatetime__lte=enddate) except Rower.DoesNotExist: - allergworkouts = [] + allworkouts = [] r2=0 try: @@ -2177,11 +2219,12 @@ def cum_flex(request,theuser=0, except User.DoesNotExist: u = '' - if allergworkouts: - res = interactive_cum_flex_chart2(allergworkouts,xparam=xparam, + if allworkouts: + res = interactive_cum_flex_chart2(allworkouts,xparam=xparam, yparam1=yparam1, yparam2=yparam2, - promember=promember) + promember=promember, + workstrokesonly=workstrokesonly) script = res[0] div = res[1] js_resources = res[2] @@ -2192,6 +2235,26 @@ def cum_flex(request,theuser=0, js_resources = '' css_resources = '' + axchoicesbasic = {ax[0]:ax[1] for ax in axes if ax[4]=='basic'} + axchoicespro = {ax[0]:ax[1] for ax in axes if ax[4]=='pro'} + noylist = ["time","distance"] + axchoicesbasic.pop("cumdist") + + # set options form correctly + initial = {} + initial['includereststrokes'] = includereststrokes + + for wtype in checktypes: + if wtype in workouttypes: + initial[wtype] = True + else: + initial[wtype] = False + + + optionsform = StatsOptionsForm(initial=initial) + + request.session['options'] = options + return render(request, 'cum_flex.html', {'interactiveplot':script, 'the_div':div, @@ -2202,12 +2265,16 @@ def cum_flex(request,theuser=0, 'startdate':startdate, 'enddate':enddate, 'form':form, + 'optionsform':optionsform, 'deltaform':deltaform, 'xparam':xparam, 'yparam1':yparam1, 'yparam2':yparam2, 'promember':promember, 'teams':get_my_teams(request.user), + 'axchoicesbasic':axchoicesbasic, + 'axchoicespro':axchoicespro, + 'noylist':noylist, }) # Show the EMpower Oarlock generated Stroke Profile