From 64121fa32497ad1cbb3eae5cd604281f279ae9d7 Mon Sep 17 00:00:00 2001 From: Trygve Date: Tue, 8 Feb 2022 21:56:44 +0100 Subject: [PATCH] =?UTF-8?q?Funksjon=20som=20sjekker=20om=20l=C3=B8pet=20er?= =?UTF-8?q?=20godkjent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli.py | 22 ++++++++++++++++++++-- otime.py | 23 +++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/cli.py b/cli.py index cae2f1c..3c58492 100644 --- a/cli.py +++ b/cli.py @@ -1,5 +1,6 @@ import otime +import datetime from rich.console import Console from rich.table import Table def print_runners(Runners): @@ -13,6 +14,22 @@ def print_runners(Runners): for i in Runners: table.add_row(i.fullname(), i.club ,str(i.card), i.o_class.name, str(i.controls)) + console = Console() + console.print(table) +def print_time(Runners): + table = Table(title="Runners") + table.add_column("Name", justify="right", style="cyan", no_wrap=True) + table.add_column("club", style="magenta") + table.add_column("card", style="red") + table.add_column("class", style="green") + table.add_column("controls", justify="right", style="blue") + for i in Runners: + try: + tottime = datetime.timedelta(seconds = i.totaltime()) + except: + tottime = 0 + table.add_row(i.fullname(), i.o_class.name, str(i.splits), str(i.check_codes()), str(tottime)) + console = Console() console.print(table) def print_o_classes(class_list): @@ -33,5 +50,6 @@ if __name__ == "__main__": runner_list = otime.xml_to_class('entries_KOK_Sommercup,_løp_2.xml', o_classes) otime.ttime_mtr_to_class('sc_2021_ttime/mtr.csv', runner_list) print_runners(runner_list) - print_o_classes(o_classes) - otime.check_codes(runner_list[21], o_classes) + print_time(runner_list) + #print_o_classes(o_classes) + #print(otime.check_codes(runner_list[1])) diff --git a/otime.py b/otime.py index 2d7045e..1087074 100644 --- a/otime.py +++ b/otime.py @@ -20,6 +20,11 @@ class runner: def fullname(self): return '{} {}'.format(self.first, self.last) + # Returns False if not ok and touple if ok + def check_codes(self): + return contains(self.o_class.course.codes, self.controls) + def totaltime(self): + return self.splits[-2] class course: def __init__(self, name, codes): @@ -115,9 +120,15 @@ def ttime_mtr_to_class(csv_file, runnerarray): if runner.card == int(row[6]): runner.controls = controls runner.splits = splits -def check_codes(runner, course_list): - print(runner.fullname()) - print(runner.o_class.name) - print(runner.controls) - print(runner.o_class.course.codes) - + +def contains(small, big): + for i in range(len(big)-len(small)+1): + for j in range(len(small)): + if big[i+j] != small[j]: + break + else: + return i, i+len(small) + return True + return False + +