bike erg import from C2 log
This commit is contained in:
@@ -56,7 +56,8 @@ def c2_open(user):
|
|||||||
|
|
||||||
return thetoken
|
return thetoken
|
||||||
|
|
||||||
def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename):
|
def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename,
|
||||||
|
workouttype='rower'):
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
if (r.c2token == '') or (r.c2token is None):
|
if (r.c2token == '') or (r.c2token is None):
|
||||||
return custom_exception_handler(401,s)
|
return custom_exception_handler(401,s)
|
||||||
@@ -73,7 +74,7 @@ def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename):
|
|||||||
c2id,
|
c2id,
|
||||||
workoutid,
|
workoutid,
|
||||||
starttimeunix,
|
starttimeunix,
|
||||||
csvfilename)
|
csvfilename,workouttype=workouttype)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -164,7 +165,8 @@ def create_async_workout(alldata,user,c2id):
|
|||||||
|
|
||||||
# Check if workout has stroke data, and get the stroke data
|
# Check if workout has stroke data, and get the stroke data
|
||||||
|
|
||||||
result = add_stroke_data(user,c2id,w.id,startdatetime,csvfilename)
|
result = add_stroke_data(user,c2id,w.id,startdatetime,csvfilename,
|
||||||
|
workouttype = w.workouttype)
|
||||||
|
|
||||||
return w.id
|
return w.id
|
||||||
|
|
||||||
@@ -830,6 +832,8 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
pace = pace.replace(0,300)
|
pace = pace.replace(0,300)
|
||||||
|
|
||||||
velo = 500./pace
|
velo = 500./pace
|
||||||
|
if workouttype == 'bike':
|
||||||
|
velo = 1000./pace
|
||||||
|
|
||||||
power = 2.8*velo**3
|
power = 2.8*velo**3
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ def create_c2_stroke_data_db(
|
|||||||
|
|
||||||
# Saves C2 stroke data to CSV and database
|
# Saves C2 stroke data to CSV and database
|
||||||
def add_c2_stroke_data_db(strokedata,workoutid,starttimeunix,csvfilename,
|
def add_c2_stroke_data_db(strokedata,workoutid,starttimeunix,csvfilename,
|
||||||
debug=False):
|
debug=False,workouttype='rower'):
|
||||||
|
|
||||||
res = make_cumvalues(0.1*strokedata['t'])
|
res = make_cumvalues(0.1*strokedata['t'])
|
||||||
cum_time = res[0]
|
cum_time = res[0]
|
||||||
@@ -246,7 +246,10 @@ def add_c2_stroke_data_db(strokedata,workoutid,starttimeunix,csvfilename,
|
|||||||
pace = pace.replace(0,300)
|
pace = pace.replace(0,300)
|
||||||
|
|
||||||
velo = 500./pace
|
velo = 500./pace
|
||||||
|
if workouttype == 'bike':
|
||||||
|
velo = 1000./pace
|
||||||
|
|
||||||
|
# This may be wrong for the bike erg
|
||||||
power = 2.8*velo**3
|
power = 2.8*velo**3
|
||||||
|
|
||||||
# save csv
|
# save csv
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ def handle_c2_import_stroke_data(c2token,
|
|||||||
starttimeunix,
|
starttimeunix,
|
||||||
csvfilename,debug=True,**kwargs):
|
csvfilename,debug=True,**kwargs):
|
||||||
|
|
||||||
|
if 'workouttype' in kwargs:
|
||||||
|
workouttype = kwargs['workouttype']
|
||||||
|
else:
|
||||||
|
workouttype = 'rower'
|
||||||
|
|
||||||
authorizationstring = str('Bearer ' + c2token)
|
authorizationstring = str('Bearer ' + c2token)
|
||||||
headers = {'Authorization': authorizationstring,
|
headers = {'Authorization': authorizationstring,
|
||||||
'user-agent': 'sanderroosendaal',
|
'user-agent': 'sanderroosendaal',
|
||||||
@@ -100,7 +105,7 @@ def handle_c2_import_stroke_data(c2token,
|
|||||||
strokedata = pd.DataFrame.from_dict(s.json()['data'])
|
strokedata = pd.DataFrame.from_dict(s.json()['data'])
|
||||||
result = add_c2_stroke_data_db(
|
result = add_c2_stroke_data_db(
|
||||||
strokedata,workoutid,starttimeunix,
|
strokedata,workoutid,starttimeunix,
|
||||||
csvfilename,debug=debug,
|
csvfilename,debug=debug,workouttype=workouttype
|
||||||
)
|
)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -9757,7 +9757,7 @@ def workout_getimportview(request,externalid,source = 'c2'):
|
|||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
w.uploadedtoc2 = c2id
|
w.uploadedtoc2 = c2id
|
||||||
w.name = 'Imported from C2'
|
w.name = 'Imported from C2'
|
||||||
w.workouttype = 'rower'
|
w.workouttype = workouttype
|
||||||
w.save()
|
w.save()
|
||||||
|
|
||||||
message = "This workout does not have any stroke data associated with it. We created synthetic stroke data."
|
message = "This workout does not have any stroke data associated with it. We created synthetic stroke data."
|
||||||
|
|||||||
Reference in New Issue
Block a user