From 66ce00d496f196da663a1c6192517564842d1264 Mon Sep 17 00:00:00 2001 From: Trygve Date: Sat, 21 May 2022 16:25:50 +0200 Subject: [PATCH] =?UTF-8?q?La=20til=20xml=20p=C3=A5meldingsimport=20igjen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/otime.py b/otime.py index 79e2fb2..0b85f9c 100644 --- a/otime.py +++ b/otime.py @@ -43,7 +43,7 @@ class Event: self.runners = runnerarray def import_mtr_file(self, mtr_file): - self.card_dumps = card_punch.list_from_mtr_f(mtr_file) + self.card_dumps = CardDump.list_from_mtr_f(mtr_file) def match_runners_cards(self): for n in self.runners: @@ -89,7 +89,7 @@ class Event: # # org = ET.SubElement(person_result, 'Organisation') - xml_child(org, 'Id', '0') + xml_child(org, 'Id', n.club_id) xml_child(org, 'Name', n.club) country = ET.SubElement(org, 'Country') # TODO: hent land fra løperobjektet @@ -138,7 +138,7 @@ class Event: def create_start_list_pdf(self, file_name): pdf = FPDF() pdf.add_page() - pdf.add_font("DejaVuSans", fname="/usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf") + pdf.add_font("DejaVuSans", fname="/usr/share/fonts/truetype/DejaVuSans.ttf") pdf.set_font("DejaVuSans", size=10) line_height = pdf.font_size * 2 col_width = pdf.epw / 4 # distribute content evenly @@ -153,14 +153,14 @@ class Event: pdf.ln(line_height) pdf.output(file_name) - # The runner object stores all the data specific to a runner. class Runner: - def __init__(self, runner_id, first, last, club, country, card, o_class, start_time): + def __init__(self, runner_id, first, last, club, club_id, country, card, o_class, start_time): self.id = runner_id self.first = first self.last = last self.club = club + self.club_id = club_id self.country = country self.card = card self.o_class = o_class @@ -199,12 +199,16 @@ class Runner: else: runner_o_class = None # TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før + options = tt_line[5].split(',') + try: + club_id = options[options.index('A')+3] + except: + club_id = 0 try: - options = tt_line[5].split(',') start_time = options[options.index('U')+1] except: start_time = None - return Runner(eventorid, first, last, club, country, card, runner_o_class, start_time) + return Runner(eventorid, first, last, club, club_id, country, card, runner_o_class, start_time) def fullname(self): return '{} {}'.format(self.first, self.last) @@ -383,6 +387,43 @@ def classes_from_ttime_conf(ttime_file, courses): loops += 1 return o_classes +def runners_from_xml_entries(xml_file, o_classes=[]): + tree = ET.parse(xml_file) + root = tree.getroot() + runnerarray = [] + + for person_root in root[1:]: + rid = person_root[1][0].text + first = person_root[1][1][1].text + last = person_root[1][1][0].text + try: + club_id = person_root[2][0].text + club = person_root[2][1].text + except: + club = "None" + country = person_root[1][3].text + try: + card = int(person_root[3].text) + except: + card = 0 + try: + xml_class_str = person_root[4][1].text + except: + # VELDIG MIDLERTIDIG + runner_o_class = o_class_list[0] + else: + for i in o_classes: + if i.name == xml_class_str: + runner_o_class = i + break + # Gjør sånn at den lager nye o klasser om den ikke finnes fra før + + start_time = None + runnerarray.append(Runner(rid, first, last, club, club_id, country, card, runner_o_class, start_time)) + print(rid, first, last, club_id, club, card, xml_class_str) + + return runnerarray + # Checks if small list is in big list def contains(small, big): valid = True