From 8621e07dcfcf0916eb692e966d15f8aad6cf8c3c Mon Sep 17 00:00:00 2001 From: Trygve Date: Mon, 6 Nov 2023 15:15:04 +0100 Subject: [PATCH] Fiksa pdf resultatliste --- otime/otime.py | 49 +++++++++++++++++++++++++---------- test_files/sc3_23/lenker.txt | 0 test_files/sc3_23/sc3_test.py | 7 ++--- 3 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 test_files/sc3_23/lenker.txt diff --git a/otime/otime.py b/otime/otime.py index 3ba89a5..a1d7823 100644 --- a/otime/otime.py +++ b/otime/otime.py @@ -127,8 +127,6 @@ class Runner: 'fee_id': self.fee_id } - - class CardDump: def __init__(self, card, controls, splits, read_time, s_time, f_time): self.card = card @@ -262,7 +260,7 @@ class OClass: class RunnerResult: def __init__(self, runner_id: int, first: str, last: str, status: str, place: int, total_time: int, split_times: list[int], end_time, - club=None, club_id=None, country=None, card_id=None, o_class=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=None, fee_id=None): self.id = runner_id self.first = first self.last = last @@ -270,6 +268,7 @@ class RunnerResult: self.country = country self.card_id = card_id self.o_class = o_class + self.controls = controls self.fork = fork self.start_time = start_time self.fee_id = fee_id @@ -279,12 +278,15 @@ class RunnerResult: self.total_time = total_time self.split_times = split_times self.end_time = end_time + + def fullname(self): + return f'{self.first} {self.last}' class ClassResult: def __init__(self, name: str, course: Course, runner_results: list[RunnerResult]): - self.name - self.course - self.runner_results + self.name = name + self.course = course + self.runner_results = runner_results class Event: def __init__(self, eventid, name, start_time=None, end_time=None, @@ -351,6 +353,9 @@ class Event: def get_runner_time(self, id): runner = self.get_runner(id) card_dump = self.get_card_dump(runner.card_id) + if card_dump == None: + return False + f_control = card_dump.controls[-1] # TODO: Må gjøres mer robust try: @@ -360,10 +365,22 @@ class Event: return False def get_runner_splits(self, id): - return self.get_card_dump(self.get_runner(id).card_id).splits + try: + return self.get_card_dump(self.get_runner(id).card_id).splits + except AttributeError: + return None + + def get_runner_controls(self, id): + try: + return self.get_card_dump(self.get_runner(id).card_id).controls + except AttributeError: + return None def get_runner_end_clock(self, id): - return self.get_card_dump(self.get_runner(id).card_id).f_time + try: + return self.get_card_dump(self.get_runner(id).card_id).f_time + except AttributeError: + return None def get_result(self, o_classes: list[str] = []) -> list[ClassResult]: if not o_classes: @@ -530,12 +547,18 @@ 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'] + ok_runners.sort(key=lambda i: event.get_runner_time(i.id)) 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 + 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)) 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)) 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] + + return ClassResult(o_class.name, o_class.course, results) # TODO: Take string instead of file. def courses_from_ttime_conf(ttime_file): diff --git a/test_files/sc3_23/lenker.txt b/test_files/sc3_23/lenker.txt new file mode 100644 index 0000000..e69de29 diff --git a/test_files/sc3_23/sc3_test.py b/test_files/sc3_23/sc3_test.py index 012220b..4dd93eb 100644 --- a/test_files/sc3_23/sc3_test.py +++ b/test_files/sc3_23/sc3_test.py @@ -1,15 +1,16 @@ import sys sys.path.insert(0, '../../otime') import otime +import pdf def main(): event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe') 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') + pdf.create_result_list(event, 'output/result.pdf') + print(event.get_runner_status('1400')) + results = event.get_result() if __name__ == '__main__': main() \ No newline at end of file