Private
Public Access
1
0

rojabo v2

This commit is contained in:
Sander Roosendaal
2022-10-31 20:58:06 +01:00
parent a20e93a0e6
commit cd8a0456c8
5 changed files with 80 additions and 6 deletions

View File

@@ -169,6 +169,66 @@ aweekago = timezone.now()-timedelta(days=7)
today = timezone.now()
a_week_from_now = timezone.now()+timedelta(days=7)
def stepsconvert(rojabo_steps, startid = 0, warmup = False, cooldown = False):
workout_steps = []
for step in rojabo_steps:
print(step)
durationtype = 'Time'
durationvalue = 10
if step['duration_type'] == 'seconds':
durationvalue = 1000*durationvalue # milliseconds
if step['duration_type'] == 'meters':
durationtype = 'Distance'
durationvalue = step['duration_value']*100 # centimeters
elif step['duration_type'] == 'strokes':
durationtype = 'Time'
try:
durationvalue = int(60.*step['duration_value']/step['stroke_rate'])
except TypeError:
try:
durationvalue = step['time']*1000
except KeyError:
durationvalue = 1000
intensity = 'Active'
if warmup:
intensity = 'Warmup'
if cooldown:
intensity = 'Cooldown'
targettype = 'Power'
targetvalue = step['target_value']
if targetvalue is None:
targettype = 'Cadence'
targetvalue = step['stroke_rate']
if step['target_type'] == 'rest':
targettype = ''
intensity = 'Rest'
targetvalue = 0
description = step['description']
if step['stroke_rate'] is not None:
description = description +' Stroke Rate {cadence} SPM'.format(
cadence = step['stroke_rate']
)
newstep = {
'stepId': startid,
'wkt_step_name': step['id'],
'durationType': durationtype,
'durationValue': durationvalue,
'targetType': targettype,
'targetvalue': targetvalue,
'intensity': intensity,
'description': description
}
startid += 1
workout_steps.append(newstep)
return workout_steps
def get_rojabo_workout_list(user,startdate=aweekago,enddate=a_week_from_now):
r = Rower.objects.get(user=user)
if (r.rojabo_token == '') or (r.rojabo_token is None): # pragma: no cover
@@ -190,7 +250,7 @@ def get_rojabo_workout_list(user,startdate=aweekago,enddate=a_week_from_now):
date2 = enddate.strftime('%Y-%m-%d')
url = ROJABO_OAUTH_LOCATION+'api/v1/training_sessions?from={date1}&to={date2}'.format(date1=date1,date2=date2)
url = ROJABO_OAUTH_LOCATION+'api/v2/training_sessions?from={date1}&to={date2}'.format(date1=date1,date2=date2)
response = requests.get(url, headers=headers)