La til strekktider for dsq i eksporten

This commit is contained in:
Trygve 2022-02-21 12:51:54 +01:00
parent 170542fbd0
commit 2d5753a31e

View File

@ -1,13 +1,10 @@
import datetime import datetime
import csv import csv
import re import re
from rich.console import Console
from rich.table import Table
from rich.traceback import install
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
install(show_locals=True)
class runner: 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.first = first
self.last = last self.last = last
self.club = club self.club = club
@ -16,7 +13,6 @@ class runner:
self.o_class = o_class self.o_class = o_class
self.controls = controls self.controls = controls
self.splits = splits self.splits = splits
self.id = 0
self.s_time = 0 self.s_time = 0
self.f_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'): def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
courses = [] courses = []
conf = open(ttime_file).readlines() conf = open(ttime_file, 'r', encoding='latin_1').readlines()
for line in conf: for line in conf:
if '-codes' in line: if '-codes' in line:
code_list = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';') 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 return courses
def classes_from_ttime_conf(ttime_file, courses): def classes_from_ttime_conf(ttime_file, courses):
o_classes = [] o_classes = []
conf = open(ttime_file).readlines() conf = open(ttime_file, 'r', encoding='latin_1').readlines()
for line in conf: for line in conf:
if '-courses' in line: if '-courses' in line:
raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';') 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=';',) csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',)
runnerarray = [] runnerarray = []
for row in csvreader: for row in csvreader:
eventorid = row[0]
country = '' country = ''
name = row[2].split(',') name = row[2].split(',')
first = name[1] first = name[1]
@ -149,7 +146,7 @@ def ttime_db_to_class(ttime_file, o_class_list=[]):
runner_o_class = i runner_o_class = i
break break
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før # 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 return runnerarray
def ttime_mtr_to_class(csv_file, 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): def gen_xml_result(runners, o_classes):
root = ET.Element('ResultList') 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) tree = ET.ElementTree(root)
event = ET.SubElement(root, 'Event') event = ET.SubElement(root, 'Event')
xml_child(event, 'Name', 'PLACEHOLDER') xml_child(event, 'Name', 'PLACEHOLDER')
@ -248,7 +249,7 @@ def gen_xml_result(runners, o_classes):
person_result = ET.SubElement(class_result, 'PersonResult') person_result = ET.SubElement(class_result, 'PersonResult')
#<Person> #<Person>
person = ET.SubElement(person_result, 'Person') person = ET.SubElement(person_result, 'Person')
xml_child(person, 'Id', '0') xml_child(person, 'Id', n.id)
#<Name> #<Name>
name = ET.SubElement(person, 'Name') name = ET.SubElement(person, 'Name')
xml_child(name, 'Family', n.last) 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, 'Position', n.rank(runners))
xml_child(result, 'Status', n.status()) xml_child(result, 'Status', n.status())
#<SplitTime> #<SplitTime>
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') st = ET.SubElement(result, 'SplitTime')
xml_child(st, 'ControlCode', code) xml_child(st, 'ControlCode', code)
xml_child(st, 'Time', split) xml_child(st, 'Time', split)
#</SplitTime> #</SplitTime>
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: else:
xml_child(result, 'Status', n.status()) xml_child(result, 'Status', n.status())
else: else:
@ -289,6 +298,6 @@ def gen_xml_result(runners, o_classes):
#</Result> #</Result>
#</PersonResult> #</PersonResult>
#</Class> #</Class>
ET.indent(root, space=' ', level=0)
tree.write('Resultater.xml') tree.write('Resultater.xml')
return ET.dump(root) return tree