Everything is now contained in the Event class.

This commit is contained in:
Trygve 2022-03-05 17:35:33 +01:00
parent 1a3dc6f4e2
commit 13949303a5
2 changed files with 13 additions and 79 deletions

13
dev.py
View File

@ -6,23 +6,10 @@ from rich.columns import Columns
from rich.table import Table
if __name__ == "__main__":
#courses = otime.courses_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt')
#o_classes = otime.classes_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt', courses)
#runner_list = otime.ttime_db_to_class('sc_2021_ttime/db_eventor.csv', o_classes)
#runner_list = otime.xml_to_class('entries_KOK_Sommercup,_løp_2.xml', o_classes)
#otime.ttime_mtr_to_class('sc_2021_ttime/mtr.csv', runner_list)
#print_runners(runner_list)
#print_time(runner_list)
#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)
event = otime.event(0, 'supercup')
event.import_ttime_cnf('sc_2021_ttime/ttime.cnf.txt')
event.import_ttime_db('sc_2021_ttime/db_eventor.csv')
event.import_mtr_file('sc_2021_ttime/mtr.csv')
#card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv')
event.append_punch_list(event.card_punches)
event.match_runners_cards()
event.get_xml_res().write('Resultater.xml')

View File

@ -38,16 +38,6 @@ class event:
if n.card == i.card:
n.card_r = i
# MIDLERTIDIG
def append_punch_list(self, punches):
for n in self.runners:
for i in punches:
if n.card == i.card:
n.controls = list(i.punches.keys())
n.splits = list(i.punches.values())
n.s_time = i.s_time
n.f_time = i.f_time
def get_xml_res(self):
root = ET.Element('ResultList')
root.set('xmlns', 'http://www.orienteering.org/datastandard/3.0')
@ -95,9 +85,9 @@ class event:
#</Organisation>
#<Result>
result = ET.SubElement(person_result, 'Result')
if len(n.splits) > 2:
xml_child(result, 'StartTime', n.s_time.isoformat())
xml_child(result, 'FinishTime', n.f_time.isoformat())
if hasattr(n,'card_r') and len(n.card_r.punches) > 2:
xml_child(result, 'StartTime', n.card_r.s_time.isoformat())
xml_child(result, 'FinishTime', n.card_r.f_time.isoformat())
xml_child(result, 'Time', n.totaltime())
if n.status() == 'OK':
#<TimeBehind>
@ -106,7 +96,7 @@ class event:
xml_child(result, 'Position', n.rank(self.runners))
xml_child(result, 'Status', n.status())
#<SplitTime>
for code,split in zip(n.o_class.course.codes, n.res_splits(), strict=True):
for code,split in n.res_splits().items():
st = ET.SubElement(result, 'SplitTime')
xml_child(st, 'ControlCode', code)
xml_child(st, 'Time', split)
@ -116,7 +106,7 @@ class event:
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):
for control,split in n.card_r.punches.items():
if code == control:
xml_child(st, 'Time', split)
else:
@ -137,16 +127,12 @@ class runner:
self.country = country
self.card = card
self.o_class = o_class
self.controls = controls
self.splits = splits
self.s_time = 0
self.f_time = 0
def fullname(self):
return '{} {}'.format(self.first, self.last)
def check_codes(self):
# Returns False if not ok and touple if ok
return contains(self.o_class.course.codes, self.controls)
return contains(self.o_class.course.codes, list(self.card_r.punches.keys()))
def totaltime(self):
f_control = self.o_class.course.codes[-1]
try:
@ -155,7 +141,7 @@ class runner:
return list(self.card_r.punches.values())[-1]
def status(self):
if self.controls == []:
if hasattr(self, 'card_r') == False:
return 'Active'
elif self.check_codes():
return 'OK'
@ -165,11 +151,12 @@ class runner:
c_ranked = rank_runners(allrunners, self.o_class)
return c_ranked.index(self) + 1
def res_splits(self):
res_p = self.card_r.punches.copy()
for key in res_p.keys:
if key not in self.o_class.course.codes
res_p.pop(key)
return res_p
punches = self.card_r.punches
punches_ret = punches.copy()
for key in punches.keys():
if key not in self.o_class.course.codes:
punches_ret.pop(key)
return punches_ret
class card_punch:
def __init__(self, card, punches, s_time, f_time):
@ -321,46 +308,6 @@ def ttime_db_to_class(ttime_file, o_class_list=[]):
runnerarray.append(runner(eventorid, first, last, club, country, card, runner_o_class, [], []))
return runnerarray
# Denne fjernes når card_punch klasses er ferdig
def ttime_mtr_to_class(csv_file, runnerarray):
csvreader = csv.reader(open(csv_file))
fields = next(csvreader)
fields = []
rows = []
# hver rad er brikkenummer med tilhørende info
for row in csvreader:
rows.append(row)
for row in rows:
controls = []
splits = []
# postkodene kommer på oddetall fra og med den 11. De blir hevet inn i controls
for item in row[11::2]:
if item != '000' and item != '0000' and item != '00000':
controls.append(int(item))
# strekktidene kommer på partall fra og med den 12. De blir hevet i splits.
for item in row[12::2]:
if item != '000' and item != '0000' and item != '00000':
splits.append(int(item))
# looper gjonnom løperobjektene og legger til poster og strekktider + start og sluttid
for runner in runnerarray:
if runner.card == int(row[6]):
runner.controls = controls
runner.splits = splits
# usikker på om dette er riktig klokeslett
if len(runner.splits) > 2:
tl = row[5].split(' ')
tl[0] = tl[0].split('.')
tl[0][2] = '20' + tl[0][2]
tl[0] = list(map(int, tl[0]))
tl[1] = tl[1].split(':')
tl[1][2] = float(tl[1][2])
tl[1] = list(map(int, tl[1]))
f_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2])
s_time = f_time - datetime.timedelta(seconds = runner.totaltime())
runner.f_time = f_time
runner.s_time = s_time
def contains(small, big):
valid = True