Mindre repetisjon i eksport funksjonen
This commit is contained in:
parent
ebc023764e
commit
b33cf0274a
55
otime.py
55
otime.py
@ -226,19 +226,21 @@ def rank_runners(allrunners, o_class):
|
||||
runners_ranked.append(i)
|
||||
return runners_ranked
|
||||
|
||||
def xml_child(parent, tag, content):
|
||||
e = ET.SubElement(parent, tag)
|
||||
e.text = str(content)
|
||||
|
||||
def gen_xml_result(runners, o_classes):
|
||||
root = ET.Element('ResultList')
|
||||
tree = ET.ElementTree(root)
|
||||
event = ET.SubElement(root, 'Event')
|
||||
ename = ET.SubElement(event, 'Name')
|
||||
ename.text = 'PLACEHOLDER'
|
||||
xml_child(event, 'Name', 'PLACEHOLDER')
|
||||
for i in o_classes:
|
||||
#<ClassResult>
|
||||
class_result = ET.SubElement(root, 'ClassResult')
|
||||
#<Class>
|
||||
t = ET.SubElement(class_result, 'Class')
|
||||
name = ET.SubElement(t, 'Name')
|
||||
name.text = i.name
|
||||
xml_child(t, 'Name', i.name)
|
||||
#<PersonResult>
|
||||
runners_same_c = get_runners_in_class(runners, i)
|
||||
runners_ranked = rank_runners(runners_same_c, i)
|
||||
@ -246,22 +248,17 @@ def gen_xml_result(runners, o_classes):
|
||||
person_result = ET.SubElement(class_result, 'PersonResult')
|
||||
#<Person>
|
||||
person = ET.SubElement(person_result, 'Person')
|
||||
eventorid = ET.SubElement(person, 'Id')
|
||||
eventorid.text = '0'
|
||||
xml_child(person, 'Id', '0')
|
||||
#<Name>
|
||||
name = ET.SubElement(person, 'Name')
|
||||
family = ET.SubElement(name, 'Family')
|
||||
family.text = n.last
|
||||
given = ET.SubElement(name, 'Given')
|
||||
given.text = n.first
|
||||
xml_child(name, 'Family', n.last)
|
||||
xml_child(name, 'Given', n.first)
|
||||
#</Name>
|
||||
#</Person>
|
||||
#<Organisation>
|
||||
org = ET.SubElement(person_result, 'Organisation')
|
||||
orgid = ET.SubElement(org, 'Id')
|
||||
orgid.text = '0'
|
||||
name = ET.SubElement(org, 'Name')
|
||||
name.text = n.club
|
||||
xml_child(org, 'Id', '0')
|
||||
xml_child(org, 'Name', n.club)
|
||||
country = ET.SubElement(org, 'Country')
|
||||
# TODO: hent land fra løperobjektet
|
||||
country.text = 'Norway'
|
||||
@ -270,35 +267,25 @@ def gen_xml_result(runners, o_classes):
|
||||
#<Result>
|
||||
result = ET.SubElement(person_result, 'Result')
|
||||
if len(n.splits) > 2:
|
||||
start_t = ET.SubElement(result, 'StartTime')
|
||||
start_t.text = n.s_time.isoformat()
|
||||
finish_t = ET.SubElement(result, 'FinishTime')
|
||||
finish_t.text = n.f_time.isoformat()
|
||||
time = ET.SubElement(result, 'Time')
|
||||
time.text = str(n.totaltime())
|
||||
xml_child(result, 'StartTime', n.s_time.isoformat())
|
||||
xml_child(result, 'FinishTime', n.f_time.isoformat())
|
||||
xml_child(result, 'Time', n.totaltime())
|
||||
if n.status() == 'OK':
|
||||
#<TimeBehind>
|
||||
totime = ET.SubElement(result, 'TimeBehind')
|
||||
totime.text = str(n.totaltime() - runners_ranked[0].totaltime())
|
||||
xml_child(result, 'TimeBehind', n.totaltime() - runners_ranked[0].totaltime())
|
||||
#</TimeBehind>
|
||||
pos = ET.SubElement(result, 'Position')
|
||||
pos.text = str(n.rank(runners))
|
||||
status = ET.SubElement(result, 'Status')
|
||||
status.text = n.status()
|
||||
xml_child(result, 'Position', n.rank(runners))
|
||||
xml_child(result, 'Status', n.status())
|
||||
#<SplitTime>
|
||||
for code,split in zip(n.o_class.course.codes, n.res_splits()):
|
||||
st = ET.SubElement(result, 'SplitTime')
|
||||
ck = ET.SubElement(st, 'ControlCode')
|
||||
ck.text = str(code)
|
||||
time = ET.SubElement(st, 'Time')
|
||||
time.text = str(split)
|
||||
xml_child(st, 'ControlCode', code)
|
||||
xml_child(st, 'Time', split)
|
||||
#</SplitTime>
|
||||
else:
|
||||
status = ET.SubElement(result, 'Status')
|
||||
status.text = n.status()
|
||||
xml_child(result, 'Status', n.status())
|
||||
else:
|
||||
status = ET.SubElement(result, 'Status')
|
||||
status.text = n.status()
|
||||
xml_child(result, 'Status', n.status())
|
||||
#</Result>
|
||||
#</PersonResult>
|
||||
#</Class>
|
||||
|
Loading…
Reference in New Issue
Block a user