Mer arbeid på xml eksport
This commit is contained in:
parent
178f0bcbd7
commit
77e7b25587
6
cli.py
6
cli.py
@ -65,10 +65,10 @@ if __name__ == "__main__":
|
|||||||
o_classes = otime.classes_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt', courses)
|
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.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)
|
#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)
|
otime.ttime_mtr_to_class('sc_2021_ttime/mtr.csv', runner_list)
|
||||||
print_runners(runner_list)
|
#print_runners(runner_list)
|
||||||
#print_time(runner_list)
|
#print_time(runner_list)
|
||||||
#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]))
|
||||||
print(otime.gen_xml_result(runner_list, o_classes))
|
otime.gen_xml_result(runner_list, o_classes)
|
||||||
|
54
otime.py
54
otime.py
@ -16,8 +16,11 @@ class runner:
|
|||||||
self.card = card
|
self.card = card
|
||||||
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.f_time = 0
|
||||||
|
|
||||||
def fullname(self):
|
def fullname(self):
|
||||||
return '{} {}'.format(self.first, self.last)
|
return '{} {}'.format(self.first, self.last)
|
||||||
def check_codes(self):
|
def check_codes(self):
|
||||||
@ -33,7 +36,9 @@ class runner:
|
|||||||
return 'OK'
|
return 'OK'
|
||||||
elif self.check_codes() == False:
|
elif self.check_codes() == False:
|
||||||
return 'Disqualified'
|
return 'Disqualified'
|
||||||
|
def rank(self, allrunners):
|
||||||
|
c_ranked = rank_runners(allrunners, self.o_class)
|
||||||
|
return c_ranked.index(self) + 1
|
||||||
|
|
||||||
class course:
|
class course:
|
||||||
def __init__(self, name, codes):
|
def __init__(self, name, codes):
|
||||||
@ -154,12 +159,26 @@ def ttime_mtr_to_class(csv_file, runnerarray):
|
|||||||
for item in row[12::2]:
|
for item in row[12::2]:
|
||||||
if item != '000' and item != '0000' and item != '00000':
|
if item != '000' and item != '0000' and item != '00000':
|
||||||
splits.append(int(item))
|
splits.append(int(item))
|
||||||
# looper gjonnom løperobjektene og legger til poster og strekktider
|
# looper gjonnom løperobjektene og legger til poster og strekktider + start og sluttid
|
||||||
for runner in runnerarray:
|
for runner in runnerarray:
|
||||||
if runner.card == int(row[6]):
|
if runner.card == int(row[6]):
|
||||||
runner.controls = controls
|
runner.controls = controls
|
||||||
runner.splits = splits
|
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):
|
def contains(small, big):
|
||||||
for i in range(len(big)-len(small)+1):
|
for i in range(len(big)-len(small)+1):
|
||||||
for j in range(len(small)):
|
for j in range(len(small)):
|
||||||
@ -170,7 +189,7 @@ def contains(small, big):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def filter_runners_by_class(runners, o_class):
|
def get_runners_in_class(runners, o_class):
|
||||||
list_filtrd = []
|
list_filtrd = []
|
||||||
for i in runners:
|
for i in runners:
|
||||||
if i.o_class == o_class:
|
if i.o_class == o_class:
|
||||||
@ -178,19 +197,27 @@ def filter_runners_by_class(runners, o_class):
|
|||||||
|
|
||||||
return list_filtrd
|
return list_filtrd
|
||||||
|
|
||||||
|
def rank_runners(allrunners, o_class):
|
||||||
|
runners = get_runners_in_class(allrunners, o_class)
|
||||||
|
runners_ranked = []
|
||||||
|
for i in runners:
|
||||||
|
if i.status() == 'OK':
|
||||||
|
runners_ranked.append(i)
|
||||||
|
return runners_ranked
|
||||||
|
|
||||||
def gen_xml_result(runners, o_classes):
|
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')
|
||||||
for i in o_classes:
|
for i in o_classes:
|
||||||
#<ClassResult>
|
#<ClassResult>
|
||||||
class_result = ET.SubElement(event, 'ClassResult')
|
class_result = ET.SubElement(root, 'ClassResult')
|
||||||
#<Class>
|
#<Class>
|
||||||
t = ET.SubElement(class_result, 'Class')
|
t = ET.SubElement(class_result, 'Class')
|
||||||
name = ET.SubElement(t, 'Name')
|
name = ET.SubElement(t, 'Name')
|
||||||
name.text = i.name
|
name.text = i.name
|
||||||
#<PersonResult>
|
#<PersonResult>
|
||||||
for n in filter_runners_by_class(runners, i):
|
for n in get_runners_in_class(runners, i):
|
||||||
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')
|
||||||
@ -216,7 +243,18 @@ 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')
|
||||||
|
if len(n.splits) > 2:
|
||||||
|
start_t = ET.SubElement(result, 'StartTime')
|
||||||
|
start_t.text = n.s_time.isoformat()
|
||||||
|
finish_t = ET.SubElement(result, 'FinishTime')
|
||||||
|
finish_t.text = n.f_time.isoformat()
|
||||||
|
time = ET.SubElement(result, 'Time')
|
||||||
|
time.text = str(n.totaltime())
|
||||||
|
#TODO:<TimeBehind>
|
||||||
|
if n.status() == 'OK':
|
||||||
|
rank = ET.SubElement(result, 'Rank')
|
||||||
|
rank.text = str(n.rank(runners))
|
||||||
status = ET.SubElement(result, 'Status')
|
status = ET.SubElement(result, 'Status')
|
||||||
status.text = n.status()
|
status.text = n.status()
|
||||||
#</Result>
|
#</Result>
|
||||||
|
Loading…
Reference in New Issue
Block a user