short notation for workouts
This commit is contained in:
112
rowers/utils.py
112
rowers/utils.py
@@ -669,11 +669,11 @@ def peel(l):
|
||||
return first,rest
|
||||
|
||||
|
||||
def ps_dict_order_dict(d):
|
||||
def ps_dict_order_dict(d,short=False):
|
||||
steps = d['steps']
|
||||
sdicts = []
|
||||
for step in steps:
|
||||
sstring, type, stepID, repeatID, repeatValue = step_to_string(step)
|
||||
sstring, type, stepID, repeatID, repeatValue = step_to_string(step,short=short)
|
||||
seconds, meters = step_to_time_dist(step)
|
||||
|
||||
sdict = {
|
||||
@@ -689,12 +689,12 @@ def ps_dict_order_dict(d):
|
||||
|
||||
return sdict2
|
||||
|
||||
def ps_dict_order(d):
|
||||
def ps_dict_order(d,short=False):
|
||||
sdict = collections.OrderedDict({})
|
||||
steps = d['steps']
|
||||
|
||||
for step in steps:
|
||||
sstring, type, stepID, repeatID, repeatValue = step_to_string(step)
|
||||
sstring, type, stepID, repeatID, repeatValue = step_to_string(step,short=short)
|
||||
seconds, meters = step_to_time_dist(step)
|
||||
|
||||
sdict[stepID] = {
|
||||
@@ -711,7 +711,7 @@ def ps_dict_order(d):
|
||||
sdict2 = collections.OrderedDict(reversed(list(sdict.items())))
|
||||
|
||||
for step in steps:
|
||||
sstring, type, stepID, repeatID, repeatValue = step_to_string(step)
|
||||
sstring, type, stepID, repeatID, repeatValue = step_to_string(step,short=short)
|
||||
seconds, meters = step_to_time_dist(step)
|
||||
|
||||
sdict[stepID] = {
|
||||
@@ -771,7 +771,7 @@ def ps_dict_order(d):
|
||||
|
||||
return sdict,totalmeters,totalseconds
|
||||
|
||||
def step_to_string(step):
|
||||
def step_to_string(step,short=False):
|
||||
type = 'Step'
|
||||
repeatID = -1
|
||||
repeatValue = 1
|
||||
@@ -804,14 +804,22 @@ def step_to_string(step):
|
||||
value = step['durationValue']
|
||||
if value <= 100:
|
||||
duration = 'until heart rate lower than {v}% of max'.format(v=value)
|
||||
if short:
|
||||
duration = 'until HR<{v}% of max'.format(v=value)
|
||||
else:
|
||||
duration = 'until heart rate lower than {v}'.format(v=value-100)
|
||||
if short:
|
||||
duration = 'until HR<{v}'.format(v=value-100)
|
||||
elif durationtype == 'HrGreaterThan':
|
||||
value = step['durationValue']
|
||||
if value <= 100:
|
||||
duration = 'until heart rate greater than {v}% of max'.format(v=value)
|
||||
if short:
|
||||
duration = 'until R>{v}% of max'.format(v=value)
|
||||
else:
|
||||
duration = 'until heart rate greater than {v}'.format(v=value-100)
|
||||
if short:
|
||||
duration = 'until HR>{v}'.format(v=value/100)
|
||||
elif durationtype == 'PowerLessThan':
|
||||
value = step['durationValue']
|
||||
targetvalue = step['targetvalue']
|
||||
@@ -819,10 +827,14 @@ def step_to_string(step):
|
||||
duration = 'Repeat until Power is less than {targetvalue} % of FTP'.format(
|
||||
targetvalue=targetvalue
|
||||
)
|
||||
if short:
|
||||
'until < {targetvalue}% of FTP'.format(targetvalue=targetvalue)
|
||||
else:
|
||||
duration = 'Repeat until Power is less than {targetvalue} Watt'.format(
|
||||
targetvalue=targetvalie
|
||||
targetvalue=targetvalue-1000
|
||||
)
|
||||
if short:
|
||||
'until < {targetvalue} W'.format(targetvalue=targetvalue-1000)
|
||||
elif durationtype == 'PowerGreaterThan':
|
||||
value = step['durationValue']
|
||||
targetvalue = step['targetvalue']
|
||||
@@ -830,13 +842,19 @@ def step_to_string(step):
|
||||
duration = 'Repeat until Power is greater than {targetvalue} % of FTP'.format(
|
||||
targetvalue=targetvalue
|
||||
)
|
||||
if short:
|
||||
duration = 'until > {targetvalue}% of FTP'.format(targetvalue=targetvalue)
|
||||
else:
|
||||
duration = 'Repeat until Power is greater than {targetvalue} Watt'.format(
|
||||
targetvalue=targetvalie
|
||||
targetvalue=targetvalue-1000
|
||||
)
|
||||
if short:
|
||||
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'])
|
||||
repeatID = step['durationValue']
|
||||
duration =ntimes
|
||||
repeatValue = step['targetValue']
|
||||
@@ -847,10 +865,14 @@ def step_to_string(step):
|
||||
duration = 'Repeat until Heart Rate is greater than {targetvalue} % of max'.format(
|
||||
targetvalue=targetvalue
|
||||
)
|
||||
if short:
|
||||
duration = ': until HR>{targervalue} % of max'.format(targetvalue=targetvalue)
|
||||
else:
|
||||
duration = 'Repeat 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':
|
||||
type = 'RepeatStep'
|
||||
@@ -859,10 +881,14 @@ def step_to_string(step):
|
||||
duration = 'Repeat 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(
|
||||
targetvalue=targetvalue-100.
|
||||
)
|
||||
if short:
|
||||
duration = ': until HR<{targetvalue}'.format(targetvalue=targetvalue-100)
|
||||
repeatID = step['durationValue']
|
||||
|
||||
|
||||
@@ -889,17 +915,29 @@ def step_to_string(step):
|
||||
|
||||
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)
|
||||
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(
|
||||
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(
|
||||
l = valuelow - 100,
|
||||
h = valuehigh - 100,
|
||||
)
|
||||
elif targettype == 'Power':
|
||||
try:
|
||||
value = step['targetValue']
|
||||
@@ -916,21 +954,37 @@ def step_to_string(step):
|
||||
|
||||
if value < 10 and value>0:
|
||||
target = 'Target: Power in zone {v}'.format(v=value)
|
||||
if short:
|
||||
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)
|
||||
elif value > 1000:
|
||||
target = 'Target: Power at {v} Watt'.format(v=value-1000)
|
||||
if short:
|
||||
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(
|
||||
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(
|
||||
l = valuelow-1000,
|
||||
h = valuehigh-1000,
|
||||
)
|
||||
elif targettype == 'Speed':
|
||||
try:
|
||||
value = step['targetValue']
|
||||
@@ -948,7 +1002,12 @@ def step_to_string(step):
|
||||
if value != 0:
|
||||
v = value/1000.
|
||||
pace = 500./v
|
||||
target = 'Target: Speed at {v} m/s'.format(v=value/1000.)
|
||||
pacestring = to_pace(pace)
|
||||
target = 'Target: Speed at {v} m/s {p} per 500m'.format(
|
||||
v=value/1000.,
|
||||
p=pacestring)
|
||||
if short:
|
||||
target = '@ {p}'.format(p=pacestring)
|
||||
elif valuelow != 0 and valuehigh != 0:
|
||||
v = valuelow/1000.
|
||||
pace = 500./v
|
||||
@@ -964,6 +1023,11 @@ def step_to_string(step):
|
||||
pl = pacestringlow,
|
||||
ph = pacestringhigh,
|
||||
)
|
||||
if short:
|
||||
target = '@ {pl} - {ph}'.format(
|
||||
pl = pacestringlow,
|
||||
ph = pacestringhigh,
|
||||
)
|
||||
elif targettype == 'Cadence':
|
||||
try:
|
||||
value = step['targetValue']
|
||||
@@ -980,11 +1044,18 @@ def step_to_string(step):
|
||||
|
||||
if value != 0:
|
||||
target = 'Target: Cadence at {v} SPM'.format(v=value)
|
||||
if short:
|
||||
target = '@ {v} SPM'.format(v=value)
|
||||
elif valuelow != 0 and valuehigh != 0:
|
||||
target = 'Target: Cadence between {l} and {h} SPM'.format(
|
||||
l = valuelow/1000.,
|
||||
h = valuehigh/1000.,
|
||||
l = valuelow,
|
||||
h = valuehigh
|
||||
)
|
||||
if short:
|
||||
target = '@ {l} - {h} SPM'.format(
|
||||
l = valuelow,
|
||||
h = valuehigh
|
||||
)
|
||||
|
||||
|
||||
nr = step['stepId']
|
||||
@@ -1014,7 +1085,26 @@ def step_to_string(step):
|
||||
notes=notes,
|
||||
)
|
||||
|
||||
if short:
|
||||
s = '{duration} {unit} {target} {repeat}'.format(
|
||||
duration = duration,
|
||||
target = target,
|
||||
repeat = repeat,
|
||||
unit = unit,
|
||||
)
|
||||
|
||||
if short and intensity in ['Warmup','Cooldown','Rest']:
|
||||
s = '{intensity} {duration} {unit} {target} {repeat}'.format(
|
||||
intensity = intensity,
|
||||
duration = duration,
|
||||
target = target,
|
||||
repeat = repeat,
|
||||
unit = unit
|
||||
)
|
||||
|
||||
if type == 'RepeatStep':
|
||||
s = 'Repeat {duration}'.format(duration=duration)
|
||||
if short:
|
||||
s = 'Repeat {duration}'.format(duration=duration)
|
||||
|
||||
return s,type, nr, repeatID, repeatValue
|
||||
|
||||
Reference in New Issue
Block a user