diff --git a/otime/iof_xml.py b/otime/iof_xml.py index 981d672..fb71e5b 100644 --- a/otime/iof_xml.py +++ b/otime/iof_xml.py @@ -1,5 +1,6 @@ import datetime import xml.etree.ElementTree as ET +import otime def xml_child(parent, tag, content): # Used to make creating xml files easier @@ -120,8 +121,8 @@ def runners_from_xml_entries(xml_file): card = None start_time = None - runners.append(Runner(rid, first, last, club=club_name, club_id=club_id, - country=country,card=card, o_class_str=class_str, + runners.append(otime.Runner(rid, first, last, club=club_name, club_id=club_id, + country=country,card_id=card, o_class_str=class_str, start_time=start_time, fee_id=fee_id)) return runners @@ -151,7 +152,7 @@ def fees_from_xml_entries(xml_file): except AttributeError: to_birth_date = None - fee_objs.append(Fee(fee_id, name, currency, amount, + fee_objs.append(otime.Fee(fee_id, name, currency, amount, from_birth_date=from_birth_date, to_birth_date=to_birth_date)) return fee_objs @@ -171,5 +172,36 @@ def courses_from_xml(xml_file): controls.remove('STA1') controls.remove('FIN1') controls = [int(l) for l in controls] - courseobjs.append(Course(name, controls)) + courseobjs.append(otime.Course(name, controls)) return courseobjs + +def event_from_xml_entries(xml_file): + tree = ET.parse(xml_file) + root = tree.getroot() + + url = '{http://www.orienteering.org/datastandard/3.0}' + event_el = root.find(f'./{url}Event') + event_id = int(event_el.find(f'./{url}Id').text) + name = event_el.find(f'./{url}Name').text + organiser = event_el.find(f'./{url}Organiser/{url}Name').text + + start_ds = event_el.find(f'./{url}StartTime/{url}Date').text + start_ts = event_el.find(f'./{url}StartTime/{url}Time').text[:-1] + start_time = datetime.datetime.fromisoformat(f'{start_ds}T{start_ts}') + + end_ds = event_el.find(f'./{url}EndTime/{url}Date').text + end_ts = event_el.find(f'./{url}EndTime/{url}Time').text[:-1] + end_time = datetime.datetime.fromisoformat(f'{end_ds}T{end_ts}') + + person_entries = root.findall(f'./{url}PersonEntry') + + class_names = [] + for p_entry in person_entries: + class_names.append(p_entry.find(f'./{url}Class/{url}Name').text) + o_classes = [otime.OClass(i, []) for i in set(class_names)] + + runners = runners_from_xml_entries(xml_file) + fees = fees_from_xml_entries(xml_file) + + return otime.Event(event_id, name, organiser=organiser, runners=runners, + fees=fees, start_time=start_time, end_time=end_time, o_classes=o_classes) \ No newline at end of file diff --git a/otime/otime.py b/otime/otime.py index af99303..dc6c2b0 100644 --- a/otime/otime.py +++ b/otime/otime.py @@ -7,7 +7,7 @@ import pdf class Runner: def __init__(self, id: int, first: str, last: str, club=None, club_id=None, country=None, card_id=None, o_class_str=None, o_class=None, - fork=0, start_time=None, fee_id=None, fee=None): + fork=0, start_time=None, fee_id=None, fee=None, status_override=''): self.id = id self.first = first self.last = last @@ -19,7 +19,7 @@ class Runner: self.fork = fork self.start_time = start_time self.fee_id = fee_id - self.status_override = '' + self.status_override = status_override def __repr__(self): return(f'name({self.fullname()})') @@ -337,29 +337,6 @@ class Event: self.add_fees(*fees_from_xml_entries(xml_file)) # Må endres - def from_xml_entries(xml_file): - tree = ET.parse(xml_file) - root = tree.getroot() - - url = '{http://www.orienteering.org/datastandard/3.0}' - event_el = root.find(f'./{url}Event') - event_id = int(event_el.find(f'./{url}Id').text) - name = event_el.find(f'./{url}Name').text - organiser = event_el.find(f'./{url}Organiser/{url}Name').text - - start_ds = event_el.find(f'./{url}StartTime/{url}Date').text - start_ts = event_el.find(f'./{url}StartTime/{url}Time').text[:-1] - start_time = datetime.datetime.fromisoformat(f'{start_ds}T{start_ts}') - - end_ds = event_el.find(f'./{url}EndTime/{url}Date').text - end_ts = event_el.find(f'./{url}EndTime/{url}Time').text[:-1] - end_time = datetime.datetime.fromisoformat(f'{end_ds}T{end_ts}') - - runners = runners_from_xml_entries(xml_file) - fees = fees_from_xml_entries(xml_file) - - return Event(event_id, name, organiser=organiser, runners=runners, - fees=fees, start_time=start_time, end_time=end_time) def read_xml_courses(self, xml_file): self.courses = courses_from_xml(xml_file)