Bytta tilbake til to lister for strekktider istedet for dictionary

This commit is contained in:
Trygve 2022-03-10 18:18:59 +01:00
parent 0160ffaec8
commit b5160008d7
2 changed files with 30 additions and 21 deletions

7
cli.py
View File

@ -83,15 +83,14 @@ def print_class_splits(runners, o_class):
runners_ok.sort(key=lambda x: x.totaltime()) runners_ok.sort(key=lambda x: x.totaltime())
pos = 0 pos = 0
for i in runners_ok: for i in runners_ok:
splits = i.res_splits().values() splits = i.res_splits()
pos += 1 pos += 1
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits) list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string) table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string)
for i in runners_dsq: 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) list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
table.add_row('Dsq', i.fullname(), i.club, *list_string) table.add_row('Dsq', i.fullname(), i.club, *list_string)
console = Console() console = Console()
console.print(table) console.print(table)
def print_o_classes(class_list): def print_o_classes(class_list):
@ -101,7 +100,7 @@ def print_o_classes(class_list):
table.add_column("Controls", justify="right", style="green") table.add_column("Controls", justify="right", style="green")
for i in class_list: for i in class_list:
table.add_row(i.name, i.course.name , str(i.course.codes)) table.add_row(i.name, i.course.name , str(i.course.codes))
console = Console() console = Console()
console.print(table) console.print(table)

View File

@ -85,7 +85,7 @@ class event:
#</Organisation> #</Organisation>
#<Result> #<Result>
result = ET.SubElement(person_result, '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, 'StartTime', n.card_r.s_time.isoformat())
xml_child(result, 'FinishTime', n.card_r.f_time.isoformat()) xml_child(result, 'FinishTime', n.card_r.f_time.isoformat())
xml_child(result, 'Time', n.totaltime()) xml_child(result, 'Time', n.totaltime())
@ -96,7 +96,7 @@ class event:
xml_child(result, 'Position', n.rank(self.runners)) xml_child(result, 'Position', n.rank(self.runners))
xml_child(result, 'Status', n.status()) xml_child(result, 'Status', n.status())
#<SplitTime> #<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') st = ET.SubElement(result, 'SplitTime')
xml_child(st, 'ControlCode', code) xml_child(st, 'ControlCode', code)
xml_child(st, 'Time', split) xml_child(st, 'Time', split)
@ -106,7 +106,7 @@ class event:
for code in n.o_class.course.codes: for code in n.o_class.course.codes:
st = ET.SubElement(result, 'SplitTime') st = ET.SubElement(result, 'SplitTime')
xml_child(st, 'ControlCode', code) 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: if code == control:
xml_child(st, 'Time', split) xml_child(st, 'Time', split)
else: else:
@ -132,13 +132,14 @@ class runner:
return '{} {}'.format(self.first, self.last) return '{} {}'.format(self.first, self.last)
def check_codes(self): def check_codes(self):
# Returns False if not ok and touple if ok # 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): def totaltime(self):
f_control = self.o_class.course.codes[-1] f_control = self.o_class.course.codes[-1]
try: try:
return self.card_r.punches[f_control] index = self.card_r.controls.index(f_control)
return self.card_r.splits[index]
except: except:
return list(self.card_r.punches.values())[-1] return self.card_r.splits[-1]
def status(self): def status(self):
if hasattr(self, 'card_r') == False: if hasattr(self, 'card_r') == False:
@ -151,17 +152,19 @@ 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):
punches = self.card_r.punches splits_cpy = self.card_r.splits.copy()
punches_ret = punches.copy() for control in self.card_r.controls:
for key in punches.keys(): if control not in self.o_class.course.codes:
if key not in self.o_class.course.codes: index = self.card_r.controls.index(control)
punches_ret.pop(key) split = self.card_r.splits[index]
return punches_ret splits_cpy.remove(split)
return splits_cpy
class card_punch: 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.card = card
self.punches = punches self.controls = controls
self.splits = splits
self.s_time = s_time self.s_time = s_time
self.f_time = f_time self.f_time = f_time
def __repr__(self): def __repr__(self):
@ -184,11 +187,18 @@ class card_punch:
splits = [] splits = []
# postkodene kommer på oddetall fra og med den 11. De blir hevet inn i controls # postkodene kommer på oddetall fra og med den 11. De blir hevet inn i controls
for item in row[11::2]: 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)) controls.append(int(item))
# strekktidene kommer på partall fra og med den 12. De blir hevet i splits. # strekktidene kommer på partall fra og med den 12. De blir hevet i splits.
for item in row[12::2]: for item in row[12::2]:
if item != '000' and item != '0000' and item != '00000': if item == '00000':
break
else:
splits.append(int(item)) splits.append(int(item))
# looper gjonnom løperobjektene og legger til poster og strekktider + start og sluttid # looper gjonnom løperobjektene og legger til poster og strekktider + start og sluttid
# usikker på om dette er riktig klokeslett # usikker på om dette er riktig klokeslett
@ -204,7 +214,7 @@ class card_punch:
s_time = f_time - datetime.timedelta(seconds = splits[-2]) s_time = f_time - datetime.timedelta(seconds = splits[-2])
else: else:
s_time = f_time 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 return cards
class course: class course:
def __init__(self, name, codes): def __init__(self, name, codes):