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_o_classes(o_classes)
#print_class_splits(runner_list, o_classes[0]) #print_class_splits(runner_list, o_classes[0])
#print(otime.check_codes(runner_list[1])) #print(otime.check_codes(runner_list[1]))
#otime.gen_xml_result(runner_list, o_classes) 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))

View File

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