Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2021-02-25 15:48:15 +01:00
parent 6577614f21
commit d7048c182f
2 changed files with 99 additions and 70 deletions

View File

@@ -81,102 +81,129 @@ from rowers.tasks import (
from rowers.utils import totaltime_sec_to_string from rowers.utils import totaltime_sec_to_string
def step_to_string(step): def step_to_string(step):
print(step)
target_dict = { target_dict = {
'heart_rate': { 'HeartRate': {
'name':'Heart Rate between', 'name':'Heart Rate between',
'low':'custom_target_heart_rate_low', 'low': 'custom_target_power_low',
'high': 'custom_target_heart_rate_high' 'high': 'custom_target_power_high',
}, },
'speed':{ 'Speed':{
'name': 'Speed between', 'name': 'Speed between',
'low': 'custom_target_speed_low', 'low': 'custom_target_power_low',
'high': 'custom_target_speed_high', 'high': 'custom_target_power_high',
}, },
'cadence':{ 'Cadence':{
'name': 'SPM between', 'name': 'SPM between',
'low': 'custom_target_cadence_low', 'low': 'custom_target_power_low',
'high': 'custom_target_cadence_high', 'high': 'custom_target_power_high',
}, },
'open':{ 'Open':{
'name': 'between', 'name': 'between',
'low': 'custom_target_value_low', 'low': 'targetValueLow',
'high': 'custom_target_value_high', 'high': 'targetValueHigh',
}, },
'power':{ 'Power':{
'name': 'Power between', 'name': 'Power between',
'low': 'custom_target_power_low', 'low': 'custom_target_power_low',
'high': 'custom_target_power_high', 'high': 'custom_target_power_high',
}, },
'stroke_type':{ 'SwimStroke':{
'name': 'Stroke type', 'name': 'Stroke type',
'low': 'target_swim_stroke', 'low': 'target_swim_stroke',
'high': '', 'high': '',
}, },
} }
duration = '' nr = 0
repeat = ''
target = ''
intensity = ''
nr = ''
name = '' name = ''
intensity = ''
duration = ''
unit = ''
target = ''
repeat = ''
for key, value in step.items(): durationtype = step['durationType']
if key == 'duration_distance': if durationtype == 'Time':
duration = '{v} m'.format(v=value) unit = 'min'
if key == 'duration_time': value = step['durationValue']
dd = timedelta(seconds=value) dd = timedelta(seconds=value/1000.)
duration = '{v} min'.format(v=str(dd)) duration = '{v}'.format(v=str(dd))
if key in ['duration_hr']: elif durationtype == 'Distance':
duration = 'until HR reaches {v}'.format(v=value) unit = 'm'
if key == 'target_type' and value is not None: value = step['durationValue']/100.
dd = target_dict[value] duration = int(value)
t = dd['name'] elif durationtype == 'HrLessThan':
l = '' value = step['durationValue']
h = '' if value < 100:
try: duration = 'until heart rate lower than {v}% of max'.format(v=value)
if dd['low']: else:
v = step[dd['low']] duration = 'until heart rate lower than {v}'.format(v=value-100)
if value == 'heart_rate': elif durationtype == 'HrGreaterThan':
if v<100: value = step['durationValue']
v = '{v} \%'.format(v=v) if value < 100:
else: duration = 'until heart rate greater than {v}% of max'.format(v=value)
v = v-100 else:
v = '{v}'.format(v=v) duration = 'until heart rate greater than {v}'.format(v=value-100)
l = '{v}'.format(v=v)
except KeyError:
pass
try:
if dd['high']:
v = step[dd['high']]
if value == 'heart_rate':
if v<100:
v = '{v} \%'.format(v=v)
else:
v = v-100
v = '{v}'.format(v=v)
h = 'and {v}'.format(v=v)
except KeyError:
pass
target = '{t} {l} {h}'.format( targettype = step['targetType']
t = t,
l = l,
h = h,
)
if key == 'intensity':
intensity = '{v}'.format(v=value)
if key == 'repeat':
pass
if key == 'message_index':
nr = '{v}'.format(v=value)
if key == 'wkt_step_name':
name = '{v}'.format(v=value)
s = '{nr}: {name} {intensity} {duration} {target} {repeat}'.format( if targettype == 'HeartRate':
value = step['targetValue']
valuelow = step['targetValueLow']
valuehigh = step['targetValueHigh']
if value < 10 and value>0:
target = 'Target: Heart Rate in zone {v}'.format(v=value)
else:
if valuelow < 100:
target = 'Target: Heart Rate between {l} and {h} % of max'.format(
l = valuelow,
h = valuehigh
)
else:
target = 'Target: Heart Rate between {l} and {h}'.format(
l = valuelow-100,
h = valuehigh+100
)
elif targettype == 'Power':
value = step['targetValue']
valuelow = step['targetValueLow']
valuehigh = step['targetValueHigh']
if value < 10 and value>0:
target = 'Target: Power in zone {v}'.format(v=value)
else:
if valuelow < 1000:
target = 'Target: Power between {l} and {h} % of FTP'.format(
l = valuelow,
h = valuehigh
)
else:
target = 'Target: Power between {l} and {h} W'.format(
l = valuelow-1000,
h = valuehigh-1000
)
elif targettype == 'Speed':
value = step['targetValue']
valuelow = step['targetValueLow']
valuehigh = step['targetValueHigh']
target = 'Target: Speed at {v} m/s'.format(v=value/1000.)
nr = step['stepId']
name = step['wkt_step_name']
intensity = step['intensity']
s = '{nr}: {name} {intensity} {duration} {unit} {target} {repeat}'.format(
nr = nr, nr = nr,
name = name, name = name,
unit=unit,
intensity = intensity, intensity = intensity,
duration = duration, duration = duration,
target=target, target=target,

View File

@@ -1912,6 +1912,8 @@ def plannedsession_view(request,id=0,userid=0):
r = getrequestplanrower(request,userid=userid) r = getrequestplanrower(request,userid=userid)
ps = get_object_or_404(PlannedSession,pk=id) ps = get_object_or_404(PlannedSession,pk=id)
jsons = json.loads(ps.steps_json)
try: try:
r = VirtualRace.objects.get(id=ps.id) r = VirtualRace.objects.get(id=ps.id)