forked from Trygve/otime
Startet på xml eksport funksjonen
This commit is contained in:
parent
00428e7b62
commit
178f0bcbd7
3
cli.py
3
cli.py
@ -69,5 +69,6 @@ if __name__ == "__main__":
|
||||
print_runners(runner_list)
|
||||
#print_time(runner_list)
|
||||
#print_o_classes(o_classes)
|
||||
print_class_splits(runner_list, o_classes[0])
|
||||
#print_class_splits(runner_list, o_classes[0])
|
||||
#print(otime.check_codes(runner_list[1]))
|
||||
print(otime.gen_xml_result(runner_list, o_classes))
|
||||
|
65
otime.py
65
otime.py
@ -20,11 +20,20 @@ class runner:
|
||||
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
# Returns False if not ok and touple if ok
|
||||
def check_codes(self):
|
||||
# Returns False if not ok and touple if ok
|
||||
return contains(self.o_class.course.codes, self.controls)
|
||||
def totaltime(self):
|
||||
return self.splits[-2]
|
||||
|
||||
def status(self):
|
||||
if self.controls == []:
|
||||
return 'Active'
|
||||
elif self.check_codes():
|
||||
return 'OK'
|
||||
elif self.check_codes() == False:
|
||||
return 'Disqualified'
|
||||
|
||||
|
||||
class course:
|
||||
def __init__(self, name, codes):
|
||||
@ -161,4 +170,58 @@ def contains(small, big):
|
||||
return True
|
||||
return False
|
||||
|
||||
def filter_runners_by_class(runners, o_class):
|
||||
list_filtrd = []
|
||||
for i in runners:
|
||||
if i.o_class == o_class:
|
||||
list_filtrd.append(i)
|
||||
|
||||
return list_filtrd
|
||||
|
||||
def gen_xml_result(runners, o_classes):
|
||||
root = ET.Element('ResultList')
|
||||
tree = ET.ElementTree(root)
|
||||
event = ET.SubElement(root, 'Event')
|
||||
for i in o_classes:
|
||||
#<ClassResult>
|
||||
class_result = ET.SubElement(event, 'ClassResult')
|
||||
#<Class>
|
||||
t = ET.SubElement(class_result, 'Class')
|
||||
name = ET.SubElement(t, 'Name')
|
||||
name.text = i.name
|
||||
#<PersonResult>
|
||||
for n in filter_runners_by_class(runners, i):
|
||||
person_result = ET.SubElement(class_result, 'PersonResult')
|
||||
#<Person>
|
||||
person = ET.SubElement(person_result, 'Person')
|
||||
eventorid = ET.SubElement(person, 'Id')
|
||||
eventorid.text = '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
|
||||
#</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
|
||||
country = ET.SubElement(org, 'Country')
|
||||
# TODO: hent land fra løperobjektet
|
||||
country.text = 'Norway'
|
||||
country.set('code', 'NOR')
|
||||
#</Organisation>
|
||||
#<Result>
|
||||
result = ET.SubElement(person, 'Result')
|
||||
status = ET.SubElement(result, 'Status')
|
||||
status.text = n.status()
|
||||
#</Result>
|
||||
#</PersonResult>
|
||||
#</Class>
|
||||
|
||||
tree.write('output.xml')
|
||||
return ET.dump(root)
|
||||
|
Loading…
Reference in New Issue
Block a user