La til strekktider i eksporten og fiksa kodesjekken

This commit is contained in:
Trygve 2022-02-17 21:17:14 +01:00
parent ebe25acca8
commit ebc023764e
2 changed files with 52 additions and 21 deletions

6
cli.py
View File

@ -71,8 +71,4 @@ if __name__ == "__main__":
#print_o_classes(o_classes)
#print_class_splits(runner_list, o_classes[0])
#print(otime.check_codes(runner_list[1]))
#otime.gen_xml_result(runner_list, o_classes)
testco = [51,52,53,31,32,23,33,34,35,55,56]
testrunner = [31,32,33,34,35]
print(otime.contains(testrunner, testco))
otime.gen_xml_result(runner_list, o_classes)

View File

@ -1,6 +1,5 @@
import datetime
import csv
import sqlite3
import re
from rich.console import Console
from rich.table import Table
@ -40,8 +39,20 @@ class runner:
c_ranked = rank_runners(allrunners, self.o_class)
return c_ranked.index(self) + 1
def res_splits(self):
pass
control_map = self.check_codes()
splits = []
lastn = 0
for n in control_map:
if n != lastn+1:
splits.append(self.splits[n])
else:
# Dette må testes ordentlig seinere!
gap = n - lastn
split = 0
for i in range(gap):
split += self.splits[n-gap]
splits.append(split)
return splits
class course:
def __init__(self, name, codes):
self.name = name
@ -182,18 +193,26 @@ def ttime_mtr_to_class(csv_file, runnerarray):
runner.s_time = s_time
def contains(small, big):
for i in range(len(big)-len(small)+1):
for j in range(len(small)):
if big[i+j] != small[j]:
valid = True
mark = 0
map_bl = []
for i in small:
for n,control in enumerate(big[mark:]):
if i == control:
mark += n
map_bl.append(mark)
break
else:
return i, i+len(small)
return True
valid = False
if valid:
return map_bl
else:
return False
def get_runners_in_class(runners, o_class):
list_filtrd = []
for i in runners:
marker = 0
if i.o_class == o_class:
list_filtrd.append(i)
@ -211,6 +230,8 @@ def gen_xml_result(runners, o_classes):
root = ET.Element('ResultList')
tree = ET.ElementTree(root)
event = ET.SubElement(root, 'Event')
ename = ET.SubElement(event, 'Name')
ename.text = 'PLACEHOLDER'
for i in o_classes:
#<ClassResult>
class_result = ET.SubElement(root, 'ClassResult')
@ -247,7 +268,7 @@ def gen_xml_result(runners, o_classes):
country.set('code', 'NOR')
#</Organisation>
#<Result>
result = ET.SubElement(person, 'Result')
result = ET.SubElement(person_result, 'Result')
if len(n.splits) > 2:
start_t = ET.SubElement(result, 'StartTime')
start_t.text = n.s_time.isoformat()
@ -260,13 +281,27 @@ def gen_xml_result(runners, o_classes):
totime = ET.SubElement(result, 'TimeBehind')
totime.text = str(n.totaltime() - runners_ranked[0].totaltime())
#</TimeBehind>
rank = ET.SubElement(result, 'Rank')
rank.text = str(n.rank(runners))
pos = ET.SubElement(result, 'Position')
pos.text = str(n.rank(runners))
status = ET.SubElement(result, 'Status')
status.text = n.status()
#<SplitTime>
for code,split in zip(n.o_class.course.codes, n.res_splits()):
st = ET.SubElement(result, 'SplitTime')
ck = ET.SubElement(st, 'ControlCode')
ck.text = str(code)
time = ET.SubElement(st, 'Time')
time.text = str(split)
#</SplitTime>
else:
status = ET.SubElement(result, 'Status')
status.text = n.status()
else:
status = ET.SubElement(result, 'Status')
status.text = n.status()
#</Result>
#</PersonResult>
#</Class>
tree.write('output.xml')
tree.write('Resultater.xml')
return ET.dump(root)