From 71020bc340cfe8ce5361e1f4128d475b8cb77a72 Mon Sep 17 00:00:00 2001 From: Trygve Date: Thu, 7 Dec 2023 00:00:08 +0100 Subject: [PATCH] =?UTF-8?q?RWC=20sjekk=20for=20diska=20l=C3=B8pere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime/cli.py | 4 ++-- otime/file_io.py | 3 +++ otime/otime.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/otime/cli.py b/otime/cli.py index b019568..ac52974 100644 --- a/otime/cli.py +++ b/otime/cli.py @@ -110,7 +110,7 @@ def run(port='/dev/ttyUSB0', project_dir='./', xml_path='./output/'): try: print(otime.CardDump.from_mtr_bytes(message)) print(runner_info(event, card_dump)) - except ValueError as error: + except Exception as error: print(error) else: card_dump = otime.CardDump.from_mtr_bytes(message) @@ -155,7 +155,7 @@ def gen(project_dir='./', xml_path='./output/'): def runner_info(event, card_dump): runner = next((i for i in event.runners if str(i.card_id) == str(card_dump.card)), None) if runner is None: - return card_dump + return f'[orange_red1]No runner with ecard {card_dump.card}! It matches these courses: {otime.find_courses_matching_controls(card_dump.controls, event.courses)}[/orange_red1] {card_dump}' result = event.get_runner_result(runner.id) if result is None: return '🧐 Dette skal ikke skje...' diff --git a/otime/file_io.py b/otime/file_io.py index 27cc851..c0399f5 100644 --- a/otime/file_io.py +++ b/otime/file_io.py @@ -46,6 +46,9 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path): i[7] = i[7] else: i[7] = None + # Sjekk om brikkenummer er tomt + if i[5] == '': + i[5] = 0 runners = [otime.Runner(id=i[0], status_override=i[1], first=i[2][0], last=i[2][1].strip(), o_class=i[3], club=i[4], card_id=int(i[5]), fork=int(i[6]), start_time=i[7]) for i in data] event.card_dumps = card_dumps event.runners = runners diff --git a/otime/otime.py b/otime/otime.py index 8397551..6cd648d 100644 --- a/otime/otime.py +++ b/otime/otime.py @@ -404,7 +404,8 @@ def produce_class_result(event, o_class_name) -> ClassResult: 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, 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, - missed_controls=find_missed_controls(event.get_runner_controls(i.id), event.get_course(o_class.course).codes[i.fork])) + missed_controls=find_missed_controls(event.get_runner_controls(i.id), event.get_course(o_class.course).codes[i.fork]), + ran_other_course=find_courses_matching_controls(event.get_card_dump(i.card_id).controls, event.courses)) 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, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in other_runners] @@ -461,4 +462,12 @@ def contains(small, big): return False def find_missed_controls(punches, codes): - return [i for i in codes if i not in punches] \ No newline at end of file + return [i for i in codes if i not in punches] + +def find_courses_matching_controls(controls, courses): + matches = [] + for i in courses: + for fork in i.codes: + if contains(fork, controls): + matches.append(i.name) + return matches \ No newline at end of file