commit
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from rowers.mytypes import workouttypes, boattypes, otwtypes, workoutsources, workouttypes_ordered
|
||||
import rowers.c2stuff as c2stuff
|
||||
from rowers.rower_rules import is_promember
|
||||
import rowers.tpstuff as tpstuff
|
||||
import rowers.sporttracksstuff as sporttracksstuff
|
||||
import rowers.stravastuff as stravastuff
|
||||
from rowers.utils import (
|
||||
geo_distance, serialize_list, deserialize_list, uniqify,
|
||||
str2bool, range_to_color_hex, absolute, myqueue, NoTokenError
|
||||
)
|
||||
# for actions related to uploads
|
||||
from django.conf import settings
|
||||
from django.utils import timezone,translation
|
||||
from django.utils import timezone, translation
|
||||
from rowers.tasks import (
|
||||
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||
handle_sendemail_unrecognized, handle_sendemailnewcomment,
|
||||
handle_sendemailnewresponse, handle_updatedps,
|
||||
handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
|
||||
handle_makeplot, handle_otwsetpower, handle_sendemailtcx,
|
||||
handle_sendemailcsv
|
||||
)
|
||||
)
|
||||
|
||||
from rowers.models import GraphImage
|
||||
|
||||
@@ -35,7 +41,6 @@ queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
queuehigh = django_rq.get_queue('high')
|
||||
|
||||
from rowers.mytypes import workouttypes,boattypes,otwtypes,workoutsources, workouttypes_ordered
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
@@ -43,18 +48,10 @@ except:
|
||||
from io import StringIO
|
||||
|
||||
|
||||
from rowers.utils import (
|
||||
geo_distance,serialize_list,deserialize_list,uniqify,
|
||||
str2bool,range_to_color_hex,absolute,myqueue,NoTokenError
|
||||
)
|
||||
sources = [s for s, name in workoutsources]
|
||||
|
||||
|
||||
sources = [s for s,name in workoutsources]
|
||||
|
||||
|
||||
|
||||
|
||||
def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
|
||||
def make_plot(r, w, f1, f2, plottype, title, imagename='', plotnr=0):
|
||||
if imagename == '':
|
||||
imagename = f1[:-4]+'.png'
|
||||
fullpathimagename = 'static/plots/'+imagename
|
||||
@@ -62,35 +59,35 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
|
||||
powerperc = 100*np.array([r.pw_ut2,
|
||||
r.pw_ut1,
|
||||
r.pw_at,
|
||||
r.pw_tr,r.pw_an])/r.ftp
|
||||
r.pw_tr, r.pw_an])/r.ftp
|
||||
|
||||
ftp = float(r.ftp)
|
||||
if w.workouttype in otwtypes:
|
||||
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),
|
||||
'hrzones':serialize_list(r.hrzones),
|
||||
'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),
|
||||
'hrzones': serialize_list(r.hrzones),
|
||||
}
|
||||
|
||||
# make plot - asynchronous task
|
||||
plotnrs = {
|
||||
'timeplot':1,
|
||||
'distanceplot':2,
|
||||
'pieplot':3,
|
||||
'None':0,
|
||||
'timeplot': 1,
|
||||
'distanceplot': 2,
|
||||
'pieplot': 3,
|
||||
'None': 0,
|
||||
}
|
||||
|
||||
axis = r.staticgrids
|
||||
if axis == None: # pragma: no cover
|
||||
if axis == None: # pragma: no cover
|
||||
gridtrue = False
|
||||
axis = 'both'
|
||||
else:
|
||||
@@ -99,22 +96,21 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
|
||||
if plotnr == 0:
|
||||
plotnr = plotnrs[plottype]
|
||||
if plotnr == 0:
|
||||
return 0,0
|
||||
return 0, 0
|
||||
|
||||
if w.workouttype in otwtypes:
|
||||
plotnr = plotnr+3
|
||||
|
||||
otwrange = [r.fastpaceotw.total_seconds(),r.slowpaceotw.total_seconds()]
|
||||
oterange = [r.fastpaceerg.total_seconds(),r.slowpaceerg.total_seconds()]
|
||||
otwrange = [r.fastpaceotw.total_seconds(), r.slowpaceotw.total_seconds()]
|
||||
oterange = [r.fastpaceerg.total_seconds(), r.slowpaceerg.total_seconds()]
|
||||
|
||||
|
||||
job = myqueue(queuehigh,handle_makeplot,f1,f2,
|
||||
title,hrpwrdata,
|
||||
plotnr,imagename,gridtrue=gridtrue,axis=axis,
|
||||
otwrange=otwrange,oterange=oterange)
|
||||
job = myqueue(queuehigh, handle_makeplot, f1, f2,
|
||||
title, hrpwrdata,
|
||||
plotnr, imagename, gridtrue=gridtrue, axis=axis,
|
||||
otwrange=otwrange, oterange=oterange)
|
||||
|
||||
try:
|
||||
width,height = Image.open(fullpathimagename).size
|
||||
width, height = Image.open(fullpathimagename).size
|
||||
except:
|
||||
width = 1200
|
||||
height = 600
|
||||
@@ -124,25 +120,16 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
|
||||
i = GraphImage(workout=w,
|
||||
creationdatetime=timezone.now(),
|
||||
filename=fullpathimagename,
|
||||
width=width,height=height)
|
||||
width=width, height=height)
|
||||
|
||||
i.save()
|
||||
else: # pragma: no cover
|
||||
return 0,'You have reached the maximum number of static images for this workout. Delete an image first'
|
||||
else: # pragma: no cover
|
||||
return 0, 'You have reached the maximum number of static images for this workout. Delete an image first'
|
||||
|
||||
return i.id,job.id
|
||||
|
||||
import rowers.c2stuff as c2stuff
|
||||
import rowers.stravastuff as stravastuff
|
||||
import rowers.sporttracksstuff as sporttracksstuff
|
||||
|
||||
import rowers.tpstuff as tpstuff
|
||||
|
||||
from rowers.rower_rules import is_promember
|
||||
return i.id, job.id
|
||||
|
||||
|
||||
|
||||
def do_sync(w,options, quick=False):
|
||||
def do_sync(w, options, quick=False):
|
||||
|
||||
do_strava_export = w.user.strava_auto_export
|
||||
try:
|
||||
@@ -151,7 +138,7 @@ def do_sync(w,options, quick=False):
|
||||
upload_to_strava = False
|
||||
|
||||
try:
|
||||
if options['stravaid'] != 0 and options['stravaid'] != '': # pragma: no cover
|
||||
if options['stravaid'] != 0 and options['stravaid'] != '': # pragma: no cover
|
||||
w.uploadedtostrava = options['stravaid']
|
||||
upload_to_strava = False
|
||||
do_strava_export = False
|
||||
@@ -159,29 +146,27 @@ def do_sync(w,options, quick=False):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
if options['nkid'] != 0 and options['nkid'] != '': # pragma: no cover
|
||||
if options['nkid'] != 0 and options['nkid'] != '': # pragma: no cover
|
||||
w.uploadedtonk = options['nkid']
|
||||
w.save()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
if options['inboard'] != 0 and options['inboard'] != '': # pragma: no cover
|
||||
if options['inboard'] != 0 and options['inboard'] != '': # pragma: no cover
|
||||
w.inboard = options['inboard']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
if options['oarlength'] != 0 and options['oarlength'] != '': # pragma: no cover
|
||||
if options['oarlength'] != 0 and options['oarlength'] != '': # pragma: no cover
|
||||
w.oarlength = options['oarlength']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
if options['garminid'] != 0 and options['garminid'] != '': # pragma: no cover
|
||||
if options['garminid'] != 0 and options['garminid'] != '': # pragma: no cover
|
||||
w.uploadedtogarmin = options['garminid']
|
||||
w.save()
|
||||
except KeyError:
|
||||
@@ -194,7 +179,7 @@ def do_sync(w,options, quick=False):
|
||||
upload_to_c2 = False
|
||||
|
||||
try:
|
||||
if options['c2id'] != 0 and options['c2id'] != '': # pragma: no cover
|
||||
if options['c2id'] != 0 and options['c2id'] != '': # pragma: no cover
|
||||
w.uploadedtoc2 = options['c2id']
|
||||
upload_to_c2 = False
|
||||
do_c2_export = False
|
||||
@@ -203,7 +188,7 @@ def do_sync(w,options, quick=False):
|
||||
pass
|
||||
|
||||
try:
|
||||
if options['rp3id'] != 0 and options['rp3id'] != '': # pragma: no cover
|
||||
if options['rp3id'] != 0 and options['rp3id'] != '': # pragma: no cover
|
||||
w.uploadedtorp3 = options['rp3id']
|
||||
w.save()
|
||||
except KeyError:
|
||||
@@ -212,68 +197,66 @@ def do_sync(w,options, quick=False):
|
||||
if w.duplicate:
|
||||
return 0
|
||||
|
||||
if do_c2_export: # pragma: no cover
|
||||
if do_c2_export: # pragma: no cover
|
||||
try:
|
||||
message,id = c2stuff.workout_c2_upload(w.user.user,w,asynchron=True)
|
||||
message, id = c2stuff.workout_c2_upload(
|
||||
w.user.user, w, asynchron=True)
|
||||
except NoTokenError:
|
||||
id = 0
|
||||
message = "Something went wrong with the Concept2 sync"
|
||||
except: # pragma: no cover
|
||||
except: # pragma: no cover
|
||||
pass
|
||||
|
||||
if do_strava_export: # pragma: no cover
|
||||
if do_strava_export: # pragma: no cover
|
||||
try:
|
||||
message,id = stravastuff.workout_strava_upload(
|
||||
w.user.user,w,quick=quick,asynchron=True,
|
||||
message, id = stravastuff.workout_strava_upload(
|
||||
w.user.user, w, quick=quick, asynchron=True,
|
||||
)
|
||||
dologging(
|
||||
'strava_export_log.log',
|
||||
'exporting workout {id} as {type}'.format(
|
||||
id=w.id,
|
||||
type = w.workouttype,
|
||||
)
|
||||
type=w.workouttype,
|
||||
)
|
||||
except NoTokenError: # pragma: no cover
|
||||
)
|
||||
except NoTokenError: # pragma: no cover
|
||||
id = 0
|
||||
message = "Please connect to Strava first"
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
t = time.localtime()
|
||||
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||
with open('stravalog.log','a') as f:
|
||||
with open('stravalog.log', 'a') as f:
|
||||
f.write('\n')
|
||||
f.write(timestamp)
|
||||
f.write(str(e))
|
||||
|
||||
|
||||
do_tp_export = w.user.trainingpeaks_auto_export
|
||||
try: # pragma: no cover
|
||||
try: # pragma: no cover
|
||||
upload_to_tp = options['upload_to_SportTracks'] or do_tp_export
|
||||
do_tp_export = upload_to_tp
|
||||
except KeyError:
|
||||
upload_to_tp = False
|
||||
|
||||
if do_tp_export: # pragma: no cover
|
||||
if do_tp_export: # pragma: no cover
|
||||
try:
|
||||
message,id = sporttracksstuff.workout_sporttracks_upload(
|
||||
w.user.user,w,asynchron=True,
|
||||
message, id = sporttracksstuff.workout_sporttracks_upload(
|
||||
w.user.user, w, asynchron=True,
|
||||
)
|
||||
with open('st_export.log','a') as logfile: # pragma: no cover
|
||||
with open('st_export.log', 'a') as logfile: # pragma: no cover
|
||||
logfile.write(str(timezone.now())+': ')
|
||||
logfile.write('Workout uploaded '+str(w.id)+'\n')
|
||||
except NoTokenError:
|
||||
with open('st_export.log','a') as logfile:
|
||||
with open('st_export.log', 'a') as logfile:
|
||||
logfile.write(str(timezone.now())+': ')
|
||||
logfile.write(str(w.user)+' NoTokenError\n')
|
||||
message = "Please connect to SportTracks first"
|
||||
id = 0
|
||||
|
||||
|
||||
|
||||
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export): # pragma: no cover
|
||||
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export): # pragma: no cover
|
||||
try:
|
||||
message,id = tpstuff.workout_tp_upload(
|
||||
w.user.user,w
|
||||
message, id = tpstuff.workout_tp_upload(
|
||||
w.user.user, w
|
||||
)
|
||||
except NoTokenError:
|
||||
message = "Please connect to TrainingPeaks first"
|
||||
|
||||
Reference in New Issue
Block a user