La til strekktider for dsq i eksporten
This commit is contained in:
parent
170542fbd0
commit
2d5753a31e
35
otime.py
35
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>
|
||||
person = ET.SubElement(person_result, 'Person')
|
||||
xml_child(person, 'Id', '0')
|
||||
xml_child(person, 'Id', n.id)
|
||||
#<Name>
|
||||
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())
|
||||
#<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')
|
||||
xml_child(st, 'ControlCode', code)
|
||||
xml_child(st, 'Time', split)
|
||||
#</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:
|
||||
xml_child(result, 'Status', n.status())
|
||||
else:
|
||||
@ -289,6 +298,6 @@ def gen_xml_result(runners, o_classes):
|
||||
#</Result>
|
||||
#</PersonResult>
|
||||
#</Class>
|
||||
|
||||
ET.indent(root, space=' ', level=0)
|
||||
tree.write('Resultater.xml')
|
||||
return ET.dump(root)
|
||||
return tree
|
||||
|
Loading…
Reference in New Issue
Block a user