From a7b46ed28dc0c59b4725b1d3983ffbe37b233204 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 23 Mar 2021 15:11:22 +0100 Subject: [PATCH] improving long step description --- rowers/plannedsessions.py | 11 +---- rowers/utils.py | 90 ++++++++++++++++----------------------- rowers/views/planviews.py | 2 +- 3 files changed, 38 insertions(+), 65 deletions(-) diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 40bae5c7..8fdd6fb2 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -32,16 +32,7 @@ from rowingdata import rower as rrower from rowers.opaque import encoder -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 +from rowers.utils import to_pace def to_time(milliseconds): diff --git a/rowers/utils.py b/rowers/utils.py index 716af58c..c1e69aab 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -105,6 +105,17 @@ info_calls = [ import random +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 get_call(): call1 = random.choice(coxes_calls) call2 = random.choice(info_calls) @@ -784,6 +795,7 @@ def step_to_string(step,short=False): unit = '' target = '' repeat = '' + notes = '' durationtype = step['durationType'] if step['durationValue'] == 0: @@ -854,9 +866,7 @@ def step_to_string(step,short=False): duration = 'until > {targetvalue} W'.format(targetvalue=targetvalue) elif durationtype == 'RepeatUntilStepsCmplt': type = 'RepeatStep' - ntimes = str(step['targetValue'])+' times:' - if short: - ntimes = ': {v}x'.format(v=step['targetValue']) + ntimes = ': {v}x'.format(v=step['targetValue']) repeatID = step['durationValue'] duration =ntimes repeatValue = step['targetValue'] @@ -868,7 +878,7 @@ def step_to_string(step,short=False): targetvalue=targetvalue ) if short: - duration = ': until HR>{targervalue} % of max'.format(targetvalue=targetvalue) + duration = ': until HR>{targetvalue} % of max'.format(targetvalue=targetvalue) else: duration = 'Repeat until Heart Rate is greater than {targetvalue}:'.format( targetvalue=targetvalue-100. @@ -916,27 +926,15 @@ def step_to_string(step,short=False): valuehigh = 0 if value < 10 and value>0: - target = 'Target: Heart Rate in zone {v}'.format(v=value) - if short: - target = '@ HR zone {v}'.format(v=value) + target = '@ HR zone {v}'.format(v=value) else: if valuelow < 100: - target = 'Target: Heart Rate between {l} and {h} % of max'.format( - l = valuelow, - h = valuehigh - ) - if short: - target = '@ HR {l} - {h} % of max'.format( + target = '@ HR {l} - {h} % of max'.format( l = valuelow, h = valuehigh, ) else: - target = 'Target: Heart Rate between {l} and {h}'.format( - l = valuelow-100, - h = valuehigh+100 - ) - if short: - target = '@ HR {l} - {h}'.format( + target = '@ HR {l} - {h}'.format( l = valuelow - 100, h = valuehigh - 100, ) @@ -955,35 +953,19 @@ def step_to_string(step,short=False): valuehigh = 0 if value < 10 and value>0: - target = 'Target: Power in zone {v}'.format(v=value) - if short: - target = '@ Power zone {v}'.format(v=value) + target = '@ Power zone {v}'.format(v=value) elif value > 10 and value < 1000: - target = 'Target: Power at {v} % of FTP'.format(v=value) - if short: - target = '@ {v}% of FTP'.format(v=value) + target = '@ {v}% of FTP'.format(v=value) elif value > 1000: - target = 'Target: Power at {v} Watt'.format(v=value-1000) - if short: - target = '@ {v} W'.format(v=value-1000) + target = '@ {v} W'.format(v=value-1000) elif valuelow > 0 and valuehigh > 0: if valuelow < 1000: - target = 'Target: Power between {l} and {h} % of FTP'.format( - l = valuelow, - h = valuehigh - ) - if short: - target = '@ {l} - {h} % of FTP'.format( + target = '@ {l} - {h} % of FTP'.format( l = valuelow, h = valuehigh, ) else: - target = 'Target: Power between {l} and {h} W'.format( - l = valuelow-1000, - h = valuehigh-1000 - ) - if short: - target = '@ {l} - {h} W'.format( + target = '@ {l} - {h} W'.format( l = valuelow-1000, h = valuehigh-1000, ) @@ -1005,7 +987,7 @@ def step_to_string(step,short=False): v = value/1000. pace = 500./v pacestring = to_pace(pace) - target = 'Target: Speed at {v} m/s {p} per 500m'.format( + target = '@ {v} m/s {p}, per 500m'.format( v=value/1000., p=pacestring) if short: @@ -1019,7 +1001,7 @@ def step_to_string(step,short=False): 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( + target = '@ {l:1.2f} and {h:1.2f} m/s, ({ph} to {pl} per 500m)'.format( l = valuelow/1000., h = valuehigh/1000., pl = pacestringlow, @@ -1045,16 +1027,9 @@ def step_to_string(step,short=False): valuehigh = 0 if value != 0: - target = 'Target: Cadence at {v} SPM'.format(v=value) - if short: - target = '@ {v} SPM'.format(v=value) + target = '@ {v} SPM'.format(v=value) elif valuelow != 0 and valuehigh != 0: - target = 'Target: Cadence between {l} and {h} SPM'.format( - l = valuelow, - h = valuehigh - ) - if short: - target = '@ {l} - {h} SPM'.format( + target = '@ {l} - {h} SPM'.format( l = valuelow, h = valuehigh ) @@ -1076,7 +1051,7 @@ def step_to_string(step,short=False): except KeyError: intensity = 0 - s = '{name} {intensity} {duration} {unit} {target} {repeat} {notes}'.format( + s = '{duration} {unit} {target} {repeat} {notes}'.format( nr = nr, name = name, unit=unit, @@ -1103,10 +1078,17 @@ def step_to_string(step,short=False): repeat = repeat, unit = unit ) + elif intensity in ['Warmup','Cooldown','Rest']: + s = '{intensity} {duration} {unit} {target} {repeat} {notes}'.format( + intensity = intensity, + duration = duration, + target = target, + repeat = repeat, + unit = unit, + notes = notes, + ) if type == 'RepeatStep': s = 'Repeat {duration}'.format(duration=duration) - if short: - s = 'Repeat {duration}'.format(duration=duration) return s,type, nr, repeatID, repeatValue diff --git a/rowers/views/planviews.py b/rowers/views/planviews.py index 221ff5e5..89767447 100644 --- a/rowers/views/planviews.py +++ b/rowers/views/planviews.py @@ -2365,7 +2365,7 @@ def plannedsession_view(request,id=0,userid=0): steps = '' if ps.steps: d = ps.steps - steps = ps_dict_get_description_html(d) + steps = ps_dict_get_description_html(d,short=False) return render(request,'plannedsessionview.html',