Compare commits

...

2 Commits

Author SHA1 Message Date
275f4b0f78 Fortsatte på produce_class_result funksjonen 2023-11-05 17:32:04 +01:00
145902624f La til requirements.txt 2023-11-05 17:30:55 +01:00
3 changed files with 50 additions and 31 deletions

View File

@ -5,10 +5,10 @@ import xml.etree.ElementTree as etree
import pdf import pdf
class Runner: class Runner:
def __init__(self, runner_id: int, first: str, last: str, club=None, club_id=None, def __init__(self, id: int, first: str, last: str, club=None, club_id=None,
country=None, card_id=None, o_class_str=None, o_class=None, country=None, card_id=None, o_class_str=None, o_class=None,
fork=0, start_time=None, fee_id=None, fee=None): fork=0, start_time=None, fee_id=None, fee=None):
self.id = runner_id self.id = id
self.first = first self.first = first
self.last = last self.last = last
self.club = club self.club = club
@ -19,7 +19,7 @@ class Runner:
self.fork = fork self.fork = fork
self.start_time = start_time self.start_time = start_time
self.fee_id = fee_id self.fee_id = fee_id
self.status_override = ''
def __repr__(self): def __repr__(self):
return(f'name({self.fullname()})') return(f'name({self.fullname()})')
@ -62,25 +62,6 @@ class Runner:
def fullname(self): def fullname(self):
return '{} {}'.format(self.first, self.last) 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 # TODO: må forbedres
def rank(self, allrunners): def rank(self, allrunners):
c_ranked = rank_runners(allrunners, self.o_class) c_ranked = rank_runners(allrunners, self.o_class)
@ -286,7 +267,6 @@ class RunnerResult:
self.first = first self.first = first
self.last = last self.last = last
self.club = club self.club = club
self.club_id = club_id
self.country = country self.country = country
self.card_id = card_id self.card_id = card_id
self.o_class = o_class self.o_class = o_class
@ -344,18 +324,51 @@ class Event:
self.fees.append(n) self.fees.append(n)
def get_course(self, name): def get_course(self, name):
pass return next((copy.copy(i) for i in self.courses if i.name == name), None)
def get_o_class(self, name): def get_o_class(self, name):
return next((copy.copy(i) for i in self.o_classes if i.name == name), None) return next((copy.copy(i) for i in self.o_classes if i.name == name), None)
def get_runner(self, name): def get_card_dump(self, id):
pass 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_result(self, o_classes: list[str] = []) -> list[ClassResult]: def get_result(self, o_classes: list[str] = []) -> list[ClassResult]:
if not o_classes: if not o_classes:
o_classes = [i.name for i in self.o_classes] o_classes = [i.name for i in self.o_classes]
return [produce_class_result(self, i) for i in o_classes] return [produce_class_result(copy.deepcopy(self), i) for i in o_classes]
def read_xml_entries(self, xml_file): def read_xml_entries(self, xml_file):
self.add_runners(*runners_from_xml_entries(xml_file)) self.add_runners(*runners_from_xml_entries(xml_file))
@ -493,8 +506,6 @@ class Event:
ET.indent(root, space=' ', level=0) ET.indent(root, space=' ', level=0)
return tree return tree
# The runner object stores all the data specific to a runner.
class Fee: class Fee:
def __init__(self, fee_id, name, currency, amount, from_birth_date=None, def __init__(self, fee_id, name, currency, amount, from_birth_date=None,
to_birth_date=None): to_birth_date=None):
@ -518,8 +529,13 @@ class Fee:
def produce_class_result(event, o_class_name) -> ClassResult: def produce_class_result(event, o_class_name) -> ClassResult:
o_class = event.get_o_class(o_class_name) o_class = event.get_o_class(o_class_name)
runners = event.get_runners_in_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. # TODO: Take string instead of file.
def courses_from_ttime_conf(ttime_file): def courses_from_ttime_conf(ttime_file):

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
fpdf2

View File

@ -7,7 +7,9 @@ def main():
event.read_ttime_cnf('tt.cnf') event.read_ttime_cnf('tt.cnf')
event.read_ttime_db('db.csv') event.read_ttime_db('db.csv')
event.read_mtr_file('mtr.csv') event.read_mtr_file('mtr.csv')
print(event.get_runner_status('28130'))
print(event.get_result()) print(event.get_result())
event.create_start_list_pdf('output/result.pdf') event.create_start_list_pdf('output/result.pdf')
if __name__ == '__main__': if __name__ == '__main__':
main() main()