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

@@ -154,8 +154,8 @@ class InstrokeForm(forms.Form):
metric = forms.ChoiceField(label='metric',choices=(('a','a'),('b','b')))
individual_curves = forms.BooleanField(label='individual curves',initial=False,
required=False)
spm_min = forms.IntegerField(initial=15,label='SPM Min',widget=HiddenInput)
spm_max = forms.IntegerField(initial=45,label='SPM Max',widget=HiddenInput)
spm_min = forms.FloatField(initial=15,label='SPM Min',widget=HiddenInput)
spm_max = forms.FloatField(initial=45,label='SPM Max',widget=HiddenInput)
activeminutesmin = forms.FloatField(
required=False, initial=0, widget=forms.HiddenInput())
activeminutesmax = forms.FloatField(

View File

@@ -4318,6 +4318,9 @@ def instroke_interactive_chart(df,metric, workout, spm_min, spm_max,
df_pos = (df+abs(df))/2.
df_min = -(-df+abs(-df))/2.
if df.empty:
return "", "No data in selection"
mean_vals = df.median().replace(0, np.nan)
q75 = df_pos.quantile(q=0.75).replace(0,np.nan)
q25 = df_pos.quantile(q=0.25).replace(0,np.nan)

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)

View File

@@ -62,6 +62,7 @@ $( function() {
range: true,
min: 0,
max: 60,
step: 0.1,
values: [ {{ spm_min }}, {{ spm_max }} ],
slide: function( event, ui ) {
$( "#amountspm" ).val(ui.values[ 0 ] + " - " + ui.values[ 1 ] );

View File

@@ -1113,13 +1113,23 @@ def workout_rojaboimport_view(request, message="", userid=0):
ps.save()
# get steps if there are any
steps = []
if item['warm_up']:
try:
steps.append(rojabostuff.stepsconvert(item['warm_up']))
except KeyError:
pass
if item['primary']:
try:
steps.append(rojabostuff.stepsconvert(item['primary']))
except KeyError:
pass
if item['cool_down']:
try:
steps.append(rojabostuff.stepsconvert(item['cool_down']))
except KeyError:
pass
if steps:
ps.steps = steps
ps.save()
messages.info(request,'Saved planned session {id}'.format(id=ps.id))
except KeyError:
pass