From 275f4b0f78d9dfa1f867f85518ede598af5dc6e4 Mon Sep 17 00:00:00 2001 From: Trygve Date: Sun, 5 Nov 2023 17:32:04 +0100 Subject: [PATCH] =?UTF-8?q?Fortsatte=20p=C3=A5=20produce=5Fclass=5Fresult?= =?UTF-8?q?=20funksjonen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime/otime.py | 78 +++++++++++++++++++++-------------- test_files/sc3_23/sc3_test.py | 2 + 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/otime/otime.py b/otime/otime.py index b98e3f7..3ba89a5 100644 --- a/otime/otime.py +++ b/otime/otime.py @@ -5,10 +5,10 @@ import xml.etree.ElementTree as etree import pdf class Runner: - def __init__(self, runner_id: int, first: str, last: str, club=None, club_id=None, + 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): - self.id = runner_id + self.id = id self.first = first self.last = last self.club = club @@ -19,7 +19,7 @@ class Runner: self.fork = fork self.start_time = start_time self.fee_id = fee_id - + self.status_override = '' def __repr__(self): return(f'name({self.fullname()})') @@ -62,25 +62,6 @@ class Runner: def fullname(self): return '{} {}'.format(self.first, self.last) - def check_codes(self): - return contains(self.res_codes(), self.card_r.controls) - - def totaltime(self): - f_control = self.res_codes()[-1] - try: - index = self.card_r.controls.index(f_control) - return self.card_r.splits[index] - except: - return 0 - - def status(self): - if hasattr(self, 'card_r') is False or self.o_class is None: - return 'Active' - elif self.check_codes(): - return 'OK' - elif self.check_codes() is False: - return 'Disqualified' - # TODO: må forbedres def rank(self, allrunners): c_ranked = rank_runners(allrunners, self.o_class) @@ -286,7 +267,6 @@ class RunnerResult: self.first = first self.last = last self.club = club - self.club_id = club_id self.country = country self.card_id = card_id self.o_class = o_class @@ -344,18 +324,51 @@ class Event: self.fees.append(n) def get_course(self, name): - pass + return next((copy.copy(i) for i in self.courses if i.name == name), None) def get_o_class(self, name): return next((copy.copy(i) for i in self.o_classes if i.name == name), None) - def get_runner(self, name): - pass + def get_card_dump(self, id): + return next((copy.copy(i) for i in self.card_dumps if i.card == id), None) + + def get_runner(self, id): + return next((copy.copy(i) for i in self.runners if i.id == id), None) + + def get_runner_status(self, id): + # https://github.com/international-orienteering-federation/datastandard-v3/blob/24eb108e4c6b5e2904e5f8f0e49142e45e2c5230/IOF.xsd#L2903C3-L2903C3 + runner = self.get_runner(id) + if runner.status_override: return runner.status_override + o_class = self.get_o_class(runner.o_class) + course = self.get_course(o_class.course) + if self.get_card_dump(runner.card_id) == None: + return 'Active' + if contains(course.codes, self.get_card_dump(runner.card_id).controls): + return 'OK' + else: + return 'MissingPunch' + + def get_runner_time(self, id): + runner = self.get_runner(id) + card_dump = self.get_card_dump(runner.card_id) + f_control = card_dump.controls[-1] + # TODO: Må gjøres mer robust + try: + index = card_dump.controls.index(f_control) + return card_dump.splits[index] + except: + return False + + def get_runner_splits(self, id): + return self.get_card_dump(self.get_runner(id).card_id).splits + def get_runner_end_clock(self, id): + return self.get_card_dump(self.get_runner(id).card_id).f_time + 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(self, i) for i in o_classes] + return [produce_class_result(copy.deepcopy(self), i) for i in o_classes] def read_xml_entries(self, xml_file): self.add_runners(*runners_from_xml_entries(xml_file)) @@ -493,8 +506,6 @@ class Event: ET.indent(root, space=' ', level=0) return tree -# The runner object stores all the data specific to a runner. - class Fee: def __init__(self, fee_id, name, currency, amount, from_birth_date=None, to_birth_date=None): @@ -518,8 +529,13 @@ class Fee: def produce_class_result(event, o_class_name) -> ClassResult: o_class = event.get_o_class(o_class_name) runners = event.get_runners_in_o_class(o_class_name) - - + ok_runners = [i for i in runners if event.get_runner_status(i.id) == 'OK'] + dsq_runners = [i for i in runners if event.get_runner_status(i.id) == 'MissingPunch' or event.get_runner_status(i.id) == 'Disqualified'] + other_runners = [i for i in runners if i not in ok_runners or i not in dsq_runners] + results = [RunnerResult(i.id, i.first, i.last, 0, event.get_runner_time(i.id), event.get_runner_splits(i.id), + event.get_runner_end_clock(i.id), i.club + ) for i in ok_runners] + return results # TODO: Take string instead of file. def courses_from_ttime_conf(ttime_file): diff --git a/test_files/sc3_23/sc3_test.py b/test_files/sc3_23/sc3_test.py index 61242a7..012220b 100644 --- a/test_files/sc3_23/sc3_test.py +++ b/test_files/sc3_23/sc3_test.py @@ -7,7 +7,9 @@ def main(): event.read_ttime_cnf('tt.cnf') event.read_ttime_db('db.csv') event.read_mtr_file('mtr.csv') + print(event.get_runner_status('28130')) print(event.get_result()) event.create_start_list_pdf('output/result.pdf') + if __name__ == '__main__': main() \ No newline at end of file