From 95f10000bb991ec2bb600d13f9c2802e82e6ef27 Mon Sep 17 00:00:00 2001 From: Trygve Date: Tue, 21 Nov 2023 22:34:40 +0100 Subject: [PATCH] =?UTF-8?q?Sm=C3=A5forbedringer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime/iof_xml.py | 2 +- otime/otime.py | 18 +++++++++++------- otime/pdf.py | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/otime/iof_xml.py b/otime/iof_xml.py index fb71e5b..4145294 100644 --- a/otime/iof_xml.py +++ b/otime/iof_xml.py @@ -16,7 +16,7 @@ def create_result_file(event, file_path, o_classes=[]): root.set('iofVersion', '3.0') root.set('createTime', datetime.datetime.now().isoformat(timespec='seconds')) root.set('creator', 'oTime') - root.set('status', 'Complete') + #root.set('status', 'Complete') tree = ET.ElementTree(root) xml_event = ET.SubElement(root, 'Event') xml_child(xml_event, 'Id', event.id) diff --git a/otime/otime.py b/otime/otime.py index d7fd7ee..d13b999 100644 --- a/otime/otime.py +++ b/otime/otime.py @@ -94,7 +94,7 @@ class CardDump: splits.append(time) # Extract start time: - year = int.from_bytes(datamsg[8:9], 'little') + year = 2000 + int.from_bytes(datamsg[8:9], 'little') month = int.from_bytes(datamsg[9:10], 'little') day = int.from_bytes(datamsg[10:11], 'little') hours = int.from_bytes(datamsg[11:12], 'little') @@ -182,7 +182,7 @@ class OClass: class RunnerResult: def __init__(self, runner_id: int, first: str, last: str, status: str, place: int, total_time: int, splits: list[int], end_time, - club=None, club_id=None, country=None, card_id=None, o_class=None, controls=None, fork=0, start_time=None, fee_id=None): + club=None, club_id=None, country=None, card_id=None, o_class=None, controls=None, fork=0, start_time=datetime.datetime(1973, 1, 1), fee_id=None): self.id = runner_id self.first = first self.last = last @@ -268,13 +268,17 @@ class Event: if not o_class: return 'Inactive' course = self.get_course(o_class.course) - if self.get_card_dump(runner.card_id) == None: + if not self.get_card_dump(runner.card_id): return 'Active' if contains(course.codes, self.get_card_dump(runner.card_id).controls): return 'OK' else: return 'MissingPunch' + def get_runner_result(self, runner_id): + runner = self.get_runner(runner_id) + return next((i for i in produce_class_result(self, runner.o_class).runner_results if i.id == runner_id), None) + def get_runner_time(self, id): runner = self.get_runner(id) card_dump = self.get_card_dump(runner.card_id) @@ -331,7 +335,7 @@ class Event: def get_result(self, o_classes: list[str] = []) -> list[ClassResult]: if not o_classes: o_classes = [i.name for i in self.o_classes] - return [produce_class_result(copy.deepcopy(self), i) for i in o_classes] + return [produce_class_result(self, i) for i in o_classes] def read_xml_entries(self, xml_file): self.add_runners(*runners_from_xml_entries(xml_file)) @@ -379,11 +383,11 @@ def produce_class_result(event, o_class_name) -> ClassResult: other_runners = [i for i in runners if i not in ok_runners and i not in dsq_runners] results = [RunnerResult(i.id, i.first, i.last, event.get_runner_status(i.id), ok_runners.index(i)+1, event.get_runner_time(i.id), event.get_runner_splits(i.id), - event.get_runner_end_clock(i.id), i.club, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in ok_runners] + event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in ok_runners] results += [RunnerResult(i.id, i.first, i.last, event.get_runner_status(i.id), 0, event.get_runner_time(i.id), event.get_runner_splits(i.id), - event.get_runner_end_clock(i.id), i.club, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in dsq_runners] + event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in dsq_runners] results += [RunnerResult(i.id, i.first, i.last, event.get_runner_status(i.id), 0, event.get_runner_time(i.id), event.get_runner_splits(i.id), - event.get_runner_end_clock(i.id), i.club, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in other_runners] + event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in other_runners] return ClassResult(o_class.name, event.get_course(o_class.course), results) diff --git a/otime/pdf.py b/otime/pdf.py index de5d16a..c179dee 100644 --- a/otime/pdf.py +++ b/otime/pdf.py @@ -11,7 +11,7 @@ def create_result_list(event, file_path, o_classes=[]): pdf = FPDF() pdf.add_page() - pdf.add_font("LiberationSans", fname="../../otime/data/fonts/LiberationSans-Regular.ttf") + pdf.add_font("LiberationSans", fname="otime/data/fonts/LiberationSans-Regular.ttf") pdf.set_font("LiberationSans", size=10) line_height = pdf.font_size * 1.5 col_width = pdf.epw / 4 # distribute content evenly @@ -38,7 +38,7 @@ def create_split_result_list(event, file_path, o_classes=[]): pdf = FPDF() pdf.add_page(orientation='L') - pdf.add_font("LiberationSans", fname="../../otime/data/fonts/LiberationSans-Regular.ttf") + pdf.add_font("LiberationSans", fname="otime/data/fonts/LiberationSans-Regular.ttf") pdf.set_font("LiberationSans", size=8) line_height = pdf.font_size * 1.5 col_width = pdf.epw / 4 # distribute content evenly