C2 splits on import
This commit is contained in:
@@ -77,6 +77,72 @@ def c2wc(weightclass):
|
||||
|
||||
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):
|
||||
filename = w.csvfilename
|
||||
row = rowingdata(filename)
|
||||
|
||||
@@ -3697,35 +3697,12 @@ def workout_getc2workout_view(request,c2id):
|
||||
res = c2stuff.get_c2_workout(request.user,c2id)
|
||||
if (res.status_code == 200):
|
||||
data = res.json()['data']
|
||||
<<<<<<< HEAD
|
||||
splitdata = None
|
||||
if 'splits' in data:
|
||||
splitdata = data['splits']
|
||||
if 'intervals' in data:
|
||||
splitdata = data['intervals']
|
||||
if 'stroke_data' in data:
|
||||
# test = data['stroke_data']
|
||||
res2 = c2stuff.get_c2_workout_strokes(request.user,c2id)
|
||||
# 2016-07-27 added below if statement (balkanboy error report)
|
||||
if res2.status_code == 200:
|
||||
strokedata = pd.DataFrame.from_dict(res2.json()['data'])
|
||||
id = add_workout_from_strokedata(request.user,c2id,
|
||||
data,strokedata,
|
||||
splitdata=None,
|
||||
source='c2')
|
||||
w = Workout.objects.get(id=id)
|
||||
w.uploadedtoc2=c2id
|
||||
w.save()
|
||||
url = "/rowers/workout/"+str(id)+"/edit"
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
message = json.loads(s.text)['message']
|
||||
url = reverse(workout_c2import_view,
|
||||
kwargs={
|
||||
'message':message,
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
=======
|
||||
if 'splits' in data['workout']:
|
||||
splitdata = data['workout']['splits']
|
||||
if 'intervals' in data['workout']:
|
||||
splitdata = data['workout']['intervals']
|
||||
|
||||
if data['stroke_data']:
|
||||
res2 = c2stuff.get_c2_workout_strokes(request.user,c2id)
|
||||
else:
|
||||
@@ -3742,10 +3719,19 @@ def workout_getc2workout_view(request,c2id):
|
||||
source='c2')
|
||||
w = Workout.objects.get(id=id)
|
||||
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()
|
||||
url = "/rowers/workout/"+str(id)+"/edit"
|
||||
return HttpResponseRedirect(url)
|
||||
>>>>>>> develop
|
||||
else:
|
||||
# message = json.loads(s.text)['message']
|
||||
message = json.loads(res2.text)['message']
|
||||
|
||||
Reference in New Issue
Block a user