Private
Public Access
1
0

now understands repetition

This commit is contained in:
Sander Roosendaal
2021-02-25 21:29:40 +01:00
parent d7048c182f
commit 195df1d25a

View File

@@ -17,7 +17,7 @@ import pytz
from dateutil import parser
from rowers.utils import myqueue,calculate_age,totaltime_sec_to_string
from rowers.rows import handle_uploaded_file
import collections
import re
import django_rq
queue = django_rq.get_queue('default')
@@ -82,40 +82,9 @@ from rowers.utils import totaltime_sec_to_string
def step_to_string(step):
print(step)
target_dict = {
'HeartRate': {
'name':'Heart Rate between',
'low': 'custom_target_power_low',
'high': 'custom_target_power_high',
},
'Speed':{
'name': 'Speed between',
'low': 'custom_target_power_low',
'high': 'custom_target_power_high',
},
'Cadence':{
'name': 'SPM between',
'low': 'custom_target_power_low',
'high': 'custom_target_power_high',
},
'Open':{
'name': 'between',
'low': 'targetValueLow',
'high': 'targetValueHigh',
},
'Power':{
'name': 'Power between',
'low': 'custom_target_power_low',
'high': 'custom_target_power_high',
},
'SwimStroke':{
'name': 'Stroke type',
'low': 'target_swim_stroke',
'high': '',
},
}
type = 'Step'
repeatID = -1
nr = 0
name = ''
@@ -148,6 +117,11 @@ def step_to_string(step):
duration = 'until heart rate greater than {v}% of max'.format(v=value)
else:
duration = 'until heart rate greater than {v}'.format(v=value-100)
elif durationtype == 'RepeatUntilStepsCmplt':
type = 'RepeatStep'
ntimes = str(step['targetValue'])+' times:'
repeatID = step['durationValue']
duration =ntimes
targettype = step['targetType']
@@ -200,7 +174,8 @@ def step_to_string(step):
intensity = step['intensity']
s = '{nr}: {name} {intensity} {duration} {unit} {target} {repeat}'.format(
s = '{name} {intensity} {duration} {unit} {target} {repeat}'.format(
nr = nr,
name = name,
unit=unit,
@@ -210,24 +185,69 @@ def step_to_string(step):
repeat = repeat,
)
return s
if type == 'RepeatStep':
s = 'Repeat {duration}'.format(duration=duration)
return s,type, nr, repeatID
def ps_dict_get_description(d):
s = ''
sdict = {}
steps = d['steps']
for step in steps:
s += step_to_string(step)
s += '\n'
sstring, type, stepID, repeatID = step_to_string(step)
sdict[stepID] = {
'string':sstring,
'type':type,
'stepID': stepID,
'repeatID': repeatID,
}
s += sstring+'\n'
return s
def ps_dict_get_description_html(d):
s = '<ul>'
sdict = collections.OrderedDict({})
steps = d['steps']
for step in steps:
s += '<li>'+step_to_string(step)+'</li>'
sstring, type, stepID, repeatID = step_to_string(step)
sdict[stepID] = {
'string':sstring,
'type':type,
'stepID': stepID,
'repeatID': repeatID,
}
sdict2 = collections.OrderedDict(reversed(list(sdict.items())))
sdict3 = []
hold = []
holduntil = []
spaces = ''
for key, item in sdict2.items():
if item['type'] == 'RepeatStep':
hold.append(item)
holduntil.append(item['repeatID'])
spaces += '&nbsp;&nbsp;&nbsp;'
if item['type'] == 'Step':
item['string'] = spaces+item['string']
sdict3.append(item)
if len(holduntil)>0 and item['stepID'] == holduntil[-1]:
sdict3.append(hold.pop())
spaces = spaces[:-18]
holduntil.pop()
sdict = list(reversed(sdict3))
s = '<ul>'
for item in sdict:
s += '<li>'+item['string']+'</li>'
s += '</ul>'
return s