From 527b2e93c34f4ee26297b7f3f333741e57528889 Mon Sep 17 00:00:00 2001 From: Trygve Date: Wed, 9 Feb 2022 21:44:13 +0100 Subject: [PATCH] la til import fra ttime db --- cli.py | 5 +++-- otime.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index 3c58492..4322c20 100644 --- a/cli.py +++ b/cli.py @@ -47,9 +47,10 @@ def print_o_classes(class_list): if __name__ == "__main__": courses = otime.courses_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt') o_classes = otime.classes_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt', courses) - runner_list = otime.xml_to_class('entries_KOK_Sommercup,_løp_2.xml', o_classes) + runner_list = otime.ttime_db_to_class('sc_2021_ttime/db_eventor.csv', o_classes) + #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_time(runner_list) - #print_o_classes(o_classes) + print_o_classes(o_classes) #print(otime.check_codes(runner_list[1])) diff --git a/otime.py b/otime.py index 1087074..1e1e23c 100644 --- a/otime.py +++ b/otime.py @@ -95,6 +95,36 @@ def xml_to_class(xml_file, o_class_list=[]): # Gjør sånn at den lager nye o klasser om den ikke finnes fra før runnerarray.append(runner(first, last, club, country, card, runner_o_class, [], [])) return runnerarray +def ttime_db_to_class(ttime_file, o_class_list=[]): + csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',) + runnerarray = [] + for row in csvreader: + country = '' + name = row[2].split(',') + first = name[1] + last = name[0] + try: + club = row[4] + except: + club = "None" + try: + card = int(row[6]) + except: + card = 0 + try: + raw_class_str = row[3] + except: + # VELDIG MIDLERTIDIG + runner_o_class = o_class_list[0] + else: + for i in o_class_list: + if i.name == raw_class_str: + runner_o_class = i + break + # TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før + runnerarray.append(runner(first, last, club, country, card, runner_o_class, [], [])) + return runnerarray + def ttime_mtr_to_class(csv_file, runnerarray): csvreader = csv.reader(open(csv_file)) fields = next(csvreader)