Merge branch 'develop' into feature/workoutfit
This commit is contained in:
@@ -214,6 +214,7 @@ def get_c2_workouts(rower,do_async=True):
|
|||||||
c2id,
|
c2id,
|
||||||
counter
|
counter
|
||||||
)
|
)
|
||||||
|
#res = handle_c2_async_workout(alldata,rower.user.id,rower.c2token,c2id,counter)
|
||||||
counter = counter+1
|
counter = counter+1
|
||||||
else:
|
else:
|
||||||
workoutid = create_async_workout(alldata,
|
workoutid = create_async_workout(alldata,
|
||||||
@@ -404,6 +405,37 @@ def create_async_workout(alldata,user,c2id):
|
|||||||
c2blocked.seek(0)
|
c2blocked.seek(0)
|
||||||
json.dump(data,c2blocked)
|
json.dump(data,c2blocked)
|
||||||
|
|
||||||
|
# summary
|
||||||
|
if 'workout' in data:
|
||||||
|
if 'splits' in data['workout']:
|
||||||
|
splitdata = data['workout']['splits']
|
||||||
|
elif 'intervals' in data['workout']:
|
||||||
|
splitdata = data['workout']['intervals']
|
||||||
|
else:
|
||||||
|
splitdata = False
|
||||||
|
else:
|
||||||
|
splitdata = False
|
||||||
|
|
||||||
|
if splitdata:
|
||||||
|
summary,sa,results = c2stuff.summaryfromsplitdata(splitdata,data,csvfilename,workouttype=workouttype)
|
||||||
|
w = Workout.objects.get(id=workoutid)
|
||||||
|
w.summary = summary
|
||||||
|
w.save()
|
||||||
|
|
||||||
|
from rowingdata.trainingparser import getlist
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
return workoutid
|
return workoutid
|
||||||
|
|
||||||
|
|||||||
211
rowers/tasks.py
211
rowers/tasks.py
@@ -79,6 +79,7 @@ from rowers.dataprepnodjango import (
|
|||||||
# create_strava_stroke_data_db
|
# create_strava_stroke_data_db
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
from rowers.opaque import encoder
|
from rowers.opaque import encoder
|
||||||
|
|
||||||
from django.core.mail import (
|
from django.core.mail import (
|
||||||
@@ -118,6 +119,162 @@ from rowers.courseutils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Concept2 logbook sends over split data for each interval
|
||||||
|
# We use it here to generate a custom summary
|
||||||
|
# Some users complained about small differences
|
||||||
|
def summaryfromsplitdata(splitdata,data,filename,sep='|',workouttype='rower'):
|
||||||
|
workouttype = workouttype.lower()
|
||||||
|
|
||||||
|
totaldist = data['distance']
|
||||||
|
totaltime = data['time']/10.
|
||||||
|
try:
|
||||||
|
spm = data['stroke_rate']
|
||||||
|
except KeyError:
|
||||||
|
spm = 0
|
||||||
|
try:
|
||||||
|
resttime = data['rest_time']/10.
|
||||||
|
except KeyError:
|
||||||
|
resttime = 0
|
||||||
|
try:
|
||||||
|
restdistance = data['rest_distance']
|
||||||
|
except KeyError:
|
||||||
|
restdistance = 0
|
||||||
|
try:
|
||||||
|
avghr = data['heart_rate']['average']
|
||||||
|
except KeyError:
|
||||||
|
avghr = 0
|
||||||
|
try:
|
||||||
|
maxhr = data['heart_rate']['max']
|
||||||
|
except KeyError:
|
||||||
|
maxhr = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
avgpace = 500.*totaltime/totaldist
|
||||||
|
except (ZeroDivisionError,OverflowError):
|
||||||
|
avgpace = 0.
|
||||||
|
|
||||||
|
try:
|
||||||
|
restpace = 500.*resttime/restdistance
|
||||||
|
except (ZeroDivisionError,OverflowError):
|
||||||
|
restpace = 0.
|
||||||
|
|
||||||
|
velo = totaldist/totaltime
|
||||||
|
avgpower = 2.8*velo**(3.0)
|
||||||
|
if workouttype in ['bike','bikeerg']:
|
||||||
|
velo = velo/2.
|
||||||
|
avgpower = 2.8*velo**(3.0)
|
||||||
|
velo = velo*2
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
restvelo = restdistance/resttime
|
||||||
|
except (ZeroDivisionError,OverflowError):
|
||||||
|
restvelo = 0
|
||||||
|
|
||||||
|
restpower = 2.8*restvelo**(3.0)
|
||||||
|
if workouttype in ['bike','bikeerg']:
|
||||||
|
restvelo = restvelo/2.
|
||||||
|
restpower = 2.8*restvelo**(3.0)
|
||||||
|
restvelo = restvelo*2
|
||||||
|
|
||||||
|
try:
|
||||||
|
avgdps = totaldist/data['stroke_count']
|
||||||
|
except (ZeroDivisionError,OverflowError,KeyError):
|
||||||
|
avgdps = 0
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
sums += '\nWorkout Details\n'
|
||||||
|
sums += '#-{sep}SDist{sep}-Split-{sep}-SPace-{sep}-Pwr-{sep}SPM-{sep}AvgHR{sep}MaxHR{sep}DPS-\n'.format(
|
||||||
|
sep=sep
|
||||||
|
)
|
||||||
|
|
||||||
|
intervalnr=0
|
||||||
|
sa = []
|
||||||
|
results = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
timebased = data['workout_type'] in ['FixedTimeSplits','FixedTimeInterval']
|
||||||
|
except KeyError:
|
||||||
|
timebased = False
|
||||||
|
|
||||||
|
for interval in splitdata:
|
||||||
|
try:
|
||||||
|
idist = interval['distance']
|
||||||
|
except KeyError:
|
||||||
|
idist = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
itime = interval['time']/10.
|
||||||
|
except KeyError:
|
||||||
|
itime = 0
|
||||||
|
try:
|
||||||
|
ipace = 500.*itime/idist
|
||||||
|
except (ZeroDivisionError,OverflowError):
|
||||||
|
ipace = 180.
|
||||||
|
|
||||||
|
try:
|
||||||
|
ispm = interval['stroke_rate']
|
||||||
|
except KeyError:
|
||||||
|
ispm = 0
|
||||||
|
try:
|
||||||
|
irest_time = interval['rest_time']/10.
|
||||||
|
except KeyError:
|
||||||
|
irest_time = 0
|
||||||
|
try:
|
||||||
|
iavghr = interval['heart_rate']['average']
|
||||||
|
except KeyError:
|
||||||
|
iavghr = 0
|
||||||
|
try:
|
||||||
|
imaxhr = interval['heart_rate']['average']
|
||||||
|
except KeyError:
|
||||||
|
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
|
||||||
|
|
||||||
|
if itime != 0:
|
||||||
|
ivelo = idist/itime
|
||||||
|
ipower = 2.8*ivelo**(3.0)
|
||||||
|
if workouttype in ['bike','bikeerg']:
|
||||||
|
ipower = 2.8*(ivelo/2.)**(3.0)
|
||||||
|
else:
|
||||||
|
ivelo = 0
|
||||||
|
ipower = 0
|
||||||
|
|
||||||
|
sums += interval_string(intervalnr,idist,itime,ipace,ispm,
|
||||||
|
iavghr,imaxhr,0,ipower,separator=sep)
|
||||||
|
intervalnr+=1
|
||||||
|
|
||||||
|
return sums,sa,results
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def add(x, y):
|
def add(x, y):
|
||||||
return x + y
|
return x + y
|
||||||
@@ -2965,8 +3122,9 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,debug=False,**k
|
|||||||
newc2id = 0
|
newc2id = 0
|
||||||
with engine.connect() as conn, conn.begin():
|
with engine.connect() as conn, conn.begin():
|
||||||
result = conn.execute(query)
|
result = conn.execute(query)
|
||||||
data = result.fetchall()
|
tdata = result.fetchall()
|
||||||
newc2id = data[0][0]
|
if tdata:
|
||||||
|
newc2id = tdata[0][0]
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
@@ -2977,9 +3135,54 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,debug=False,**k
|
|||||||
|
|
||||||
newparkedids = [id for id in parkedids if id != newc2id]
|
newparkedids = [id for id in parkedids if id != newc2id]
|
||||||
with open('c2blocked.json','wt') as c2blocked:
|
with open('c2blocked.json','wt') as c2blocked:
|
||||||
data = {'ids':newparkedids}
|
tdata = {'ids':newparkedids}
|
||||||
c2blocked.seek(0)
|
c2blocked.seek(0)
|
||||||
json.dump(data,c2blocked)
|
json.dump(tdata,c2blocked)
|
||||||
|
|
||||||
|
# set distance, time
|
||||||
|
query = "UPDATE `rowers_workout` SET `distance` = '%s', `duration` = '%s' WHERE `id` = '%s'" % (distance, duration, workoutid)
|
||||||
|
|
||||||
|
with engine.connect() as conn, conn.begin():
|
||||||
|
result = conn.execute(query)
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
engine.dispose()
|
||||||
|
|
||||||
|
# summary
|
||||||
|
if 'workout' in data:
|
||||||
|
if 'splits' in data['workout']:
|
||||||
|
splitdata = data['workout']['splits']
|
||||||
|
elif 'intervals' in data['workout']:
|
||||||
|
splitdata = data['workout']['intervals']
|
||||||
|
else:
|
||||||
|
splitdata = False
|
||||||
|
else:
|
||||||
|
splitdata = False
|
||||||
|
|
||||||
|
if splitdata:
|
||||||
|
summary,sa,results = summaryfromsplitdata(splitdata,data,csvfilename,workouttype=workouttype)
|
||||||
|
|
||||||
|
query = "UPDATE `rowers_workout` SET `summary` = '%s' WHERE `id` = %s" % (summary, workoutid)
|
||||||
|
|
||||||
|
with engine.connect() as conn, conn.begin():
|
||||||
|
result = conn.execute(query)
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
engine.dispose()
|
||||||
|
|
||||||
|
from rowingdata.trainingparser import getlist
|
||||||
|
if sa:
|
||||||
|
values = getlist(sa)
|
||||||
|
units = getlist(sa,sel='unit')
|
||||||
|
types = getlist(sa,sel='type')
|
||||||
|
|
||||||
|
rowdata = rdata(csvfilename)
|
||||||
|
if rowdata:
|
||||||
|
rowdata.updateintervaldata(values,
|
||||||
|
units,types,results)
|
||||||
|
|
||||||
|
rowdata.write_csv(csvfilename,gzip=True)
|
||||||
|
dataprepnodjango.update_strokedata(w.id,rowdata.df)
|
||||||
|
|
||||||
return workoutid
|
return workoutid
|
||||||
|
|
||||||
|
|||||||
@@ -737,8 +737,11 @@ def rower_process_garmincallback(request):
|
|||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
absoluteurl = request.build_absolute_uri()
|
absoluteurl = request.build_absolute_uri()
|
||||||
|
|
||||||
|
try:
|
||||||
key = request.session['garmin_owner_key']
|
key = request.session['garmin_owner_key']
|
||||||
secret = request.session['garmin_owner_secret']
|
secret = request.session['garmin_owner_secret']
|
||||||
|
except KeyError:
|
||||||
|
authorization_url, key, secret = garmin_stuff.garmin_authorize()
|
||||||
garmintoken,garminrefreshtoken = garmin_stuff.garmin_processcallback(absoluteurl,key,secret)
|
garmintoken,garminrefreshtoken = garmin_stuff.garmin_processcallback(absoluteurl,key,secret)
|
||||||
r.garmintoken = garmintoken
|
r.garmintoken = garmintoken
|
||||||
r.garminrefreshtoken = garminrefreshtoken
|
r.garminrefreshtoken = garminrefreshtoken
|
||||||
|
|||||||
Reference in New Issue
Block a user