Merge branch 'feature/emailcommands' into develop
This commit is contained in:
@@ -30,7 +30,7 @@ queuelow = django_rq.get_queue('low')
|
|||||||
queuehigh = django_rq.get_queue('default')
|
queuehigh = django_rq.get_queue('default')
|
||||||
|
|
||||||
# Sends a confirmation with a link to the workout
|
# Sends a confirmation with a link to the workout
|
||||||
def send_confirm(u,name,link):
|
def send_confirm(u,name,link,options):
|
||||||
fullemail = u.email
|
fullemail = u.email
|
||||||
subject = 'Workout added: '+name
|
subject = 'Workout added: '+name
|
||||||
message = 'Dear '+u.first_name+',\n\n'
|
message = 'Dear '+u.first_name+',\n\n'
|
||||||
@@ -38,6 +38,10 @@ def send_confirm(u,name,link):
|
|||||||
message += "Link to workout: "+link+"\n\n"
|
message += "Link to workout: "+link+"\n\n"
|
||||||
message += "Best Regards, the Rowsandall Team"
|
message += "Best Regards, the Rowsandall Team"
|
||||||
|
|
||||||
|
if options:
|
||||||
|
message += "\n\n"+str(options)
|
||||||
|
|
||||||
|
|
||||||
email = EmailMessage(subject,message,
|
email = EmailMessage(subject,message,
|
||||||
'Rowsandall <info@rowsandall.com>',
|
'Rowsandall <info@rowsandall.com>',
|
||||||
[fullemail])
|
[fullemail])
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
#from rowers.mailprocessing import processattachments
|
#from rowers.mailprocessing import processattachments
|
||||||
import time
|
import time
|
||||||
|
from time import strftime
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rowers.tasks import handle_sendemail_unrecognized
|
from rowers.tasks import handle_sendemail_unrecognized
|
||||||
from django_mailbox.models import Mailbox,Message,MessageAttachment
|
from django_mailbox.models import Mailbox,Message,MessageAttachment
|
||||||
@@ -30,6 +31,7 @@ from rowingdata import summarydata,get_file_type
|
|||||||
|
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
from rowers.mailprocessing import make_new_workout_from_email,send_confirm
|
from rowers.mailprocessing import make_new_workout_from_email,send_confirm
|
||||||
|
import rowers.uploads as uploads
|
||||||
|
|
||||||
def rdata(file,rower=rrower()):
|
def rdata(file,rower=rrower()):
|
||||||
try:
|
try:
|
||||||
@@ -50,6 +52,8 @@ class Command(BaseCommand):
|
|||||||
extension = a.document.name[-3:].lower()
|
extension = a.document.name[-3:].lower()
|
||||||
donotdelete = 0
|
donotdelete = 0
|
||||||
m = Message.objects.get(id=a.message_id)
|
m = Message.objects.get(id=a.message_id)
|
||||||
|
body = "\n".join(m.text.splitlines())
|
||||||
|
uploadoptions = uploads.upload_options(body)
|
||||||
from_address = m.from_address[0].lower()
|
from_address = m.from_address[0].lower()
|
||||||
name = m.subject
|
name = m.subject
|
||||||
cntr += 1
|
cntr += 1
|
||||||
@@ -69,15 +73,31 @@ class Command(BaseCommand):
|
|||||||
]
|
]
|
||||||
res += wid
|
res += wid
|
||||||
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
||||||
|
if uploadoptions and not 'error' in uploadoptions:
|
||||||
|
w = Workout.objects.get(id=wid[0])
|
||||||
|
r = w.user
|
||||||
|
uploads.do_sync(w,uploadoptions)
|
||||||
|
uploads.make_private(w,uploadoptions)
|
||||||
|
if 'make_plot' in uploadoptions:
|
||||||
|
plottype = uploadoptions['plottype']
|
||||||
|
f1 = w.csvfilename[6:-4]
|
||||||
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
imagename = f1+timestr+'.png'
|
||||||
|
resu = uploads.make_plot(r,w,f1,
|
||||||
|
w.csvfilename,
|
||||||
|
plottype,name,
|
||||||
|
imagename=imagename)
|
||||||
try:
|
try:
|
||||||
if wid != 1:
|
if wid != 1:
|
||||||
dd = send_confirm(rr.user,title,link)
|
dd = send_confirm(rr.user,title,link,
|
||||||
|
uploadoptions)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
if wid != 1:
|
if wid != 1:
|
||||||
dd = send_confirm(rr.user,title,link)
|
dd = send_confirm(rr.user,title,link,
|
||||||
|
uploadoptions)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -91,6 +111,20 @@ class Command(BaseCommand):
|
|||||||
]
|
]
|
||||||
res += wid
|
res += wid
|
||||||
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
||||||
|
if uploadoptions:
|
||||||
|
w = Workout.objects.get(id=wid[0])
|
||||||
|
r = w.user
|
||||||
|
uploads.do_sync(w,uploadoptions)
|
||||||
|
uploads.make_private(w,uploadoptions)
|
||||||
|
if 'make_plot' in uploadoptions:
|
||||||
|
plottype = uploadoptions['plottype']
|
||||||
|
f1 = w.csvfilename[6:-4]
|
||||||
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
imagename = f1+timestr+'.png'
|
||||||
|
resu = uploads.make_plot(r,w,f1,
|
||||||
|
w.csvfilename,
|
||||||
|
plottype,name,
|
||||||
|
imagename=imagename)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# replace with code to process error
|
# replace with code to process error
|
||||||
@@ -99,12 +133,13 @@ class Command(BaseCommand):
|
|||||||
wid = 1
|
wid = 1
|
||||||
try:
|
try:
|
||||||
if wid != 1:
|
if wid != 1:
|
||||||
dd = send_confirm(rr.user,name,link)
|
dd = send_confirm(rr.user,name,link,
|
||||||
|
uploadoptions)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# remove attachment
|
# remove attachment
|
||||||
if donotdelete == 0:
|
if donotdelete == 0:
|
||||||
a.delete()
|
a.delete()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,249 @@
|
|||||||
|
# for actions related to uploads
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils import timezone,translation
|
||||||
|
from rowers.tasks import (
|
||||||
|
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||||
|
handle_sendemailnewresponse, handle_updatedps,
|
||||||
|
handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
|
||||||
|
handle_sendemailcsv
|
||||||
|
)
|
||||||
|
|
||||||
|
from rowers.models import GraphImage
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import yaml
|
||||||
|
import argparse
|
||||||
|
import yamllint
|
||||||
|
from subprocess import call
|
||||||
|
import re
|
||||||
|
|
||||||
|
try:
|
||||||
|
from cStringIO import StringIO
|
||||||
|
except:
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
from rowers.utils import (
|
||||||
|
geo_distance,serialize_list,deserialize_list,uniqify,
|
||||||
|
str2bool,range_to_color_hex,absolute
|
||||||
|
)
|
||||||
|
|
||||||
|
def cleanbody(body):
|
||||||
|
regex = r".*---\n([\s\S]*?)\.\.\..*"
|
||||||
|
matches = re.finditer(regex,body)
|
||||||
|
|
||||||
|
for m in matches:
|
||||||
|
|
||||||
|
if m != None:
|
||||||
|
body = m.group(0)
|
||||||
|
|
||||||
|
return body
|
||||||
|
|
||||||
|
def getsyncoptions(uploadoptions,values):
|
||||||
|
try:
|
||||||
|
value = values.lower()
|
||||||
|
values = [values]
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for v in values:
|
||||||
|
try:
|
||||||
|
v = v.lower()
|
||||||
|
|
||||||
|
if v in ['c2','concept2','logbook']:
|
||||||
|
uploadoptions['upload_to_C2'] = True
|
||||||
|
if v in ['tp','trainingpeaks']:
|
||||||
|
uploadoptions['upload_totp'] = True
|
||||||
|
if v in ['strava']:
|
||||||
|
uploadoptions['upload_to_Strava'] = True
|
||||||
|
if v in ['st','sporttracks']:
|
||||||
|
uploadoptions['upload_to_SportTracks'] = True
|
||||||
|
if v in ['rk','runkeeper']:
|
||||||
|
uploadoptions['upload_to_RunKeeper'] = True
|
||||||
|
if v in ['ua','underarmour','mapmyfitness']:
|
||||||
|
uploadoptions['upload_to_MapMyFitness'] = True
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
|
def getplotoptions(uploadoptions,value):
|
||||||
|
try:
|
||||||
|
v = value.lower()
|
||||||
|
if v in ['pieplot','timeplot','distanceplot']:
|
||||||
|
uploadoptions['make_plot'] = True
|
||||||
|
uploadoptions['plottype'] = v
|
||||||
|
elif 'pie' in v:
|
||||||
|
uploadoptions['make_plot'] = True
|
||||||
|
uploadoptions['plottype'] = 'pieplot'
|
||||||
|
elif 'distance' in v:
|
||||||
|
uploadoptions['make_plot'] = True
|
||||||
|
uploadoptions['plottype'] = 'distanceplot'
|
||||||
|
elif 'time' in v:
|
||||||
|
uploadoptions['make_plot'] = True
|
||||||
|
uploadoptions['plottype'] = 'timeplot'
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
|
def getboolean(uploadoptions,value,key):
|
||||||
|
b = True
|
||||||
|
if not value:
|
||||||
|
b = False
|
||||||
|
if value in [False,'false','False',None,'no']:
|
||||||
|
b = False
|
||||||
|
|
||||||
|
uploadoptions[key] = b
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
|
def upload_options(body):
|
||||||
|
uploadoptions = {}
|
||||||
|
body = cleanbody(body)
|
||||||
|
try:
|
||||||
|
yml = (yaml.load(body))
|
||||||
|
try:
|
||||||
|
for key, value in yml.iteritems():
|
||||||
|
if key == 'sync' or key == 'synchronization':
|
||||||
|
uploadoptions = getsyncoptions(uploadoptions,value)
|
||||||
|
if key == 'chart' or key == 'static' or key == 'plot':
|
||||||
|
uploadoptions = getplotoptions(uploadoptions,value)
|
||||||
|
if 'priva' in key:
|
||||||
|
uploadoptions = getboolean(uploadoptions,value,'makeprivate')
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
except yaml.YAMLError as exc:
|
||||||
|
pm = exc.problem_mark
|
||||||
|
strpm = str(pm)
|
||||||
|
pbm = "Your email has an issue on line {} at position {}. The error is: ".format(
|
||||||
|
pm.line+1,
|
||||||
|
pm.column+1,
|
||||||
|
)+strpm
|
||||||
|
return {'error':pbm}
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
|
def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
|
||||||
|
if imagename == '':
|
||||||
|
imagename = f1[:-4]+'.png'
|
||||||
|
fullpathimagename = 'static/plots/'+imagename
|
||||||
|
|
||||||
|
powerperc = 100*np.array([r.pw_ut2,
|
||||||
|
r.pw_ut1,
|
||||||
|
r.pw_at,
|
||||||
|
r.pw_tr,r.pw_an])/r.ftp
|
||||||
|
|
||||||
|
ftp = float(r.ftp)
|
||||||
|
if w.workouttype in ('water','coastal'):
|
||||||
|
ftp = ftp*(100.-r.otwslack)/100.
|
||||||
|
|
||||||
|
hrpwrdata = {
|
||||||
|
'hrmax':r.max,
|
||||||
|
'hrut2':r.ut2,
|
||||||
|
'hrut1':r.ut1,
|
||||||
|
'hrat':r.at,
|
||||||
|
'hrtr':r.tr,
|
||||||
|
'hran':r.an,
|
||||||
|
'ftp':ftp,
|
||||||
|
'powerperc':serialize_list(powerperc),
|
||||||
|
'powerzones':serialize_list(r.powerzones),
|
||||||
|
}
|
||||||
|
|
||||||
|
# make plot - asynchronous task
|
||||||
|
plotnrs = {
|
||||||
|
'timeplot':1,
|
||||||
|
'distanceplot':2,
|
||||||
|
'pieplot':3,
|
||||||
|
}
|
||||||
|
|
||||||
|
if plotnr == 0:
|
||||||
|
plotnr = plotnrs[plottype]
|
||||||
|
|
||||||
|
if w.workouttype in ('water','coastal'):
|
||||||
|
plotnr = plotnr+3
|
||||||
|
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
|
res = handle_makeplot.delay(f1,f2,title,
|
||||||
|
hrpwrdata,plotnr,
|
||||||
|
imagename)
|
||||||
|
else:
|
||||||
|
res = queue.enqueue(handle_makeplot,f1,f2,
|
||||||
|
title,hrpwrdata,
|
||||||
|
plotnr,imagename)
|
||||||
|
|
||||||
|
|
||||||
|
i = GraphImage(workout=w,
|
||||||
|
creationdatetime=timezone.now(),
|
||||||
|
filename=fullpathimagename)
|
||||||
|
i.save()
|
||||||
|
|
||||||
|
return i.id
|
||||||
|
|
||||||
|
import c2stuff,stravastuff,sporttracksstuff,runkeeperstuff
|
||||||
|
import underarmourstuff,tpstuff
|
||||||
|
|
||||||
|
def make_private(w,options):
|
||||||
|
if 'makeprivate' in options and options['makeprivate']:
|
||||||
|
w.privacy = 'hidden'
|
||||||
|
w.save()
|
||||||
|
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def do_sync(w,options):
|
||||||
|
if 'upload_to_C2' in options and options['upload_to_C2']:
|
||||||
|
try:
|
||||||
|
message,id = c2stuff.workout_c2_upload(w.user.user,w)
|
||||||
|
except c2stuff.C2NoTokenError:
|
||||||
|
id = 0
|
||||||
|
message = "Something went wrong with the Concept2 sync"
|
||||||
|
|
||||||
|
if 'upload_to_Strava' in options and options['upload_to_Strava']:
|
||||||
|
try:
|
||||||
|
message,id = stravastuff.workout_strava_upload(
|
||||||
|
w.user.user,w
|
||||||
|
)
|
||||||
|
except stravastuff.StravaNoTokenError:
|
||||||
|
id = 0
|
||||||
|
message = "Please connect to Strava first"
|
||||||
|
|
||||||
|
|
||||||
|
if 'upload_to_SportTracks' in options and options['upload_to_SportTracks']:
|
||||||
|
try:
|
||||||
|
message,id = sporttracksstuff.workout_sporttracks_upload(
|
||||||
|
w.user.user,w
|
||||||
|
)
|
||||||
|
except sporttracksstuff.SportTracksNoTokenError:
|
||||||
|
message = "Please connect to SportTracks first"
|
||||||
|
id = 0
|
||||||
|
|
||||||
|
|
||||||
|
if 'upload_to_RunKeeper' in options and options['upload_to_RunKeeper']:
|
||||||
|
try:
|
||||||
|
message,id = runkeeperstuff.workout_runkeeper_upload(
|
||||||
|
w.user.user,w
|
||||||
|
)
|
||||||
|
except runkeeperstuff.RunKeeperNoTokenError:
|
||||||
|
message = "Please connect to Runkeeper first"
|
||||||
|
id = 0
|
||||||
|
|
||||||
|
if 'upload_to_MapMyFitness' in options and options['upload_to_MapMyFitness']:
|
||||||
|
try:
|
||||||
|
message,id = underarmourstuff.workout_ua_upload(
|
||||||
|
w.user.user,w
|
||||||
|
)
|
||||||
|
except underarmourstuff.UnderArmourNoTokenError:
|
||||||
|
message = "Please connect to MapMyFitness first"
|
||||||
|
id = 0
|
||||||
|
|
||||||
|
|
||||||
|
if 'upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']:
|
||||||
|
try:
|
||||||
|
message,id = tpstuff.workout_tp_upload(
|
||||||
|
w.user.user,w
|
||||||
|
)
|
||||||
|
except tpstuff.TPNoTokenError:
|
||||||
|
message = "Please connect to TrainingPeaks first"
|
||||||
|
id = 0
|
||||||
|
|
||||||
|
return 1
|
||||||
+26
-7
@@ -219,13 +219,32 @@ urlpatterns = [
|
|||||||
url(r'^physics$',TemplateView.as_view(template_name='physics.html'),name='physics'),
|
url(r'^physics$',TemplateView.as_view(template_name='physics.html'),name='physics'),
|
||||||
url(r'^partners$',TemplateView.as_view(template_name='partners.html'),name='partners'),
|
url(r'^partners$',TemplateView.as_view(template_name='partners.html'),name='partners'),
|
||||||
url(r'^workout/(?P<id>\d+)/$',views.workout_view),
|
url(r'^workout/(?P<id>\d+)/$',views.workout_view),
|
||||||
url(r'^workout/(?P<id>\d+)/addtimeplot$',views.workout_add_timeplot_view),
|
# keeping the old URLs for retrofit
|
||||||
url(r'^workout/(?P<id>\d+)/addpiechart$',views.workout_add_piechart_view),
|
url(r'^workout/(?P<id>\d+)/addtimeplot$',
|
||||||
url(r'^workout/(?P<id>\d+)/addpowerpiechart$',views.workout_add_power_piechart_view),
|
views.workout_add_chart_view,
|
||||||
url(r'^workout/(?P<id>\d+)/adddistanceplot$',views.workout_add_distanceplot_view),
|
{'plotnr':'1'}),
|
||||||
url(r'^workout/(?P<id>\d+)/adddistanceplot2$',views.workout_add_distanceplot2_view),
|
url(r'^workout/(?P<id>\d+)/adddistanceplot$',
|
||||||
url(r'^workout/(?P<id>\d+)/addotwpowerplot$',views.workout_add_otw_powerplot_view),
|
views.workout_add_chart_view,
|
||||||
url(r'^workout/(?P<id>\d+)/addtimeplot2$',views.workout_add_timeplot2_view),
|
{'plotnr':'2'}),
|
||||||
|
url(r'^workout/(?P<id>\d+)/addpiechart$',
|
||||||
|
views.workout_add_chart_view,
|
||||||
|
{'plotnr':'3'}),
|
||||||
|
url(r'^workout/(?P<id>\d+)/adddistanceplot2$',
|
||||||
|
views.workout_add_chart_view,
|
||||||
|
{'plotnr':'7'}),
|
||||||
|
url(r'^workout/(?P<id>\d+)/addtimeplot2$',
|
||||||
|
views.workout_add_chart_view,
|
||||||
|
{'plotnr':'8'}),
|
||||||
|
url(r'^workout/(?P<id>\d+)/addotwpowerplot$',
|
||||||
|
views.workout_add_chart_view,
|
||||||
|
{'plotnr':'9'}),
|
||||||
|
url(r'^workout/(?P<id>\d+)/addpowerpiechart$',
|
||||||
|
views.workout_add_chart_view,
|
||||||
|
{'plotnr':'13'}),
|
||||||
|
# addstatic is the new URL -> need to update in templates
|
||||||
|
url(r'^workout/(?P<id>\d+)/addstatic/(?P<plotnr>\d+)$',
|
||||||
|
views.workout_add_chart_view),
|
||||||
|
url(r'^workout/(?P<id>\d+)/addstatic$',views.workout_add_chart_view),
|
||||||
url(r'^workout/(?P<id>\d+)/delete$',views.workout_delete_view),
|
url(r'^workout/(?P<id>\d+)/delete$',views.workout_delete_view),
|
||||||
url(r'^workout/(?P<id>\d+)/smoothenpace$',views.workout_smoothenpace_view),
|
url(r'^workout/(?P<id>\d+)/smoothenpace$',views.workout_smoothenpace_view),
|
||||||
url(r'^workout/(?P<id>\d+)/undosmoothenpace$',views.workout_undo_smoothenpace_view),
|
url(r'^workout/(?P<id>\d+)/undosmoothenpace$',views.workout_undo_smoothenpace_view),
|
||||||
|
|||||||
+12
-506
@@ -49,6 +49,7 @@ from rowers.models import (
|
|||||||
)
|
)
|
||||||
from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement
|
from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement
|
||||||
from rowers.metrics import rowingmetrics
|
from rowers.metrics import rowingmetrics
|
||||||
|
import rowers.uploads as uploads
|
||||||
from django.forms.formsets import formset_factory
|
from django.forms.formsets import formset_factory
|
||||||
import StringIO
|
import StringIO
|
||||||
from django.contrib.auth.decorators import login_required,user_passes_test
|
from django.contrib.auth.decorators import login_required,user_passes_test
|
||||||
@@ -6588,12 +6589,6 @@ def workout_edit_view_navionics(request,id=0,message="",successmessage=""):
|
|||||||
rowdata.df[' longitude'],
|
rowdata.df[' longitude'],
|
||||||
row.name)
|
row.name)
|
||||||
|
|
||||||
#res = googlemap_chart(rowdata.df[' latitude'],
|
|
||||||
# rowdata.df[' longitude'],
|
|
||||||
# row.name)
|
|
||||||
#gmscript = res[0]
|
|
||||||
#gmdiv = res[1]
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
mapscript = ""
|
mapscript = ""
|
||||||
mapdiv = ""
|
mapdiv = ""
|
||||||
@@ -6626,425 +6621,32 @@ def workout_edit_view_navionics(request,id=0,message="",successmessage=""):
|
|||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
# Generic chart creation
|
||||||
|
|
||||||
# Create the chart image with wind corrected pace (OTW)
|
|
||||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||||
def workout_add_otw_powerplot_view(request,id):
|
def workout_add_chart_view(request,id,plotnr=1):
|
||||||
try:
|
try:
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
except Workout.DoesNotExist:
|
except Workout.DoesNotExist:
|
||||||
raise Http404("Workout doesn't exist")
|
raise Http404("Workout doesn't exist")
|
||||||
|
|
||||||
|
plotnr = int(plotnr)
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
if (checkworkoutuser(request.user,w)==False):
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
raise PermissionDenied("You are not allowed add plots to this workout")
|
||||||
else:
|
else:
|
||||||
f1 = w.csvfilename[6:-4]
|
f1 = w.csvfilename[6:-4]
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
imagename = f1+timestr+'.png'
|
imagename = f1+timestr+'.png'
|
||||||
fullpathimagename = 'static/plots/'+imagename
|
|
||||||
u = w.user.user
|
u = w.user.user
|
||||||
r = getrower(u)
|
r = getrower(u)
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
title = w.name
|
||||||
r.pw_ut1,
|
res = uploads.make_plot(r,w,f1,w.csvfilename,'timeplot',title,plotnr=plotnr,
|
||||||
r.pw_at,
|
imagename=imagename)
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
|
|
||||||
ftp = r.ftp
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 9
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
# i = GraphImage(workout=w,creationdatetime=datetime.datetime.now(),
|
|
||||||
# filename=fullpathimagename)
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
url = "/rowers/workout/"+str(w.id)+"/edit"
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# Create the Heart rate zone pie chart
|
|
||||||
@login_required()
|
|
||||||
def workout_add_piechart_view(request,id):
|
|
||||||
try:
|
|
||||||
w = Workout.objects.get(id=id)
|
|
||||||
except Workout.DoesNotExist:
|
|
||||||
raise Http404("Workout doesn't exist")
|
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 3
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
# i = GraphImage(workout=w,creationdatetime=datetime.datetime.now(),
|
|
||||||
# filename=fullpathimagename)
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# Create the Power zone pie chart
|
|
||||||
@login_required()
|
|
||||||
def workout_add_power_piechart_view(request,id):
|
|
||||||
try:
|
|
||||||
w = Workout.objects.get(id=id)
|
|
||||||
except Workout.DoesNotExist:
|
|
||||||
raise Http404("Workout doesn't exist")
|
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 13
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# Create the time based summary chart
|
|
||||||
@login_required()
|
|
||||||
def workout_add_timeplot_view(request,id):
|
|
||||||
try:
|
|
||||||
w = Workout.objects.get(id=id)
|
|
||||||
except Workout.DoesNotExist:
|
|
||||||
raise Http404("Workout doesn't exist")
|
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 1
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
# i = GraphImage(workout=w,creationdatetime=datetime.datetime.now(),
|
|
||||||
# filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# Create the distance based summary chart
|
|
||||||
@login_required()
|
|
||||||
def workout_add_distanceplot_view(request,id):
|
|
||||||
try:
|
|
||||||
w = Workout.objects.get(id=id)
|
|
||||||
except Workout.DoesNotExist:
|
|
||||||
raise Http404("Workout doesn't exist")
|
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 2
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# Create the advanced parameters distance overview chart
|
|
||||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
|
||||||
def workout_add_distanceplot2_view(request,id):
|
|
||||||
try:
|
|
||||||
w = Workout.objects.get(id=id)
|
|
||||||
except Workout.DoesNotExist:
|
|
||||||
raise Http404("Workout doesn't exist")
|
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 7
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
|
|
||||||
# Create the advanced parameters time based overview chart
|
|
||||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
|
||||||
def workout_add_timeplot2_view(request,id):
|
|
||||||
try:
|
|
||||||
w = Workout.objects.get(id=id)
|
|
||||||
except Workout.DoesNotExist:
|
|
||||||
raise Http404("Workout doesn't exist")
|
|
||||||
|
|
||||||
if (checkworkoutuser(request.user,w)==False):
|
|
||||||
raise PermissionDenied("You are not allowed add plots to this workout")
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnr = 8
|
|
||||||
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,w.csvfilename,
|
|
||||||
w.name,hrpwrdata,plotnr,imagename)
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(w.id)+"/edit"
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# The page where you select which Strava workout to import
|
# The page where you select which Strava workout to import
|
||||||
@login_required()
|
@login_required()
|
||||||
@@ -7772,58 +7374,9 @@ def workout_upload_view(request,
|
|||||||
response = HttpResponseRedirect(url)
|
response = HttpResponseRedirect(url)
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
|
|
||||||
|
r = getrower(request.user)
|
||||||
if (make_plot):
|
if (make_plot):
|
||||||
imagename = f1[:-4]+'.png'
|
id = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||||
fullpathimagename = 'static/plots/'+imagename
|
|
||||||
u = request.user
|
|
||||||
r = getrower(request.user)
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnrs = {
|
|
||||||
'timeplot':1,
|
|
||||||
'distanceplot':2,
|
|
||||||
'pieplot':3,
|
|
||||||
}
|
|
||||||
|
|
||||||
plotnr = plotnrs[plottype]
|
|
||||||
if workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,f2,t,
|
|
||||||
hrpwrdata,plotnr,
|
|
||||||
imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,f2,
|
|
||||||
t,hrpwrdata,
|
|
||||||
plotnr,imagename)
|
|
||||||
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,
|
|
||||||
creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
# upload to C2
|
# upload to C2
|
||||||
if (upload_to_c2):
|
if (upload_to_c2):
|
||||||
@@ -8028,56 +7581,9 @@ def team_workout_upload_view(request,message="",
|
|||||||
response = HttpResponseRedirect(url)
|
response = HttpResponseRedirect(url)
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
|
|
||||||
|
r = getrower(request.user)
|
||||||
if (make_plot):
|
if (make_plot):
|
||||||
imagename = f1[:-4]+'.png'
|
id = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||||
fullpathimagename = 'static/plots/'+imagename
|
|
||||||
powerperc = 100*np.array([r.pw_ut2,
|
|
||||||
r.pw_ut1,
|
|
||||||
r.pw_at,
|
|
||||||
r.pw_tr,r.pw_an])/r.ftp
|
|
||||||
|
|
||||||
ftp = float(r.ftp)
|
|
||||||
if w.workouttype in ('water','coastal'):
|
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
|
||||||
|
|
||||||
hrpwrdata = {
|
|
||||||
'hrmax':r.max,
|
|
||||||
'hrut2':r.ut2,
|
|
||||||
'hrut1':r.ut1,
|
|
||||||
'hrat':r.at,
|
|
||||||
'hrtr':r.tr,
|
|
||||||
'hran':r.an,
|
|
||||||
'ftp':ftp,
|
|
||||||
'powerperc':serialize_list(powerperc),
|
|
||||||
'powerzones':serialize_list(r.powerzones),
|
|
||||||
}
|
|
||||||
|
|
||||||
# make plot - asynchronous task
|
|
||||||
plotnrs = {
|
|
||||||
'timeplot':1,
|
|
||||||
'distanceplot':2,
|
|
||||||
'pieplot':3,
|
|
||||||
}
|
|
||||||
|
|
||||||
plotnr = plotnrs[plottype]
|
|
||||||
if workouttype in ('water','coastal'):
|
|
||||||
plotnr = plotnr+3
|
|
||||||
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
res = handle_makeplot.delay(f1,f2,t,
|
|
||||||
hrpwrdata,plotnr,
|
|
||||||
imagename)
|
|
||||||
else:
|
|
||||||
res = queue.enqueue(handle_makeplot,f1,f2,
|
|
||||||
t,hrpwrdata,
|
|
||||||
plotnr,imagename)
|
|
||||||
|
|
||||||
|
|
||||||
i = GraphImage(workout=w,
|
|
||||||
creationdatetime=timezone.now(),
|
|
||||||
filename=fullpathimagename)
|
|
||||||
i.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user