la til import fra ttime db #1

Merged
Trygve merged 1 commits from ttime-db-import into master 2022-02-09 20:50:41 +00:00
2 changed files with 33 additions and 2 deletions

5
cli.py
View File

@ -47,9 +47,10 @@ def print_o_classes(class_list):
if __name__ == "__main__": if __name__ == "__main__":
courses = otime.courses_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt') 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) 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) otime.ttime_mtr_to_class('sc_2021_ttime/mtr.csv', runner_list)
print_runners(runner_list) print_runners(runner_list)
print_time(runner_list) print_time(runner_list)
#print_o_classes(o_classes) print_o_classes(o_classes)
#print(otime.check_codes(runner_list[1])) #print(otime.check_codes(runner_list[1]))

View File

@ -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 # 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, [], [])) runnerarray.append(runner(first, last, club, country, card, runner_o_class, [], []))
return runnerarray 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): def ttime_mtr_to_class(csv_file, runnerarray):
csvreader = csv.reader(open(csv_file)) csvreader = csv.reader(open(csv_file))
fields = next(csvreader) fields = next(csvreader)