initial implementation (update splits/intervals in csv file)
This commit is contained in:
@@ -106,6 +106,7 @@ def summaryfromsplitdata(splitdata,data,filename,sep='|'):
|
|||||||
avgdps = totaldist/data['stroke_count']
|
avgdps = totaldist/data['stroke_count']
|
||||||
|
|
||||||
from rowingdata import summarystring,workstring,interval_string
|
from rowingdata import summarystring,workstring,interval_string
|
||||||
|
|
||||||
|
|
||||||
sums = summarystring(totaldist,totaltime,avgpace,spm,avghr,maxhr,
|
sums = summarystring(totaldist,totaltime,avgpace,spm,avghr,maxhr,
|
||||||
avgdps,avgpower,readFile=filename,
|
avgdps,avgpower,readFile=filename,
|
||||||
@@ -124,29 +125,57 @@ def summaryfromsplitdata(splitdata,data,filename,sep='|'):
|
|||||||
)
|
)
|
||||||
|
|
||||||
intervalnr=0
|
intervalnr=0
|
||||||
|
sa = []
|
||||||
|
results = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
timebased = data['workout_type'] in ['FixedTimeSplits','FixedTimeInterval']
|
||||||
|
except KeyError:
|
||||||
|
timebased = False
|
||||||
|
|
||||||
for interval in splitdata:
|
for interval in splitdata:
|
||||||
idist = interval['distance']
|
idist = interval['distance']
|
||||||
itime = interval['time']/10.
|
itime = interval['time']/10.
|
||||||
ipace = 500.*itime/idist
|
ipace = 500.*itime/idist
|
||||||
ispm = interval['stroke_rate']
|
ispm = interval['stroke_rate']
|
||||||
|
try:
|
||||||
|
irest_time = interval['rest_time']
|
||||||
|
except KeyError:
|
||||||
|
irest_time = 0
|
||||||
try:
|
try:
|
||||||
iavghr = interval['heart_rate']['average']
|
iavghr = interval['heart_rate']['average']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
iavghr = 0
|
iavghr = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
imaxhr = interval['heart_rate']['average']
|
imaxhr = interval['heart_rate']['average']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
imaxhr = 0
|
imaxhr = 0
|
||||||
|
|
||||||
|
# create interval values
|
||||||
|
iarr = [idist,'meters','work']
|
||||||
|
resarr = [itime]
|
||||||
|
if timebased:
|
||||||
|
iarr = [itime,'seconds','work']
|
||||||
|
resarr = [idist]
|
||||||
|
|
||||||
|
if irest_time > 0:
|
||||||
|
iarr += [irest_time,'seconds','rest']
|
||||||
|
try:
|
||||||
|
resarr += [interval['rest_distance']]
|
||||||
|
except KeyError:
|
||||||
|
resarr += [np.nan]
|
||||||
|
|
||||||
|
sa += iarr
|
||||||
|
results += resarr
|
||||||
|
|
||||||
ivelo = idist/itime
|
ivelo = idist/itime
|
||||||
ipower = 2.8*ivelo**(3.0)
|
ipower = 2.8*ivelo**(3.0)
|
||||||
|
|
||||||
sums += interval_string(intervalnr,idist,itime,ipace,ispm,
|
sums += interval_string(intervalnr,idist,itime,ipace,ispm,
|
||||||
iavghr,imaxhr,0,ipower,separator=sep)
|
iavghr,imaxhr,0,ipower,separator=sep)
|
||||||
intervalnr+=1
|
intervalnr+=1
|
||||||
|
|
||||||
return sums
|
return sums,sa,results
|
||||||
|
|
||||||
def createc2workoutdata_as_splits(w):
|
def createc2workoutdata_as_splits(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
|
|||||||
@@ -3721,8 +3721,10 @@ def workout_getc2workout_view(request,c2id):
|
|||||||
w.uploadedtoc2=c2id
|
w.uploadedtoc2=c2id
|
||||||
if splitdata:
|
if splitdata:
|
||||||
try:
|
try:
|
||||||
w.summary = c2stuff.summaryfromsplitdata(splitdata,data,w.csvfilename)
|
w.summary,sa,results = c2stuff.summaryfromsplitdata(splitdata,data,w.csvfilename)
|
||||||
except:
|
except:
|
||||||
|
sa = []
|
||||||
|
results = []
|
||||||
with open("media/c2splitdata.log","a") as errorlog:
|
with open("media/c2splitdata.log","a") as errorlog:
|
||||||
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")
|
||||||
@@ -3730,6 +3732,22 @@ def workout_getc2workout_view(request,c2id):
|
|||||||
errorlog.write("views.py line 952\r\n")
|
errorlog.write("views.py line 952\r\n")
|
||||||
|
|
||||||
w.save()
|
w.save()
|
||||||
|
|
||||||
|
from rowingdata.trainingparser import getlist
|
||||||
|
# set stroke data
|
||||||
|
if sa:
|
||||||
|
values = getlist(sa)
|
||||||
|
units = getlist(sa,sel='unit')
|
||||||
|
types = getlist(sa,sel='type')
|
||||||
|
|
||||||
|
rowdata = rdata(w.csvfilename)
|
||||||
|
if rowdata:
|
||||||
|
rowdata.updateintervaldata(values,
|
||||||
|
units,types,results)
|
||||||
|
|
||||||
|
rowdata.write_csv(w.csvfilename,gzip=True)
|
||||||
|
dataprep.update_strokedata(w.id,rowdata.df)
|
||||||
|
|
||||||
url = "/rowers/workout/"+str(id)+"/edit"
|
url = "/rowers/workout/"+str(id)+"/edit"
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user