From 467471437edd40772678b7e0d93183702e564996 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 4 Jan 2017 11:05:32 +0100 Subject: [PATCH] toggle rest stroke buttons --- rowers/interactiveplots.py | 15 +- rowers/templates/flexchart3.html | 265 ++++++++++++------------ rowers/templates/flexchart3otw.html | 3 +- rowers/templates/forcecurve_single.html | 41 ++-- rowers/views.py | 13 +- 5 files changed, 187 insertions(+), 150 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 248545b1..be61191e 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -125,7 +125,7 @@ def tailwind(bearing,vwind,winddir): from rowers.dataprep import nicepaceformat,niceformat from rowers.dataprep import timedeltaconv -def interactive_forcecurve(theworkouts): +def interactive_forcecurve(theworkouts,workstrokesonly=False): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair' ids = [int(w.id) for w in theworkouts] @@ -133,10 +133,21 @@ def interactive_forcecurve(theworkouts): boattype = theworkouts[0].boattype columns = ['catch','slip','wash','finish','averageforce', - 'peakforceangle','peakforce','spm','distance'] + 'peakforceangle','peakforce','spm','distance', + 'workoutstate'] rowdata = dataprep.getsmallrowdata_db(columns,ids=ids) + workoutstateswork = [1,4,5,8,9,6,7] + workoutstatesrest = [3] + workoutstatetransition = [0,2,10,11,12,13] + + if workstrokesonly: + try: + rowdata = rowdata[~rowdata['workoutstate'].isin(workoutstatesrest)] + except KeyError: + pass + catchav = rowdata['catch'].mean() finishav = rowdata['finish'].mean() washav = rowdata['wash'].mean() diff --git a/rowers/templates/flexchart3.html b/rowers/templates/flexchart3.html index ecb92d10..6a8b6d35 100644 --- a/rowers/templates/flexchart3.html +++ b/rowers/templates/flexchart3.html @@ -8,159 +8,160 @@ {% localtime on %} {% block content %} - {{ js_res | safe }} - {{ css_res| safe }} +{{ js_res | safe }} +{{ css_res| safe }} - - - + + + - {{ the_script |safe }} +{{ the_script |safe }} - +

 

+ - - - -
-
-
+ + +
+
+ {% csrf_token %} {% if workstrokesonly %} - + + {% else %} - + + {% endif %} - - - If your data source allows, this will show or hide strokes taken during rest intervals. -
-
- Line Plot -
- -
- + + If your data source allows, this will show or hide strokes taken during rest intervals. +
+
+ Line Plot +
+ +
+
- - - {{ the_div|safe }} - + + + {{ the_div|safe }} +
{% if user.rower.rowerplan == 'pro' %} diff --git a/rowers/templates/flexchart3otw.html b/rowers/templates/flexchart3otw.html index 62938673..67ab99b7 100644 --- a/rowers/templates/flexchart3otw.html +++ b/rowers/templates/flexchart3otw.html @@ -174,10 +174,11 @@ {% csrf_token %} {% if workstrokesonly %} + {% else %} + {% endif %} - If your data source allows, this will show or hide strokes taken during rest intervals. diff --git a/rowers/templates/forcecurve_single.html b/rowers/templates/forcecurve_single.html index 2f7e83b1..c45300c4 100644 --- a/rowers/templates/forcecurve_single.html +++ b/rowers/templates/forcecurve_single.html @@ -8,22 +8,22 @@ {% localtime on %} {% block content %} - {{ js_res | safe }} - {{ css_res| safe }} +{{ js_res | safe }} +{{ css_res| safe }} - - - + + + - {{ the_script |safe }} +{{ the_script |safe }} - + -
+ {% endif %} + +
+
+ {% csrf_token %} + {% if workstrokesonly %} + + + {% else %} + + + {% endif %} +
+ If your data source allows, this will show or hide strokes taken during rest intervals. +
+
diff --git a/rowers/views.py b/rowers/views.py index d6c8792b..f80ff03a 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1463,7 +1463,7 @@ def cum_flex(request,theuser=0, }) @user_passes_test(promember,login_url="/",redirect_field_name=None) -def workout_forcecurve_view(request,id=0): +def workout_forcecurve_view(request,id=0,workstrokesonly=False): row = Workout.objects.get(id=id) promember=0 mayedit=0 @@ -1478,7 +1478,15 @@ def workout_forcecurve_view(request,id=0): if not promember: return HttpResponseRedirect("/rowers/about/") - script,div,js_resources,css_resources = interactive_forcecurve([row]) + if request.method == 'POST' and 'workstrokesonly' in request.POST: + workstrokesonly = request.POST['workstrokesonly'] + if workstrokesonly == 'True': + workstrokesonly = True + else: + workstrokesonly = False + + script,div,js_resources,css_resources = interactive_forcecurve([row], + workstrokesonly=workstrokesonly) return render(request, 'forcecurve_single.html', @@ -1489,6 +1497,7 @@ def workout_forcecurve_view(request,id=0): 'css_res':css_resources, 'id':id, 'mayedit':mayedit, + 'workstrokesonly': not workstrokesonly, }) @login_required()