From e6457962ab6d7c15731f7a41ca582019c1180ada Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 26 Feb 2021 09:01:12 +0100 Subject: [PATCH] fix --- rowers/plannedsessions.py | 66 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index f2308576..46918021 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -30,6 +30,18 @@ import pandas as pd from rowingdata import rowingdata as rrdata from rowingdata import rower as rrower +def to_pace(pace): + minutes, seconds = divmod(pace,60) + seconds, rest = divmod(seconds, 1) + tenths = int(rest*10) + s = '{m:0>2}:{s:0>2}.{t:0>1}'.format( + m=int(minutes), + s=int(seconds), + t=int(tenths) + ) + return s + + def to_time(milliseconds): seconds = milliseconds/1000. hours = int(seconds / 3600) @@ -82,6 +94,7 @@ from rowers.utils import totaltime_sec_to_string def step_to_string(step): + print(step) type = 'Step' repeatID = -1 @@ -95,6 +108,8 @@ def step_to_string(step): repeat = '' durationtype = step['durationType'] + if step['durationValue'] == 0: + return '',type, -1, -1 if durationtype == 'Time': unit = 'min' @@ -107,13 +122,13 @@ def step_to_string(step): duration = int(value) elif durationtype == 'HrLessThan': value = step['durationValue'] - if value < 100: + if value <= 100: duration = 'until heart rate lower than {v}% of max'.format(v=value) else: duration = 'until heart rate lower than {v}'.format(v=value-100) elif durationtype == 'HrGreaterThan': value = step['durationValue'] - if value < 100: + if value <= 100: duration = 'until heart rate greater than {v}% of max'.format(v=value) else: duration = 'until heart rate greater than {v}'.format(v=value-100) @@ -122,6 +137,32 @@ def step_to_string(step): ntimes = str(step['targetValue'])+' times:' repeatID = step['durationValue'] duration =ntimes + elif durationtype == 'RepeatUntilHrGreaterThan': + type = 'RepeatStep' + targetvalue = step['targetValue'] + if targetvalue <= 100: + duration = 'Repeat until Heart Rate is greater than {targetvalue} % of max'.format( + targetvalue=targetvalue + ) + else: + duration = 'Repeat until Heart Rate is greater than {targetvalue}:'.format( + targetvalue=targetvalue-100. + ) + repeatID = step['durationValue'] + elif durationtype == 'RepeatUntilHrLessThan': + type = 'RepeatStep' + targetvalue = step['targetValue'] + if targetvalue <= 100: + duration = 'Repeat until Heart Rate is less than {targetvalue} % of max'.format( + targetvalue=targetvalue + ) + else: + duration = 'Repeat until Heart Rate is less than {targetvalue}:'.format( + targetvalue=targetvalue-100. + ) + repeatID = step['durationValue'] + + # targettype = step['targetType'] @@ -166,7 +207,26 @@ def step_to_string(step): valuelow = step['targetValueLow'] valuehigh = step['targetValueHigh'] - target = 'Target: Speed at {v} m/s'.format(v=value/1000.) + if value != 0: + v = value/1000. + pace = 500./v + print(to_pace(pace)) + target = 'Target: Speed at {v} m/s'.format(v=value/1000.) + elif valuelow != 0 and valuehigh != 0: + v = valuelow/1000. + pace = 500./v + pacestringlow = to_pace(pace) + + v = valuehigh/1000. + pace = 500./v + pacestringhigh = to_pace(pace) + + target = 'Target: Speed between {l:1.2f} and {h:1.2f} m/s ({ph} to {pl} per 500m)'.format( + l = valuelow/1000., + h = valuehigh/1000., + pl = pacestringlow, + ph = pacestringhigh, + ) nr = step['stepId']