Private
Public Access
1
0

fixing fit

This commit is contained in:
2025-01-06 20:27:00 +01:00
parent 7a8271ca95
commit 7c03f11595
3 changed files with 53 additions and 45 deletions

View File

@@ -72,7 +72,7 @@ class PlanStepTest(TestCase):
self.assertEqual(len(steps['steps']),3) self.assertEqual(len(steps['steps']),3)
s = ps.steps_intervals() s = ps.steps_intervals()
expected = '\n\n4x\n- 300s 20rpm Active 0\n- 300s 22rpm Active 1\n\n' expected = '\n\n4x\n- 300s 20rpm active 0\n- 300s 22rpm active 1\n\n'
self.assertEqual(s,expected) self.assertEqual(s,expected)

Binary file not shown.

View File

@@ -755,20 +755,20 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
seconds = 0 seconds = 0
distance = 0 distance = 0
rscore = 0 rscore = 0
durationtype = step.get('durationType', 0) durationtype = step.get('durationType', '')
value = step.get('durationValue', 0) value = step.get('durationValue', 0)
if value == 0: # pragma: no cover if value == 0: # pragma: no cover
return 0, 0, 0 return 0, 0, 0
targettype = step.get('targetType', 0) targettype = step.get('targetType', '')
if durationtype == 'Time': if durationtype.lower() == 'time':
seconds = value/1000. seconds = value/1000.
distance = avgspeed*seconds distance = avgspeed*seconds
rscore = 60.*seconds/3600. rscore = 60.*seconds/3600.
if targettype == 'Speed': # pragma: no cover if targettype.lower() == 'speed': # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -788,7 +788,7 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
rscoreperhour = 100.*veloratio rscoreperhour = 100.*veloratio
rscore = rscoreperhour*seconds/3600. rscore = rscoreperhour*seconds/3600.
if targettype in ['Power','PowerLap']: if targettype.lower() in ['power','powerlap','power_lap']:
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -819,7 +819,7 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
rscore = 100.*(targetpower/ftp)*seconds/3600. rscore = 100.*(targetpower/ftp)*seconds/3600.
if targettype in ['Cadence','CadenceLap']: if targettype.lower() in ['cadence','cadencelap','cadence_lap']:
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -836,12 +836,12 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
rscore = 100*(avgpower/ftp)*seconds/3600. rscore = 100*(avgpower/ftp)*seconds/3600.
return seconds, distance, rscore return seconds, distance, rscore
elif durationtype == 'Distance': elif durationtype.lower() == 'distance':
distance = value/100. distance = value/100.
seconds = distance/avgspeed seconds = distance/avgspeed
rscore = 60.*float(seconds)/3600. rscore = 60.*float(seconds)/3600.
if targettype in ['Speed', 'SpeedLap']: # pragma: no cover if targettype.lower() in ['speed', 'speedlap','speed_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -860,7 +860,7 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
if velomid > 0: if velomid > 0:
seconds = distance/velomid seconds = distance/velomid
if targettype in ['Power','PowerLap']: # pragma: no cover if targettype.lower() in ['power','powerlap','power_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -890,7 +890,7 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
rscore = 100.*(targetpower/ftp)*seconds/3600. rscore = 100.*(targetpower/ftp)*seconds/3600.
if targettype in ['Cadence','CadenceLap']: # pragma: no cover if targettype.lower() in ['cadence','cadencelap','cadence_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -906,7 +906,8 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
seconds = distance/avgspeed seconds = distance/avgspeed
return seconds, distance, rscore return seconds, distance, rscore
elif durationtype in ['PowerLessThan', 'PowerGreaterThan', 'HrLessThan', 'HrGreaterThan']: # pragma: no cover elif durationtype.lower() in ['powerlessthan', 'powergreaterthan', 'hrlessthan', 'hrgreaterthan',
'power_less_than','power_greater_than','hr_less_than', 'hr_greater_than']: # pragma: no cover
seconds = 600 seconds = 600
distance = seconds*avgspeed distance = seconds*avgspeed
veloratio = (avgspeed/ftv)**(3.0) veloratio = (avgspeed/ftv)**(3.0)
@@ -921,7 +922,8 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones
def get_step_type(step): # pragma: no cover def get_step_type(step): # pragma: no cover
t = 'WorkoutStep' t = 'WorkoutStep'
if step['durationType'] in ['RepeatUntilStepsCmplt', 'RepeatUntilHrLessThan', 'RepeatUntilHrGreaterThan']: if step['durationType'].lower() in ['repeatuntilstepscmplt', 'repeatuntilhrlessthan', 'repeatuntilhrgreaterthan',
'repeat_until_steps_cmplt', 'repeat_until_hr_less_than', 'repeat_until_hr_greater_than']:
t = 'WorkoutRepeatStep' t = 'WorkoutRepeatStep'
return t return t
@@ -1081,7 +1083,7 @@ def ps_dict_order(d, short=False, rower=None, html=True):
def step_to_string(step, short=False): def step_to_string(step, short=False):
type = 'Step' stype = 'Step'
repeatID = -1 repeatID = -1
repeatValue = 1 repeatValue = 1
@@ -1096,25 +1098,28 @@ def step_to_string(step, short=False):
durationtype = step['durationType'] durationtype = step['durationType']
if step['durationValue'] == 0: if step['durationValue'] == 0:
if durationtype not in [ if durationtype.lower() not in [
'RepeatUntilStepsCmplt', 'repeatuntilstepscmplt',
'RepeatUntilHrLessThan', 'repeatuntilhrlessthan',
'RepeatUntilHrGreaterThan' 'repeatuntilhrgreaterthan',
'repeat_until_steps_cmplt',
'repeat_until_hr_less_than',
'repeat_until_hr_greater_than'
]: # pragma: no cover ]: # pragma: no cover
return '', type, -1, -1, 1 return '', stype, -1, -1, 1
if durationtype == 'Time': if durationtype.lower() == 'time':
unit = 'min' unit = 'min'
value = step['durationValue'] value = step['durationValue']
if value/1000. >= 3600: # pragma: no cover if value/1000. >= 3600: # pragma: no cover
unit = 'h' unit = 'h'
dd = timedelta(seconds=value/1000.) dd = timedelta(seconds=value/1000.)
duration = '{v}'.format(v=str(dd)) duration = '{v}'.format(v=str(dd))
elif durationtype == 'Distance': elif durationtype.lower() == 'distance':
unit = 'm' unit = 'm'
value = step['durationValue']/100. value = step['durationValue']/100.
duration = int(value) duration = int(value)
elif durationtype == 'HrLessThan': # pragma: no cover elif durationtype.lower() in ['hrlessthan', 'hr_less_than']: # pragma: no cover
value = step['durationValue'] value = step['durationValue']
if value <= 100: if value <= 100:
duration = 'until heart rate lower than {v}% of max'.format( duration = 'until heart rate lower than {v}% of max'.format(
@@ -1125,7 +1130,7 @@ def step_to_string(step, short=False):
duration = 'until heart rate lower than {v}'.format(v=value-100) duration = 'until heart rate lower than {v}'.format(v=value-100)
if short: if short:
duration = 'until HR<{v}'.format(v=value-100) duration = 'until HR<{v}'.format(v=value-100)
elif durationtype == 'HrGreaterThan': # pragma: no cover elif durationtype.lower() in ['hrgreaterthan','hr_greater_than']: # pragma: no cover
value = step['durationValue'] value = step['durationValue']
if value <= 100: if value <= 100:
duration = 'until heart rate greater than {v}% of max'.format( duration = 'until heart rate greater than {v}% of max'.format(
@@ -1136,7 +1141,7 @@ def step_to_string(step, short=False):
duration = 'until heart rate greater than {v}'.format(v=value-100) duration = 'until heart rate greater than {v}'.format(v=value-100)
if short: if short:
duration = 'until HR>{v}'.format(v=value/100) duration = 'until HR>{v}'.format(v=value/100)
elif durationtype == 'PowerLessThan': # pragma: no cover elif durationtype.lower() in ['powerlessthan','power_less_than']: # pragma: no cover
value = step['durationValue'] value = step['durationValue']
targetvalue = step.get('targetValue', 0) targetvalue = step.get('targetValue', 0)
if value <= 1000: if value <= 1000:
@@ -1151,7 +1156,7 @@ def step_to_string(step, short=False):
) )
if short: if short:
'until < {targetvalue} W'.format(targetvalue=targetvalue-1000) 'until < {targetvalue} W'.format(targetvalue=targetvalue-1000)
elif durationtype == 'PowerGreaterThan': # pragma: no cover elif durationtype.lower() in ['powergreaterthan','power_greater_than']: # pragma: no cover
value = step['durationValue'] value = step['durationValue']
targetvalue = step.get('targetValue', 0) targetvalue = step.get('targetValue', 0)
if value <= 1000: if value <= 1000:
@@ -1168,42 +1173,42 @@ def step_to_string(step, short=False):
if short: if short:
duration = 'until > {targetvalue} W'.format( duration = 'until > {targetvalue} W'.format(
targetvalue=targetvalue) targetvalue=targetvalue)
elif durationtype == 'RepeatUntilStepsCmplt': # pragma: no cover elif durationtype.lower() in ['repeatuntilstepscmplt','repeat_until_steps_cmplt']: # pragma: no cover
type = 'RepeatStep' stype = 'RepeatStep'
ntimes = ': {v}x'.format(v=step['targetValue']) ntimes = ': {v}x'.format(v=step['targetValue'])
repeatID = step['durationValue'] repeatID = step['durationValue']
duration = ntimes duration = ntimes
repeatValue = step.get('targetValue', 0) repeatValue = step.get('targetValue', 0)
elif durationtype == 'RepeatUntilHrGreaterThan': # pragma: no cover elif durationtype.lower() in ['repeatuntilhrgreaterthan','repeat_until_hr_greater_than']: # pragma: no cover
type = 'RepeatStep' stype = 'RepeatStep'
targetvalue = step.get('targetValue', 0) targetvalue = step.get('targetValue', 0)
if targetvalue <= 100: if targetvalue <= 100:
duration = 'Repeat until Heart Rate is greater than {targetvalue} % of max'.format( duration = 'until Heart Rate is greater than {targetvalue} % of max'.format(
targetvalue=targetvalue targetvalue=targetvalue
) )
if short: if short:
duration = ': until HR>{targetvalue} % of max'.format( duration = ': until HR>{targetvalue} % of max'.format(
targetvalue=targetvalue) targetvalue=targetvalue)
else: else:
duration = 'Repeat until Heart Rate is greater than {targetvalue}:'.format( duration = 'until Heart Rate is greater than {targetvalue}:'.format(
targetvalue=targetvalue-100. targetvalue=targetvalue-100.
) )
if short: if short:
duration = ': untl HR>{targetvalue}'.format( duration = ': untl HR>{targetvalue}'.format(
targetvalue=targetvalue-100) targetvalue=targetvalue-100)
repeatID = step['durationValue'] repeatID = step['durationValue']
elif durationtype == 'RepeatUntilHrLessThan': # pragma: no cover elif durationtype.lower() in ['repeatuntilhrlessthan','repeat_until_hr_less_than']: # pragma: no cover
type = 'RepeatStep' stype = 'RepeatStep'
targetvalue = step.get('targetValue', 0) targetvalue = step.get('targetValue', 0)
if targetvalue <= 100: if targetvalue <= 100:
duration = 'Repeat until Heart Rate is less than {targetvalue} % of max'.format( duration = 'until Heart Rate is less than {targetvalue} % of max'.format(
targetvalue=targetvalue targetvalue=targetvalue
) )
if short: if short:
duration = ': until HR<{targetvalue}% of max'.format( duration = ': until HR<{targetvalue}% of max'.format(
targetvalue=targetvalue) targetvalue=targetvalue)
else: else:
duration = 'Repeat until Heart Rate is less than {targetvalue}:'.format( duration = 'until Heart Rate is less than {targetvalue}:'.format(
targetvalue=targetvalue-100. targetvalue=targetvalue-100.
) )
if short: if short:
@@ -1216,9 +1221,12 @@ def step_to_string(step, short=False):
try: try:
targettype = step['targetType'] targettype = step['targetType']
except KeyError: except KeyError:
targettype = None targettype = ''
if targettype in ['HeartRate','HeartRateLap']: # pragma: no cover if targettype is None:
targettype = ''
if targettype.lower() in ['heartrate','heartratelap','heart_rate','heart_rate_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -1236,7 +1244,7 @@ def step_to_string(step, short=False):
l=valuelow - 100, l=valuelow - 100,
h=valuehigh - 100, h=valuehigh - 100,
) )
elif targettype in ['Power', 'PowerLap']: # pragma: no cover elif targettype.lower() in ['power', 'powerlap','power_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -1258,7 +1266,7 @@ def step_to_string(step, short=False):
l=valuelow-1000, l=valuelow-1000,
h=valuehigh-1000, h=valuehigh-1000,
) )
elif targettype in ['Speed', 'SpeedLap']: # pragma: no cover elif targettype.lower() in ['speed', 'speedlap','speed_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
@@ -1293,7 +1301,7 @@ def step_to_string(step, short=False):
pl=pacestringlow, pl=pacestringlow,
ph=pacestringhigh, ph=pacestringhigh,
) )
elif targettype in ['Cadence','CadenceLap']: # pragma: no cover elif targettype.lower() in ['cadence','cadencelap','cadence_lap']: # pragma: no cover
value = step.get('targetValue', 0) value = step.get('targetValue', 0)
valuelow = step.get('targetValueLow', 0) valuelow = step.get('targetValueLow', 0)
valuehigh = step.get('targetValueHigh', 0) valuehigh = step.get('targetValueHigh', 0)
@@ -1320,7 +1328,7 @@ def step_to_string(step, short=False):
try: try:
intensity = step['intensity'] intensity = step['intensity']
except KeyError: except KeyError:
intensity = 0 intensity = ''
s = '{duration} {unit} {target} {repeat} {notes}'.format( s = '{duration} {unit} {target} {repeat} {notes}'.format(
# nr=nr, # nr=nr,
@@ -1341,7 +1349,7 @@ def step_to_string(step, short=False):
unit=unit, unit=unit,
) )
if short and intensity in ['Warmup', 'Cooldown', 'Rest']: if short and intensity.lower() in ['warmup', 'cooldown', 'rest']:
s = '{intensity} {duration} {unit} {target} {repeat}'.format( s = '{intensity} {duration} {unit} {target} {repeat}'.format(
intensity=intensity, intensity=intensity,
duration=duration, duration=duration,
@@ -1349,7 +1357,7 @@ def step_to_string(step, short=False):
repeat=repeat, repeat=repeat,
unit=unit unit=unit
) )
elif intensity in ['Warmup', 'Cooldown', 'Rest']: elif intensity.lower() in ['warmup', 'cooldown', 'rest']:
s = '{intensity} {duration} {unit} {target} {repeat} {notes}'.format( s = '{intensity} {duration} {unit} {target} {repeat} {notes}'.format(
intensity=intensity, intensity=intensity,
duration=duration, duration=duration,
@@ -1359,10 +1367,10 @@ def step_to_string(step, short=False):
notes=notes, notes=notes,
) )
if type == 'RepeatStep': if stype == 'RepeatStep':
s = 'Repeat {duration}'.format(duration=duration) s = 'Repeat {duration}'.format(duration=duration)
return s, type, nr, repeatID, repeatValue return s, stype, nr, repeatID, repeatValue
def strfdelta(tdelta): # pragma: no cover def strfdelta(tdelta): # pragma: no cover