77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
# 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
|
|
|
|
from rowers.utils import (
|
|
geo_distance,serialize_list,deserialize_list,uniqify,
|
|
str2bool,range_to_color_hex,absolute
|
|
)
|
|
|
|
|
|
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
|