From 3444995880e4156ccfaa6a1d4bb7cb0073561f51 Mon Sep 17 00:00:00 2001 From: sanderroosendaal Date: Tue, 8 Nov 2016 10:31:27 +0100 Subject: [PATCH] Initial updates (rowerpowerform) and ftp everywhere rrower is called --- rowers/dataprep.py | 2 +- rowers/interactiveplots.py | 4 +- rowers/mailprocessing.py | 2 +- rowers/models.py | 8 ++- rowers/tasks.py | 2 + rowers/templates/rower_form.html | 15 +++-- rowers/tests.py | 33 +++++++++- rowers/views.py | 104 ++++++++++++++++++++----------- 8 files changed, 124 insertions(+), 46 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 353a4f86..092fdb54 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -73,7 +73,7 @@ def getrowdata(id=0): rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 15be12f3..2744d1e4 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -359,7 +359,7 @@ def interactive_windchart(id=0,promember=0): rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) if rowdata == 0: @@ -447,7 +447,7 @@ def interactive_streamchart(id=0,promember=0): rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) if rowdata == 0: diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index 32d24bdc..8e900112 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -142,7 +142,7 @@ def make_new_workout_from_email(rr,f2,name,cntr=0): # make workout and put in database #r = rrower(hrmax=rr.max,hrut2=rr.ut2, # hrut1=rr.ut1,hrat=rr.at, - # hrtr=rr.tr,hran=rr.an) + # hrtr=rr.tr,hran=rr.an,ftp=r.ftp) row = rdata('media/'+f2) #,rower=r) if row == 0: return 0 diff --git a/rowers/models.py b/rowers/models.py index efa91b55..186cc531 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -32,6 +32,8 @@ class Rower(models.Model): weightcategory = models.CharField(default="hwt", max_length=30, choices=weightcategories) + + ftp = models.IntegerField(default=226,verbose_name="Functional Threshold Power") c2token = models.CharField(default='',max_length=200,blank=True,null=True) tokenexpirydate = models.DateTimeField(blank=True,null=True) @@ -49,7 +51,7 @@ class Rower(models.Model): ) rowerplan = models.CharField(default='basic',max_length=30, choices=plans) - friends = models.ManyToManyField("self") + friends = models.ManyToManyField("self",blank=True) team = models.ForeignKey(Team,blank=True,null=True) @@ -158,6 +160,10 @@ class AdvancedWorkoutForm(ModelForm): model = Workout fields = ['boattype','weightvalue'] +class RowerPowerForm(ModelForm): + class Meta: + model = Rower + fields = ['ftp'] class RowerForm(ModelForm): class Meta: diff --git a/rowers/tasks.py b/rowers/tasks.py index 143f0ffe..5637644b 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -177,6 +177,8 @@ def handle_makeplot(f1,f2,t,hrdata,plotnr,imagename): fig1 = row.get_timeplot_erg2(t) elif (plotnr==9) or (plotnr==12): fig1 = row.get_time_otwpower(t) + elif (plotnr==13) or (plotnr==16): + fig1 = row.get_power_piechart(t) canvas = FigureCanvas(fig1) diff --git a/rowers/templates/rower_form.html b/rowers/templates/rower_form.html index c8368c6e..ffc83a3a 100644 --- a/rowers/templates/rower_form.html +++ b/rowers/templates/rower_form.html @@ -9,7 +9,7 @@

{% endif %}
-

Edit your Parameters

+

Heart Rate Bands

@@ -18,16 +18,21 @@ {% csrf_token %}
+
-

Tokens etcetera

+

Functional Threshold Power

+

- - - + {{ powerform.as_table }}
Concept2 sync issues? Click:Concept2 logo
+ {% csrf_token %} +
+ + +

diff --git a/rowers/tests.py b/rowers/tests.py index b2551c9c..9e73ea0a 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -235,7 +235,7 @@ class DataTest(TestCase): rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) row = rdata(filename,rower=rr) totaldist = row.df['cum_dist'].max() totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min() @@ -871,6 +871,7 @@ class PlotTests(TestCase): 'hrat':r.at, 'hrtr':r.tr, 'hran':r.an, + 'ftp':r.ftp, } @@ -971,6 +972,16 @@ class PlotTests(TestCase): filename=fullpathimagename) os.remove(fullpathimagename) + plotnr = 13 + if (w.workouttype=='water'): + plotnr = plotnr+3 + + res = handle_makeplot(f1,w.csvfilename, + w.name,self.hrdata,plotnr,imagename) + i = GraphImage(workout=w,creationdatetime=self.nu, + filename=fullpathimagename) + os.remove(fullpathimagename) + def test_otw_plots(self): w = self.wotw f1 = 'testdata.csv'[:-4] @@ -1067,3 +1078,23 @@ class PlotTests(TestCase): i = GraphImage(workout=w,creationdatetime=self.nu, filename=fullpathimagename) os.remove(fullpathimagename) + + plotnr = 9 + if (w.workouttype=='water'): + plotnr = plotnr+3 + + res = handle_makeplot(f1,w.csvfilename, + w.name,self.hrdata,plotnr,imagename) + i = GraphImage(workout=w,creationdatetime=self.nu, + filename=fullpathimagename) + os.remove(fullpathimagename) + + plotnr = 13 + if (w.workouttype=='water'): + plotnr = plotnr+3 + + res = handle_makeplot(f1,w.csvfilename, + w.name,self.hrdata,plotnr,imagename) + i = GraphImage(workout=w,creationdatetime=self.nu, + filename=fullpathimagename) + os.remove(fullpathimagename) diff --git a/rowers/views.py b/rowers/views.py index daa521a4..7b032b52 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -13,7 +13,8 @@ from django.core.mail import send_mail, BadHeaderError from rowers.forms import EmailForm, RegistrationForm, RegistrationFormTermsOfService,RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,UpdateStreamForm from rowers.forms import PredictedPieceForm,DateRangeForm,DeltaDaysForm from rowers.forms import SummaryStringForm,IntervalUpdateForm -from rowers.models import Workout, User, Rower, WorkoutForm,RowerForm,GraphImage,AdvancedWorkoutForm +from rowers.models import Workout, User, Rower, WorkoutForm +from rowers.models import RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm import StringIO from django.contrib.auth.decorators import login_required,user_passes_test from time import strftime,strptime,mktime,time,daylight @@ -419,7 +420,7 @@ def add_workout_from_strokedata(user,importid,data,strokedata,source='c2'): # make workout rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) row = rdata(csvfilename,rower=rr) totaldist = row.df['cum_dist'].max() totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min() @@ -647,7 +648,7 @@ def add_workout_from_stdata(user,importid,data): # make workout rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) row = rdata(csvfilename,rower=rr) totaldist = row.df['cum_dist'].max() totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min() @@ -2752,13 +2753,14 @@ def workout_add_otw_powerplot_view(request,id): fullpathimagename = 'static/plots/'+imagename u = request.user r = Rower.objects.get(user=u) - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, 'hrat':r.at, 'hrtr':r.tr, 'hran':r.an, + 'ftp':r.ftp, } # make plot - asynchronous task @@ -2769,10 +2771,10 @@ def workout_add_otw_powerplot_view(request,id): if settings.DEBUG: res = handle_makeplot.delay(f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) else: res = queue.enqueue(handle_makeplot,f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) # i = GraphImage(workout=w,creationdatetime=datetime.datetime.now(), # filename=fullpathimagename) @@ -2796,13 +2798,14 @@ def workout_add_piechart_view(request,id): fullpathimagename = 'static/plots/'+imagename u = request.user r = Rower.objects.get(user=u) - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, 'hrat':r.at, 'hrtr':r.tr, 'hran':r.an, + 'ftp':r.ftp, } # make plot - asynchronous task @@ -2813,10 +2816,10 @@ def workout_add_piechart_view(request,id): if settings.DEBUG: res = handle_makeplot.delay(f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) else: res = queue.enqueue(handle_makeplot,f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) # i = GraphImage(workout=w,creationdatetime=datetime.datetime.now(), # filename=fullpathimagename) @@ -2839,13 +2842,14 @@ def workout_add_timeplot_view(request,id): fullpathimagename = 'static/plots/'+imagename u = request.user r = Rower.objects.get(user=u) - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, 'hrat':r.at, 'hrtr':r.tr, 'hran':r.an, + 'ftp':r.ftp, } # make plot - asynchronous task @@ -2856,10 +2860,10 @@ def workout_add_timeplot_view(request,id): if settings.DEBUG: res = handle_makeplot.delay(f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) else: res = queue.enqueue(handle_makeplot,f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) i = GraphImage(workout=w,creationdatetime=timezone.now(), filename=fullpathimagename) @@ -2883,13 +2887,14 @@ def workout_add_distanceplot_view(request,id): fullpathimagename = 'static/plots/'+imagename u = request.user r = Rower.objects.get(user=u) - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, 'hrat':r.at, 'hrtr':r.tr, 'hran':r.an, + 'ftp':r.ftp, } # make plot - asynchronous task @@ -2900,10 +2905,10 @@ def workout_add_distanceplot_view(request,id): if settings.DEBUG: res = handle_makeplot.delay(f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) else: res = queue.enqueue(handle_makeplot,f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) i = GraphImage(workout=w,creationdatetime=timezone.now(), filename=fullpathimagename) @@ -2926,7 +2931,7 @@ def workout_add_distanceplot2_view(request,id): fullpathimagename = 'static/plots/'+imagename u = request.user r = Rower.objects.get(user=u) - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, @@ -2943,10 +2948,10 @@ def workout_add_distanceplot2_view(request,id): if settings.DEBUG: res = handle_makeplot.delay(f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) else: res = queue.enqueue(handle_makeplot,f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) i = GraphImage(workout=w,creationdatetime=timezone.now(), filename=fullpathimagename) @@ -2970,7 +2975,7 @@ def workout_add_timeplot2_view(request,id): fullpathimagename = 'static/plots/'+imagename u = request.user r = Rower.objects.get(user=u) - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, @@ -2987,10 +2992,10 @@ def workout_add_timeplot2_view(request,id): if settings.DEBUG: res = handle_makeplot.delay(f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) else: res = queue.enqueue(handle_makeplot,f1,w.csvfilename, - w.name,hrdata,plotnr,imagename) + w.name,hrpwrdata,plotnr,imagename) i = GraphImage(workout=w,creationdatetime=timezone.now(), filename=fullpathimagename) @@ -3335,7 +3340,7 @@ def workout_upload_view(request,message=""): r = Rower.objects.get(user=request.user) rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) row = rdata(f2,rower=rr) if row == 0: return HttpResponse("Error: CSV Data File Not Found") @@ -3421,7 +3426,7 @@ def workout_upload_view(request,message=""): imagename = f1[:-4]+'.png' fullpathimagename = 'static/plots/'+imagename u = request.user - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, @@ -3443,14 +3448,14 @@ def workout_upload_view(request,message=""): # res = handle_makeplot.delay(f1,f2,t, -# hrdata,plotnr,imagename) +# hrpwrdata,plotnr,imagename) if settings.DEBUG: res = handle_makeplot.delay(f1,f2,t, - hrdata,plotnr, + hrpwrdata,plotnr, imagename) else: res = queue.enqueue(handle_makeplot,f1,f2, - t,hrdata, + t,hrpwrdata, plotnr,imagename) @@ -3607,7 +3612,7 @@ def workout_upload_view_debug(request,message=""): r = Rower.objects.get(user=request.user) rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) row = rdata(f2,rower=rr) if row == 0: return HttpResponse("Error: CSV Data File Not Found") @@ -3657,7 +3662,7 @@ def workout_upload_view_debug(request,message=""): imagename = f1[:-4]+'.png' fullpathimagename = 'static/plots/'+imagename u = request.user - hrdata = { + hrpwrdata = { 'hrmax':r.max, 'hrut2':r.ut2, 'hrut1':r.ut1, @@ -3679,14 +3684,14 @@ def workout_upload_view_debug(request,message=""): # res = handle_makeplot.delay(f1,f2,t, - # hrdata,plotnr,imagename) + # hrpwrdata,plotnr,imagename) if settings.DEBUG: res = handle_makeplot.delay(f1,f2,t, - hrdata,plotnr, + hrpwrdata,plotnr, imagename) else: res = queue.enqueue(handle_makeplot,f1,f2, - t,hrdata, + t,hrpwrdata, plotnr,imagename) @@ -3900,7 +3905,7 @@ def workout_summary_restore_view(request,id,message="",successmessage=""): r = Rower.objects.get(user=u) rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) if rowdata == 0: return HttpResponse("Error: CSV Data File Not Found") @@ -3948,7 +3953,7 @@ def workout_summary_edit_view(request,id,message="",successmessage="" r = Rower.objects.get(user=u) rr = rrower(hrmax=r.max,hrut2=r.ut2, hrut1=r.ut1,hrat=r.at, - hrtr=r.tr,hran=r.an) + hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) if rowdata == 0: return HttpResponse("Error: CSV Data File Not Found") @@ -4120,7 +4125,7 @@ def workout_summary_edit_view(request,id,message="",successmessage="" @login_required() def rower_edit_view(request,message=""): - if request.method == 'POST': + if request.method == 'POST' and "ut2" in request.POST: form = RowerForm(request.POST) if form.is_valid(): # something @@ -4159,13 +4164,42 @@ def rower_edit_view(request,message=""): # response = HttpResponseRedirect(url) + return response + elif request.method == 'POST' and "ftp" in request.POST: + form = RowerPowerForm(request.POST) + if form.is_valid(): + cd = form.cleaned_data + ftp = cd['ftp'] + try: + r = Rower.objects.get(user=request.user) + r.ftp = max(min(ftp,650),50) + r.save() + message = "Functional Threshold Value Changed" + url = reverse(workouts_view,args=[str(message)]) + response = HttpResponseRedirect(url) + except Rower.DoesNotExist: + message = "Funny. This user doesn't exist." + url = reverse(workouts_view,args=[str(message)]) + response = HttpResponseRedirect(url) + else: + message = HttpResponse("invalid form") + return render(request, 'rower_form.html', + {'form':form, + 'powerform':powerform, + }) + + return response else: try: r = Rower.objects.get(user=request.user) form = RowerForm(instance=r) + powerform = RowerPowerForm(instance=r) return render(request, 'rower_form.html', - {'form':form,}) + { + 'form':form, + 'powerform':powerform, + }) except Rower.DoesNotExist: return HttpResponse("This user doesn't exist")