Compare commits
No commits in common. "275f4b0f78d9dfa1f867f85518ede598af5dc6e4" and "aa61d7a41563016c441576ecd17d7d96836c173c" have entirely different histories.
275f4b0f78
...
aa61d7a415
@ -5,10 +5,10 @@ import xml.etree.ElementTree as etree
|
||||
import pdf
|
||||
|
||||
class Runner:
|
||||
def __init__(self, id: int, first: str, last: str, club=None, club_id=None,
|
||||
def __init__(self, runner_id: int, first: str, last: str, club=None, club_id=None,
|
||||
country=None, card_id=None, o_class_str=None, o_class=None,
|
||||
fork=0, start_time=None, fee_id=None, fee=None):
|
||||
self.id = id
|
||||
self.id = runner_id
|
||||
self.first = first
|
||||
self.last = last
|
||||
self.club = club
|
||||
@ -19,7 +19,7 @@ class Runner:
|
||||
self.fork = fork
|
||||
self.start_time = start_time
|
||||
self.fee_id = fee_id
|
||||
self.status_override = ''
|
||||
|
||||
def __repr__(self):
|
||||
return(f'name({self.fullname()})')
|
||||
|
||||
@ -62,6 +62,25 @@ class Runner:
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
|
||||
def check_codes(self):
|
||||
return contains(self.res_codes(), self.card_r.controls)
|
||||
|
||||
def totaltime(self):
|
||||
f_control = self.res_codes()[-1]
|
||||
try:
|
||||
index = self.card_r.controls.index(f_control)
|
||||
return self.card_r.splits[index]
|
||||
except:
|
||||
return 0
|
||||
|
||||
def status(self):
|
||||
if hasattr(self, 'card_r') is False or self.o_class is None:
|
||||
return 'Active'
|
||||
elif self.check_codes():
|
||||
return 'OK'
|
||||
elif self.check_codes() is False:
|
||||
return 'Disqualified'
|
||||
|
||||
# TODO: må forbedres
|
||||
def rank(self, allrunners):
|
||||
c_ranked = rank_runners(allrunners, self.o_class)
|
||||
@ -267,6 +286,7 @@ class RunnerResult:
|
||||
self.first = first
|
||||
self.last = last
|
||||
self.club = club
|
||||
self.club_id = club_id
|
||||
self.country = country
|
||||
self.card_id = card_id
|
||||
self.o_class = o_class
|
||||
@ -324,51 +344,18 @@ class Event:
|
||||
self.fees.append(n)
|
||||
|
||||
def get_course(self, name):
|
||||
return next((copy.copy(i) for i in self.courses if i.name == name), None)
|
||||
pass
|
||||
|
||||
def get_o_class(self, name):
|
||||
return next((copy.copy(i) for i in self.o_classes if i.name == name), None)
|
||||
|
||||
def get_card_dump(self, id):
|
||||
return next((copy.copy(i) for i in self.card_dumps if i.card == id), None)
|
||||
|
||||
def get_runner(self, id):
|
||||
return next((copy.copy(i) for i in self.runners if i.id == id), None)
|
||||
|
||||
def get_runner_status(self, id):
|
||||
# https://github.com/international-orienteering-federation/datastandard-v3/blob/24eb108e4c6b5e2904e5f8f0e49142e45e2c5230/IOF.xsd#L2903C3-L2903C3
|
||||
runner = self.get_runner(id)
|
||||
if runner.status_override: return runner.status_override
|
||||
o_class = self.get_o_class(runner.o_class)
|
||||
course = self.get_course(o_class.course)
|
||||
if self.get_card_dump(runner.card_id) == None:
|
||||
return 'Active'
|
||||
if contains(course.codes, self.get_card_dump(runner.card_id).controls):
|
||||
return 'OK'
|
||||
else:
|
||||
return 'MissingPunch'
|
||||
|
||||
def get_runner_time(self, id):
|
||||
runner = self.get_runner(id)
|
||||
card_dump = self.get_card_dump(runner.card_id)
|
||||
f_control = card_dump.controls[-1]
|
||||
# TODO: Må gjøres mer robust
|
||||
try:
|
||||
index = card_dump.controls.index(f_control)
|
||||
return card_dump.splits[index]
|
||||
except:
|
||||
return False
|
||||
|
||||
def get_runner_splits(self, id):
|
||||
return self.get_card_dump(self.get_runner(id).card_id).splits
|
||||
|
||||
def get_runner_end_clock(self, id):
|
||||
return self.get_card_dump(self.get_runner(id).card_id).f_time
|
||||
def get_runner(self, name):
|
||||
pass
|
||||
|
||||
def get_result(self, o_classes: list[str] = []) -> list[ClassResult]:
|
||||
if not o_classes:
|
||||
o_classes = [i.name for i in self.o_classes]
|
||||
return [produce_class_result(copy.deepcopy(self), i) for i in o_classes]
|
||||
return [produce_class_result(self, i) for i in o_classes]
|
||||
|
||||
def read_xml_entries(self, xml_file):
|
||||
self.add_runners(*runners_from_xml_entries(xml_file))
|
||||
@ -506,6 +493,8 @@ class Event:
|
||||
ET.indent(root, space=' ', level=0)
|
||||
return tree
|
||||
|
||||
# The runner object stores all the data specific to a runner.
|
||||
|
||||
class Fee:
|
||||
def __init__(self, fee_id, name, currency, amount, from_birth_date=None,
|
||||
to_birth_date=None):
|
||||
@ -529,13 +518,8 @@ class Fee:
|
||||
def produce_class_result(event, o_class_name) -> ClassResult:
|
||||
o_class = event.get_o_class(o_class_name)
|
||||
runners = event.get_runners_in_o_class(o_class_name)
|
||||
ok_runners = [i for i in runners if event.get_runner_status(i.id) == 'OK']
|
||||
dsq_runners = [i for i in runners if event.get_runner_status(i.id) == 'MissingPunch' or event.get_runner_status(i.id) == 'Disqualified']
|
||||
other_runners = [i for i in runners if i not in ok_runners or i not in dsq_runners]
|
||||
results = [RunnerResult(i.id, i.first, i.last, 0, event.get_runner_time(i.id), event.get_runner_splits(i.id),
|
||||
event.get_runner_end_clock(i.id), i.club
|
||||
) for i in ok_runners]
|
||||
return results
|
||||
|
||||
|
||||
|
||||
# TODO: Take string instead of file.
|
||||
def courses_from_ttime_conf(ttime_file):
|
||||
|
@ -1 +0,0 @@
|
||||
fpdf2
|
@ -7,9 +7,7 @@ def main():
|
||||
event.read_ttime_cnf('tt.cnf')
|
||||
event.read_ttime_db('db.csv')
|
||||
event.read_mtr_file('mtr.csv')
|
||||
print(event.get_runner_status('28130'))
|
||||
print(event.get_result())
|
||||
event.create_start_list_pdf('output/result.pdf')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user