From 60ac117fb4a46dfbda3e37409a99ca217662536c Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 27 Nov 2017 18:14:40 +0100 Subject: [PATCH] added static plot of in stroke from geeky page --- rowers/templates/otwgeeky.html | 222 +++++++++++++++++---------------- rowers/urls.py | 1 + rowers/views.py | 62 ++++++++- 3 files changed, 179 insertions(+), 106 deletions(-) diff --git a/rowers/templates/otwgeeky.html b/rowers/templates/otwgeeky.html index 8248084d..14699098 100644 --- a/rowers/templates/otwgeeky.html +++ b/rowers/templates/otwgeeky.html @@ -7,122 +7,134 @@ {% block content %}
- {% if form.errors %} -

- Please correct the error{{ form.errors|pluralize }} below. -

- {% endif %} + {% if form.errors %} +

+ Please correct the error{{ form.errors|pluralize }} below. +

+ {% endif %} + +

Advanced OTW features

+ {% if user.rower.rowerplan == 'basic' %} +

This is a preview of the page with advanced functionality for Pro users. See the About page for more information and to sign up for Pro Membership +{% endif %} +

+

+ Edit Workout +

+
+
+

+ Advanced Edit +

+
+
+

+ Export +

+ +
-

Advanced OTW features

- {% if user.rower.rowerplan == 'basic' %} -

This is a preview of the page with advanced functionality for Pro users. See the About page for more information and to sign up for Pro Membership - {% endif %} -

-

- Edit Workout -

-
-
-

- Advanced Edit -

-
-
-

- Export -

- -
- -
- - - - - - - - - - - - -
Date:{{ workout.date }}
Time:{{ workout.starttime }}
Distance:{{ workout.distance }}m
Duration:{{ workout.duration |durationprint:"%H:%M:%S.%f" }}
Public link to this workout - https://rowsandall.com/rowers/workout/{{ workout.id }} - -
-
+
+ + + + + + + + + + + + +
Date:{{ workout.date }}
Time:{{ workout.starttime }}
Distance:{{ workout.distance }}m
Duration:{{ workout.duration |durationprint:"%H:%M:%S.%f" }}
Public link to this workout + https://rowsandall.com/rowers/workout/{{ workout.id }} + +
+
-
-

+

+

+ {% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} + Edit Wind Data + {% else %} + Edit Wind Data + {% endif %} + +

+

+ Add wind data for OTW workouts +

+
+
+

+ {% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} + Edit Stream Data + {% else %} + Edit Stream Data + {% endif %} + +

+

+ For river dwellers. Add stream information. +

+
+
+

+ {% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} + OTW Power + {% else %} + OTW Power + {% endif %} +

+

+ Run OTW Power calculations (wind & stream correction, equivalent erg pace) +

+
+ + + +
+ +
+

{% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} - Edit Wind Data - {% else %} - Edit Wind Data - {% endif %} - -

-

- Add wind data for OTW workouts -

-
-
-

- {% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} - Edit Stream Data - {% else %} - Edit Stream Data - {% endif %} - -

-

- For river dwellers. Add stream information. -

-
-
-

- {% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} - OTW Power - {% else %} - OTW Power - {% endif %} -

-

- Run OTW Power calculations (wind & stream correction, equivalent erg pace) -

-
- - - -
- -
-

- {% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %} - Corrected Pace Plot + Corrected Pace Plot {% else %} Corrected Pace Plot {% endif %} - -

-

- Wind and Stream corrected pace plots will be here. -

-
-
-

+ +

+

+ Wind and Stream corrected pace plots will be here. +

+
+
+

Big Interactive Plot -

-

- See (and save) the big interactive plot -

-
+

+

+ See (and save) the big interactive plot +

+
+
+
+ {% if instrokemetrics %} + {% for metric in instrokemetrics %} + {% if forloop.first %} +
+ {% else %} +
+ {% endif %} + {{ metric }} +
+ {% endfor %} + {% endif %} +
-
-
diff --git a/rowers/urls.py b/rowers/urls.py index 193b2a2e..d79a7bbc 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -223,6 +223,7 @@ urlpatterns = [ url(r'^workout/(?P\d+)/makepublic$',views.workout_makepublic_view), url(r'^workout/(?P\d+)/geeky$',views.workout_geeky_view), url(r'^workout/(?P\d+)/advanced$',views.workout_advanced_view), + url(r'^workout/(?P\d+)/instroke/(?P\w+.*)$',views.instroke_chart), url(r'^workout/(?P\d+)/stats$',views.workout_stats_view), url(r'^workout/(?P\d+)/otwsetpower$',views.workout_otwsetpower_view), url(r'^workout/(?P\d+)/interactiveotwplot$',views.workout_otwpowerplot_view), diff --git a/rowers/views.py b/rowers/views.py index 3b8731b1..2d80cbb8 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -16,7 +16,8 @@ from django.db.models import Q from django import template from django.db import IntegrityError, transaction from django.views.decorators.csrf import csrf_exempt - +from matplotlib.backends.backend_agg import FigureCanvas +import gc from django.shortcuts import render from django.http import ( @@ -6445,6 +6446,10 @@ def workout_geeky_view(request,id=0,message="",successmessage=""): form = WorkoutForm(instance=row) g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") + rowdata = rrdata(csvfile=row.csvfilename) + instrokemetrics = rowdata.get_instroke_columns() + + for i in g: try: width,height = Image.open(i.filename).size @@ -6486,6 +6491,7 @@ def workout_geeky_view(request,id=0,message="",successmessage=""): {'workout':row, 'teams':get_my_teams(request.user), 'interactiveplot':script, + 'instrokemetrics':instrokemetrics, 'the_div':div}) else: return render(request, @@ -6495,6 +6501,60 @@ def workout_geeky_view(request,id=0,message="",successmessage=""): 'interactiveplot':script, 'the_div':div}) +# generate instroke chart +@login_required() +def instroke_chart(request,id=0,metric=''): + try: + w = Workout.objects.get(id=id) + except Workout.DoesNotExist: + raise Http404("Workout doesn't exist") + + if (checkworkoutuser(request.user,w)==False): + message = "You are not allowed to edit this workout" + messages.error(request,message) + url = reverse(workouts_view) + + return HttpResponseRedirect(url) + + rowdata = rrdata(csvfile=w.csvfilename) + instrokemetrics = rowdata.get_instroke_columns() + + if metric in instrokemetrics: + f1 = w.csvfilename[6:-4] + timestr = strftime("%Y%m%d-%H%M%S") + imagename = f1+timestr+'.png' + fullpathimagename = 'static/plots/'+imagename + u = w.user.user + r = getrower(u) + title = w.name + fig1 = rowdata.get_plot_instroke(metric) + canvas = FigureCanvas(fig1) + canvas.print_figure('static/plots/'+imagename) + plt.close(fig1) + fig1.clf() + gc.collect() + + try: + width,height = Image.open(fullpathimagename).size + except: + width = 1200 + height = 600 + + i = GraphImage(workout=w, + creationdatetime=timezone.now(), + filename=fullpathimagename, + width=width,height=height) + + i.save() + print i.id,'aap' + + url = reverse(workout_geeky_view, + kwargs = { + 'id':id, + }) + + return HttpResponseRedirect(url) + # Cumulative stats page @login_required() def cumstats(request,theuser=0,