From 2d5753a31e8cf874b1f7f53c0e7f0850b57b2bc1 Mon Sep 17 00:00:00 2001 From: Trygve Date: Mon, 21 Feb 2022 12:51:54 +0100 Subject: [PATCH] La til strekktider for dsq i eksporten --- otime.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/otime.py b/otime.py index 6508a0d..247ecf9 100644 --- a/otime.py +++ b/otime.py @@ -1,13 +1,10 @@ import datetime import csv import re -from rich.console import Console -from rich.table import Table -from rich.traceback import install import xml.etree.ElementTree as ET -install(show_locals=True) class runner: - def __init__(self, first, last, club, country, card, o_class, controls, splits): + def __init__(self, eventorid, first, last, club, country, card, o_class, controls, splits): + self.id = eventorid self.first = first self.last = last self.club = club @@ -16,7 +13,6 @@ class runner: self.o_class = o_class self.controls = controls self.splits = splits - self.id = 0 self.s_time = 0 self.f_time = 0 @@ -65,7 +61,7 @@ class o_class: def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'): courses = [] - conf = open(ttime_file).readlines() + conf = open(ttime_file, 'r', encoding='latin_1').readlines() for line in conf: if '-codes' in line: code_list = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';') @@ -78,7 +74,7 @@ def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'): return courses def classes_from_ttime_conf(ttime_file, courses): o_classes = [] - conf = open(ttime_file).readlines() + conf = open(ttime_file, 'r', encoding='latin_1').readlines() for line in conf: if '-courses' in line: raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';') @@ -126,6 +122,7 @@ 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: + eventorid = row[0] country = '' name = row[2].split(',') first = name[1] @@ -149,7 +146,7 @@ def ttime_db_to_class(ttime_file, o_class_list=[]): 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, [], [])) + runnerarray.append(runner(eventorid, first, last, club, country, card, runner_o_class, [], [])) return runnerarray def ttime_mtr_to_class(csv_file, runnerarray): @@ -232,6 +229,10 @@ def xml_child(parent, tag, content): def gen_xml_result(runners, o_classes): root = ET.Element('ResultList') + root.set('iofVersion', '3.0') + root.set('createTime', datetime.datetime.now().isoformat()) + root.set('creator', 'oTime') + root.set('status', 'Complete') tree = ET.ElementTree(root) event = ET.SubElement(root, 'Event') xml_child(event, 'Name', 'PLACEHOLDER') @@ -248,7 +249,7 @@ def gen_xml_result(runners, o_classes): person_result = ET.SubElement(class_result, 'PersonResult') # person = ET.SubElement(person_result, 'Person') - xml_child(person, 'Id', '0') + xml_child(person, 'Id', n.id) # name = ET.SubElement(person, 'Name') xml_child(name, 'Family', n.last) @@ -277,11 +278,19 @@ def gen_xml_result(runners, o_classes): xml_child(result, 'Position', n.rank(runners)) xml_child(result, 'Status', n.status()) # - for code,split in zip(n.o_class.course.codes, n.res_splits()): + for code,split in zip(n.o_class.course.codes, n.res_splits(), strict=True): st = ET.SubElement(result, 'SplitTime') xml_child(st, 'ControlCode', code) xml_child(st, 'Time', split) # + elif n.status() == 'Disqualified': + xml_child(result, 'Status', n.status()) + for code in n.o_class.course.codes: + st = ET.SubElement(result, 'SplitTime') + xml_child(st, 'ControlCode', code) + for control,split in zip(n.controls, n.splits): + if code == control: + xml_child(st, 'Time', split) else: xml_child(result, 'Status', n.status()) else: @@ -289,6 +298,6 @@ def gen_xml_result(runners, o_classes): # # # - + ET.indent(root, space=' ', level=0) tree.write('Resultater.xml') - return ET.dump(root) + return tree