diff --git a/rowers/tests/test_plans.py b/rowers/tests/test_plans.py index 382eafbe..9cf2db43 100644 --- a/rowers/tests/test_plans.py +++ b/rowers/tests/test_plans.py @@ -72,7 +72,7 @@ class PlanStepTest(TestCase): self.assertEqual(len(steps['steps']),3) 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) diff --git a/rowers/tests/testdata/testdata.tcx.gz b/rowers/tests/testdata/testdata.tcx.gz index 3b33bebd..757489ac 100644 Binary files a/rowers/tests/testdata/testdata.tcx.gz and b/rowers/tests/testdata/testdata.tcx.gz differ diff --git a/rowers/utils.py b/rowers/utils.py index e763564f..ba032e86 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -755,20 +755,20 @@ def step_to_time_dist(step, avgspeed=3.2, ftp=200, ftspm=25, ftv=3.7, powerzones seconds = 0 distance = 0 rscore = 0 - durationtype = step.get('durationType', 0) + durationtype = step.get('durationType', '') value = step.get('durationValue', 0) if value == 0: # pragma: no cover return 0, 0, 0 - targettype = step.get('targetType', 0) + targettype = step.get('targetType', '') - if durationtype == 'Time': + if durationtype.lower() == 'time': seconds = value/1000. distance = avgspeed*seconds rscore = 60.*seconds/3600. - if targettype == 'Speed': # pragma: no cover + if targettype.lower() == 'speed': # pragma: no cover value = step.get('targetValue', 0) valuelow = step.get('targetValueLow', 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 rscore = rscoreperhour*seconds/3600. - if targettype in ['Power','PowerLap']: + if targettype.lower() in ['power','powerlap','power_lap']: value = step.get('targetValue', 0) valuelow = step.get('targetValueLow', 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. - if targettype in ['Cadence','CadenceLap']: + if targettype.lower() in ['cadence','cadencelap','cadence_lap']: value = step.get('targetValue', 0) valuelow = step.get('targetValueLow', 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. return seconds, distance, rscore - elif durationtype == 'Distance': + elif durationtype.lower() == 'distance': distance = value/100. seconds = distance/avgspeed 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) valuelow = step.get('targetValueLow', 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: 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) valuelow = step.get('targetValueLow', 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. - if targettype in ['Cadence','CadenceLap']: # pragma: no cover + if targettype.lower() in ['cadence','cadencelap','cadence_lap']: # pragma: no cover value = step.get('targetValue', 0) valuelow = step.get('targetValueLow', 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 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 distance = seconds*avgspeed 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 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' return t @@ -1081,7 +1083,7 @@ def ps_dict_order(d, short=False, rower=None, html=True): def step_to_string(step, short=False): - type = 'Step' + stype = 'Step' repeatID = -1 repeatValue = 1 @@ -1096,25 +1098,28 @@ def step_to_string(step, short=False): durationtype = step['durationType'] if step['durationValue'] == 0: - if durationtype not in [ - 'RepeatUntilStepsCmplt', - 'RepeatUntilHrLessThan', - 'RepeatUntilHrGreaterThan' + if durationtype.lower() not in [ + 'repeatuntilstepscmplt', + 'repeatuntilhrlessthan', + 'repeatuntilhrgreaterthan', + 'repeat_until_steps_cmplt', + 'repeat_until_hr_less_than', + 'repeat_until_hr_greater_than' ]: # pragma: no cover - return '', type, -1, -1, 1 + return '', stype, -1, -1, 1 - if durationtype == 'Time': + if durationtype.lower() == 'time': unit = 'min' value = step['durationValue'] if value/1000. >= 3600: # pragma: no cover unit = 'h' dd = timedelta(seconds=value/1000.) duration = '{v}'.format(v=str(dd)) - elif durationtype == 'Distance': + elif durationtype.lower() == 'distance': unit = 'm' value = step['durationValue']/100. duration = int(value) - elif durationtype == 'HrLessThan': # pragma: no cover + elif durationtype.lower() in ['hrlessthan', 'hr_less_than']: # pragma: no cover value = step['durationValue'] if value <= 100: 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) if short: 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'] if value <= 100: 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) if short: 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'] targetvalue = step.get('targetValue', 0) if value <= 1000: @@ -1151,7 +1156,7 @@ def step_to_string(step, short=False): ) if short: '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'] targetvalue = step.get('targetValue', 0) if value <= 1000: @@ -1168,42 +1173,42 @@ def step_to_string(step, short=False): if short: duration = 'until > {targetvalue} W'.format( targetvalue=targetvalue) - elif durationtype == 'RepeatUntilStepsCmplt': # pragma: no cover - type = 'RepeatStep' + elif durationtype.lower() in ['repeatuntilstepscmplt','repeat_until_steps_cmplt']: # pragma: no cover + stype = 'RepeatStep' ntimes = ': {v}x'.format(v=step['targetValue']) repeatID = step['durationValue'] duration = ntimes repeatValue = step.get('targetValue', 0) - elif durationtype == 'RepeatUntilHrGreaterThan': # pragma: no cover - type = 'RepeatStep' + elif durationtype.lower() in ['repeatuntilhrgreaterthan','repeat_until_hr_greater_than']: # pragma: no cover + stype = 'RepeatStep' targetvalue = step.get('targetValue', 0) 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 ) if short: duration = ': until HR>{targetvalue} % of max'.format( targetvalue=targetvalue) else: - duration = 'Repeat until Heart Rate is greater than {targetvalue}:'.format( + duration = 'until Heart Rate is greater than {targetvalue}:'.format( targetvalue=targetvalue-100. ) if short: duration = ': untl HR>{targetvalue}'.format( targetvalue=targetvalue-100) repeatID = step['durationValue'] - elif durationtype == 'RepeatUntilHrLessThan': # pragma: no cover - type = 'RepeatStep' + elif durationtype.lower() in ['repeatuntilhrlessthan','repeat_until_hr_less_than']: # pragma: no cover + stype = 'RepeatStep' targetvalue = step.get('targetValue', 0) 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 ) if short: duration = ': until HR<{targetvalue}% of max'.format( targetvalue=targetvalue) else: - duration = 'Repeat until Heart Rate is less than {targetvalue}:'.format( + duration = 'until Heart Rate is less than {targetvalue}:'.format( targetvalue=targetvalue-100. ) if short: @@ -1216,9 +1221,12 @@ def step_to_string(step, short=False): try: targettype = step['targetType'] 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) valuelow = step.get('targetValueLow', 0) valuehigh = step.get('targetValueHigh', 0) @@ -1236,7 +1244,7 @@ def step_to_string(step, short=False): l=valuelow - 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) valuelow = step.get('targetValueLow', 0) valuehigh = step.get('targetValueHigh', 0) @@ -1258,7 +1266,7 @@ def step_to_string(step, short=False): l=valuelow-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) valuelow = step.get('targetValueLow', 0) @@ -1293,7 +1301,7 @@ def step_to_string(step, short=False): pl=pacestringlow, 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) valuelow = step.get('targetValueLow', 0) valuehigh = step.get('targetValueHigh', 0) @@ -1320,7 +1328,7 @@ def step_to_string(step, short=False): try: intensity = step['intensity'] except KeyError: - intensity = 0 + intensity = '' s = '{duration} {unit} {target} {repeat} {notes}'.format( # nr=nr, @@ -1341,7 +1349,7 @@ def step_to_string(step, short=False): 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( intensity=intensity, duration=duration, @@ -1349,7 +1357,7 @@ def step_to_string(step, short=False): repeat=repeat, unit=unit ) - elif intensity in ['Warmup', 'Cooldown', 'Rest']: + elif intensity.lower() in ['warmup', 'cooldown', 'rest']: s = '{intensity} {duration} {unit} {target} {repeat} {notes}'.format( intensity=intensity, duration=duration, @@ -1359,10 +1367,10 @@ def step_to_string(step, short=False): notes=notes, ) - if type == 'RepeatStep': + if stype == 'RepeatStep': s = 'Repeat {duration}'.format(duration=duration) - return s, type, nr, repeatID, repeatValue + return s, stype, nr, repeatID, repeatValue def strfdelta(tdelta): # pragma: no cover