forked from Trygve/otime
Bytta tilbake til to lister for strekktider istedet for dictionary
This commit is contained in:
parent
0160ffaec8
commit
b5160008d7
5
cli.py
5
cli.py
@ -83,15 +83,14 @@ def print_class_splits(runners, o_class):
|
||||
runners_ok.sort(key=lambda x: x.totaltime())
|
||||
pos = 0
|
||||
for i in runners_ok:
|
||||
splits = i.res_splits().values()
|
||||
splits = i.res_splits()
|
||||
pos += 1
|
||||
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
|
||||
table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string)
|
||||
for i in runners_dsq:
|
||||
splits = i.res_splits().values()
|
||||
splits = i.res_splits()
|
||||
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
|
||||
table.add_row('Dsq', i.fullname(), i.club, *list_string)
|
||||
|
||||
console = Console()
|
||||
console.print(table)
|
||||
def print_o_classes(class_list):
|
||||
|
44
otime.py
44
otime.py
@ -85,7 +85,7 @@ class event:
|
||||
#</Organisation>
|
||||
#<Result>
|
||||
result = ET.SubElement(person_result, 'Result')
|
||||
if hasattr(n,'card_r') and len(n.card_r.punches) > 2:
|
||||
if hasattr(n,'card_r') and len(n.card_r.splits) > 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())
|
||||
@ -96,7 +96,7 @@ class event:
|
||||
xml_child(result, 'Position', n.rank(self.runners))
|
||||
xml_child(result, 'Status', n.status())
|
||||
#<SplitTime>
|
||||
for code,split in n.res_splits().items():
|
||||
for code,split in zip(n.card_r.controls,n.card_r.splits):
|
||||
st = ET.SubElement(result, 'SplitTime')
|
||||
xml_child(st, 'ControlCode', code)
|
||||
xml_child(st, 'Time', split)
|
||||
@ -106,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 n.card_r.punches.items():
|
||||
for control,split in zip(n.card_r.controls,n.card_r.splits):
|
||||
if code == control:
|
||||
xml_child(st, 'Time', split)
|
||||
else:
|
||||
@ -132,13 +132,14 @@ class runner:
|
||||
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, list(self.card_r.punches.keys()))
|
||||
return contains(self.o_class.course.codes, list(self.card_r.controls))
|
||||
def totaltime(self):
|
||||
f_control = self.o_class.course.codes[-1]
|
||||
try:
|
||||
return self.card_r.punches[f_control]
|
||||
index = self.card_r.controls.index(f_control)
|
||||
return self.card_r.splits[index]
|
||||
except:
|
||||
return list(self.card_r.punches.values())[-1]
|
||||
return self.card_r.splits[-1]
|
||||
|
||||
def status(self):
|
||||
if hasattr(self, 'card_r') == False:
|
||||
@ -151,17 +152,19 @@ class runner:
|
||||
c_ranked = rank_runners(allrunners, self.o_class)
|
||||
return c_ranked.index(self) + 1
|
||||
def res_splits(self):
|
||||
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
|
||||
splits_cpy = self.card_r.splits.copy()
|
||||
for control in self.card_r.controls:
|
||||
if control not in self.o_class.course.codes:
|
||||
index = self.card_r.controls.index(control)
|
||||
split = self.card_r.splits[index]
|
||||
splits_cpy.remove(split)
|
||||
return splits_cpy
|
||||
|
||||
class card_punch:
|
||||
def __init__(self, card, punches, s_time, f_time):
|
||||
def __init__(self, card, controls, splits, s_time, f_time):
|
||||
self.card = card
|
||||
self.punches = punches
|
||||
self.controls = controls
|
||||
self.splits = splits
|
||||
self.s_time = s_time
|
||||
self.f_time = f_time
|
||||
def __repr__(self):
|
||||
@ -184,11 +187,18 @@ class card_punch:
|
||||
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':
|
||||
if item == '250':
|
||||
controls.append(int(item))
|
||||
break
|
||||
elif item == '000':
|
||||
break
|
||||
else:
|
||||
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':
|
||||
if item == '00000':
|
||||
break
|
||||
else:
|
||||
splits.append(int(item))
|
||||
# looper gjonnom løperobjektene og legger til poster og strekktider + start og sluttid
|
||||
# usikker på om dette er riktig klokeslett
|
||||
@ -204,7 +214,7 @@ class card_punch:
|
||||
s_time = f_time - datetime.timedelta(seconds = splits[-2])
|
||||
else:
|
||||
s_time = f_time
|
||||
cards.append(card_punch(int(row[6]), dict(zip(controls, splits)), s_time, f_time))
|
||||
cards.append(card_punch(int(row[6]), controls, splits, s_time, f_time))
|
||||
return cards
|
||||
class course:
|
||||
def __init__(self, name, codes):
|
||||
|
Loading…
Reference in New Issue
Block a user