now understands repetition
This commit is contained in:
@@ -17,7 +17,7 @@ import pytz
|
|||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
from rowers.utils import myqueue,calculate_age,totaltime_sec_to_string
|
from rowers.utils import myqueue,calculate_age,totaltime_sec_to_string
|
||||||
from rowers.rows import handle_uploaded_file
|
from rowers.rows import handle_uploaded_file
|
||||||
|
import collections
|
||||||
import re
|
import re
|
||||||
import django_rq
|
import django_rq
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
@@ -82,40 +82,9 @@ from rowers.utils import totaltime_sec_to_string
|
|||||||
|
|
||||||
def step_to_string(step):
|
def step_to_string(step):
|
||||||
|
|
||||||
print(step)
|
|
||||||
|
|
||||||
target_dict = {
|
type = 'Step'
|
||||||
'HeartRate': {
|
repeatID = -1
|
||||||
'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': '',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
nr = 0
|
nr = 0
|
||||||
name = ''
|
name = ''
|
||||||
@@ -148,6 +117,11 @@ def step_to_string(step):
|
|||||||
duration = 'until heart rate greater than {v}% of max'.format(v=value)
|
duration = 'until heart rate greater than {v}% of max'.format(v=value)
|
||||||
else:
|
else:
|
||||||
duration = 'until heart rate greater than {v}'.format(v=value-100)
|
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']
|
targettype = step['targetType']
|
||||||
|
|
||||||
@@ -200,7 +174,8 @@ def step_to_string(step):
|
|||||||
|
|
||||||
intensity = step['intensity']
|
intensity = step['intensity']
|
||||||
|
|
||||||
s = '{nr}: {name} {intensity} {duration} {unit} {target} {repeat}'.format(
|
|
||||||
|
s = '{name} {intensity} {duration} {unit} {target} {repeat}'.format(
|
||||||
nr = nr,
|
nr = nr,
|
||||||
name = name,
|
name = name,
|
||||||
unit=unit,
|
unit=unit,
|
||||||
@@ -210,24 +185,69 @@ def step_to_string(step):
|
|||||||
repeat = repeat,
|
repeat = repeat,
|
||||||
)
|
)
|
||||||
|
|
||||||
return s
|
if type == 'RepeatStep':
|
||||||
|
s = 'Repeat {duration}'.format(duration=duration)
|
||||||
|
|
||||||
|
return s,type, nr, repeatID
|
||||||
|
|
||||||
def ps_dict_get_description(d):
|
def ps_dict_get_description(d):
|
||||||
s = ''
|
sdict = {}
|
||||||
steps = d['steps']
|
steps = d['steps']
|
||||||
for step in steps:
|
for step in steps:
|
||||||
s += step_to_string(step)
|
sstring, type, stepID, repeatID = step_to_string(step)
|
||||||
s += '\n'
|
|
||||||
|
sdict[stepID] = {
|
||||||
|
'string':sstring,
|
||||||
|
'type':type,
|
||||||
|
'stepID': stepID,
|
||||||
|
'repeatID': repeatID,
|
||||||
|
}
|
||||||
|
|
||||||
|
s += sstring+'\n'
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def ps_dict_get_description_html(d):
|
def ps_dict_get_description_html(d):
|
||||||
s = '<ul>'
|
sdict = collections.OrderedDict({})
|
||||||
steps = d['steps']
|
steps = d['steps']
|
||||||
for step in 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 += ' '
|
||||||
|
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>'
|
s += '</ul>'
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user