Private
Public Access
1
0

Merge branch 'release/c2splits'

This commit is contained in:
Sander Roosendaal
2017-01-09 21:19:49 +01:00
4 changed files with 101 additions and 5 deletions
+66
View File
@@ -77,6 +77,72 @@ def c2wc(weightclass):
return res return res
def summaryfromsplitdata(splitdata,data,filename,sep='|'):
totaldist = data['distance']
totaltime = data['time']/10.
spm = data['stroke_rate']
resttime = data['rest_time']/10.
restdistance = data['rest_distance']
try:
avghr = data['heart_rate']['average']
except KeyError:
avghr = 0
try:
maxhr = data['heart_rate']['max']
except KeyError:
maxhr = 0
avgpace = 500.*totaltime/totaldist
restpace = 500.*resttime/restdistance
velo = totaldist/totaltime
avgpower = 2.8*velo**(3.0)
restvelo = restdistance/resttime
restpower = 2.8*restvelo**(3.0)
avgdps = totaldist/data['stroke_count']
from rowingdata import summarystring,workstring,interval_string
sums = summarystring(totaldist,totaltime,avgpace,spm,avghr,maxhr,
avgdps,avgpower,readFile=filename,
separator=sep)
sums += workstring(totaldist,totaltime,avgpace,spm,avghr,maxhr,
avgdps,avgpower,separator=sep,symbol='W')
sums += workstring(restdistance,resttime,restpace,0,0,0,0,restpower,
separator=sep,
symbol='R')
intervalnr=0
for interval in splitdata:
idist = interval['distance']
itime = interval['time']/10.
ipace = 500.*itime/idist
ispm = interval['stroke_rate']
try:
iavghr = interval['heart_rate']['average']
except KeyError:
iavghr = 0
try:
imaxhr = interval['heart_rate']['average']
except KeyError:
imaxhr = 0
ivelo = idist/itime
ipower = 2.8*ivelo**(3.0)
sums += interval_string(intervalnr,idist,itime,ipace,ispm,
iavghr,imaxhr,0,ipower,separator=sep)
intervalnr+=1
return sums
def createc2workoutdata_as_splits(w): def createc2workoutdata_as_splits(w):
filename = w.csvfilename filename = w.csvfilename
row = rowingdata(filename) row = rowingdata(filename)
+1 -1
View File
@@ -1714,7 +1714,7 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
seconds = ["%S"], seconds = ["%S"],
minutes = ["%M"] minutes = ["%M"]
) )
plot.y_range = Range1d(ymin,ymax)
#plot.y_range = Range1d(ymin,ymax) #plot.y_range = Range1d(ymin,ymax)
hover = plot.select(dict(type=HoverTool)) hover = plot.select(dict(type=HoverTool))
+5 -1
View File
@@ -63,12 +63,16 @@ class Command(BaseCommand):
wid = [make_new_workout_from_email(rr,a.document,name)] wid = [make_new_workout_from_email(rr,a.document,name)]
res += wid res += wid
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
dd = send_confirm(u,name,link)
except: except:
# replace with code to process error # replace with code to process error
res += ['fail: '+name] res += ['fail: '+name]
donotdelete = 1 donotdelete = 1
try:
dd = send_confirm(u,name,link)
except:
pass
except Rower.DoesNotExist: except Rower.DoesNotExist:
pass pass
+28 -2
View File
@@ -319,7 +319,8 @@ def checkworkoutuser(user,workout):
except Rower.DoesNotExist: except Rower.DoesNotExist:
return(False) return(False)
def add_workout_from_strokedata(user,importid,data,strokedata,source='c2'): def add_workout_from_strokedata(user,importid,data,strokedata,
source='c2',splitdata=None):
workouttype = data['type'] workouttype = data['type']
if workouttype not in [x[0] for x in Workout.workouttypes]: if workouttype not in [x[0] for x in Workout.workouttypes]:
workouttype = 'water' workouttype = 'water'
@@ -929,6 +930,15 @@ def workout_strava_upload_view(request,id=0):
res = stravastuff.handle_stravaexport(f,w.name, res = stravastuff.handle_stravaexport(f,w.name,
r.stravatoken, r.stravatoken,
description=w.notes) description=w.notes)
except:
with open("media/stravaerrors.log","a") as errorlog:
errorstring = str(sys.exc_info()[0])
timestr = strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\r\n")
errorlog.write("views.py line 937\r\n")
message = 'Error: '+errorstring
res = 0
try:
w.uploadedtostrava = res w.uploadedtostrava = res
w.save() w.save()
os.remove(tcxfile) os.remove(tcxfile)
@@ -939,7 +949,7 @@ def workout_strava_upload_view(request,id=0):
errorstring = str(sys.exc_info()[0]) errorstring = str(sys.exc_info()[0])
timestr = strftime("%Y%m%d-%H%M%S") timestr = strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\r\n") errorlog.write(timestr+errorstring+"\r\n")
errorlog.write("views.py line 946\r\n") errorlog.write("views.py line 952\r\n")
message = 'Error: '+errorstring message = 'Error: '+errorstring
@@ -3687,6 +3697,12 @@ def workout_getc2workout_view(request,c2id):
res = c2stuff.get_c2_workout(request.user,c2id) res = c2stuff.get_c2_workout(request.user,c2id)
if (res.status_code == 200): if (res.status_code == 200):
data = res.json()['data'] data = res.json()['data']
splitdata = None
if 'splits' in data['workout']:
splitdata = data['workout']['splits']
if 'intervals' in data['workout']:
splitdata = data['workout']['intervals']
if data['stroke_data']: if data['stroke_data']:
res2 = c2stuff.get_c2_workout_strokes(request.user,c2id) res2 = c2stuff.get_c2_workout_strokes(request.user,c2id)
else: else:
@@ -3703,6 +3719,16 @@ def workout_getc2workout_view(request,c2id):
source='c2') source='c2')
w = Workout.objects.get(id=id) w = Workout.objects.get(id=id)
w.uploadedtoc2=c2id w.uploadedtoc2=c2id
if splitdata:
try:
w.summary = c2stuff.summaryfromsplitdata(splitdata,data,w.csvfilename)
except:
with open("media/c2splitdata.log","a") as errorlog:
errorstring = str(sys.exc_info()[0])
timestr = strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\r\n")
errorlog.write("views.py line 952\r\n")
w.save() w.save()
url = "/rowers/workout/"+str(id)+"/edit" url = "/rowers/workout/"+str(id)+"/edit"
return HttpResponseRedirect(url) return HttpResponseRedirect(url)