Initial updates (rowerpowerform) and ftp everywhere rrower is called
This commit is contained in:
104
rowers/views.py
104
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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user