From caca1fac990e16ebff993fc12b0de046246b546b Mon Sep 17 00:00:00 2001 From: Trygve Date: Mon, 30 May 2022 16:25:49 +0200 Subject: [PATCH] =?UTF-8?q?La=20til=20st=C3=B8tte=20for=20gaffla=20l=C3=B8?= =?UTF-8?q?yper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime.py | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/otime.py b/otime.py index 86fc326..f34fe99 100644 --- a/otime.py +++ b/otime.py @@ -1,3 +1,4 @@ +from copy import copy import datetime import csv import re @@ -112,6 +113,8 @@ class Event: runners_ranked.extend(runners_sorted) for n in runners_ranked: + if n.status() == 'Active': + continue person_result = ET.SubElement(class_result, 'PersonResult') # person = ET.SubElement(person_result, 'Person') @@ -149,17 +152,23 @@ class Event: st = ET.SubElement(result, 'SplitTime') xml_child(st, 'ControlCode', code) xml_child(st, 'Time', split) - if code == n.o_class.course.codes[-1]: + if code == n.res_codes()[-1]: break # elif n.status() == 'Disqualified': xml_child(result, 'Status', n.status()) - for code in n.o_class.course.codes: + + controls = copy(n.card_r.controls) + splits = copy(n.card_r.splits) + for code in n.res_codes(): st = ET.SubElement(result, 'SplitTime') xml_child(st, 'ControlCode', code) - for control, split in zip(n.card_r.controls, n.card_r.splits): + for control, split in zip(controls, splits): if code == control: xml_child(st, 'Time', split) + controls.remove(control) + splits.remove(split) + break else: xml_child(result, 'Status', n.status()) else: @@ -206,7 +215,7 @@ class Event: courses = [] for c in data['courses']: - courses.append(Course(c['name'], c['codes'])) + courses.append(Course(c['name'], c['codes'], forked=c['forked'], variations=c['variations'])) o_classes = [] for c in data['o_classes']: @@ -335,11 +344,10 @@ 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.controls)) + return contains(self.res_codes(), self.card_r.controls) def totaltime(self): - f_control = self.o_class.course.codes[-1] + f_control = self.res_codes()[-1] try: index = self.card_r.controls.index(f_control) return self.card_r.splits[index] @@ -358,15 +366,24 @@ class Runner: c_ranked = rank_runners(allrunners, self.o_class) return c_ranked.index(self) + 1 + def res_codes(self): + if self.o_class.course.forked == False: + return self.o_class.course.codes + else: + return self.o_class.course.variations[self.fork] + + # Used for making result files and tables def res_splits(self): + splits_cpy = self.card_r.splits.copy() for control in self.card_r.controls: - if control not in self.o_class.course.codes: + if control not in self.res_codes(): index = self.card_r.controls.index(control) split = self.card_r.splits[index] splits_cpy.remove(split) return splits_cpy # list + def asdict(self): return { 'id': self.id, @@ -494,14 +511,14 @@ class Course: self.codes = codes try: - forked = kwargs['forked'] + self.forked = kwargs['forked'] except KeyError: - forked = False + self.forked = False try: - variations = kwargs['variations'] + self.variations = kwargs['variations'] except KeyError: - variations = None + self.variations = None def __repr__(self): return f'name({self.name})' @@ -509,7 +526,9 @@ class Course: def asdict(self): return { 'name': self.name, - 'codes': self.codes + 'codes': self.codes, + 'forked': self.forked, + 'variations': self.variations } # Stored in Event.o_classes