Mer arbeid på xml eksport
This commit is contained in:
parent
178f0bcbd7
commit
77e7b25587
4
cli.py
4
cli.py
@ -66,9 +66,9 @@ if __name__ == "__main__":
|
||||
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_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]))
|
||||
print(otime.gen_xml_result(runner_list, o_classes))
|
||||
otime.gen_xml_result(runner_list, o_classes)
|
||||
|
48
otime.py
48
otime.py
@ -17,6 +17,9 @@ class runner:
|
||||
self.o_class = o_class
|
||||
self.controls = controls
|
||||
self.splits = splits
|
||||
self.id = 0
|
||||
self.s_time = 0
|
||||
self.f_time = 0
|
||||
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
@ -33,7 +36,9 @@ class runner:
|
||||
return 'OK'
|
||||
elif self.check_codes() == False:
|
||||
return 'Disqualified'
|
||||
|
||||
def rank(self, allrunners):
|
||||
c_ranked = rank_runners(allrunners, self.o_class)
|
||||
return c_ranked.index(self) + 1
|
||||
|
||||
class course:
|
||||
def __init__(self, name, codes):
|
||||
@ -154,12 +159,26 @@ def ttime_mtr_to_class(csv_file, runnerarray):
|
||||
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
|
||||
# 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):
|
||||
for i in range(len(big)-len(small)+1):
|
||||
for j in range(len(small)):
|
||||
@ -170,7 +189,7 @@ def contains(small, big):
|
||||
return True
|
||||
return False
|
||||
|
||||
def filter_runners_by_class(runners, o_class):
|
||||
def get_runners_in_class(runners, o_class):
|
||||
list_filtrd = []
|
||||
for i in runners:
|
||||
if i.o_class == o_class:
|
||||
@ -178,19 +197,27 @@ def filter_runners_by_class(runners, o_class):
|
||||
|
||||
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):
|
||||
root = ET.Element('ResultList')
|
||||
tree = ET.ElementTree(root)
|
||||
event = ET.SubElement(root, 'Event')
|
||||
for i in o_classes:
|
||||
#<ClassResult>
|
||||
class_result = ET.SubElement(event, 'ClassResult')
|
||||
class_result = ET.SubElement(root, 'ClassResult')
|
||||
#<Class>
|
||||
t = ET.SubElement(class_result, 'Class')
|
||||
name = ET.SubElement(t, 'Name')
|
||||
name.text = i.name
|
||||
#<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>
|
||||
person = ET.SubElement(person_result, 'Person')
|
||||
@ -217,6 +244,17 @@ def gen_xml_result(runners, o_classes):
|
||||
#</Organisation>
|
||||
#<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.text = n.status()
|
||||
#</Result>
|
||||
|
Loading…
Reference in New Issue
Block a user