Fiksa pdf resultatliste

This commit is contained in:
Trygve 2023-11-06 15:15:04 +01:00
parent 275f4b0f78
commit 8621e07dcf
3 changed files with 40 additions and 16 deletions

View File

@ -127,8 +127,6 @@ class Runner:
'fee_id': self.fee_id 'fee_id': self.fee_id
} }
class CardDump: class CardDump:
def __init__(self, card, controls, splits, read_time, s_time, f_time): def __init__(self, card, controls, splits, read_time, s_time, f_time):
self.card = card self.card = card
@ -262,7 +260,7 @@ class OClass:
class RunnerResult: class RunnerResult:
def __init__(self, runner_id: int, first: str, last: str, status: str, place: int, total_time: int, split_times: list[int], end_time, def __init__(self, runner_id: int, first: str, last: str, status: str, place: int, total_time: int, split_times: list[int], end_time,
club=None, club_id=None, country=None, card_id=None, o_class=None, fork=0, start_time=None, fee_id=None): club=None, club_id=None, country=None, card_id=None, o_class=None, controls=None, fork=0, start_time=None, fee_id=None):
self.id = runner_id self.id = runner_id
self.first = first self.first = first
self.last = last self.last = last
@ -270,6 +268,7 @@ class RunnerResult:
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
self.controls = controls
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
@ -279,12 +278,15 @@ class RunnerResult:
self.total_time = total_time self.total_time = total_time
self.split_times = split_times self.split_times = split_times
self.end_time = end_time self.end_time = end_time
def fullname(self):
return f'{self.first} {self.last}'
class ClassResult: class ClassResult:
def __init__(self, name: str, course: Course, runner_results: list[RunnerResult]): def __init__(self, name: str, course: Course, runner_results: list[RunnerResult]):
self.name self.name = name
self.course self.course = course
self.runner_results self.runner_results = runner_results
class Event: class Event:
def __init__(self, eventid, name, start_time=None, end_time=None, def __init__(self, eventid, name, start_time=None, end_time=None,
@ -351,6 +353,9 @@ class Event:
def get_runner_time(self, id): def get_runner_time(self, id):
runner = self.get_runner(id) runner = self.get_runner(id)
card_dump = self.get_card_dump(runner.card_id) card_dump = self.get_card_dump(runner.card_id)
if card_dump == None:
return False
f_control = card_dump.controls[-1] f_control = card_dump.controls[-1]
# TODO: Må gjøres mer robust # TODO: Må gjøres mer robust
try: try:
@ -360,10 +365,22 @@ class Event:
return False return False
def get_runner_splits(self, id): def get_runner_splits(self, id):
return self.get_card_dump(self.get_runner(id).card_id).splits try:
return self.get_card_dump(self.get_runner(id).card_id).splits
except AttributeError:
return None
def get_runner_controls(self, id):
try:
return self.get_card_dump(self.get_runner(id).card_id).controls
except AttributeError:
return None
def get_runner_end_clock(self, id): def get_runner_end_clock(self, id):
return self.get_card_dump(self.get_runner(id).card_id).f_time try:
return self.get_card_dump(self.get_runner(id).card_id).f_time
except AttributeError:
return None
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:
@ -530,12 +547,18 @@ 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'] ok_runners = [i for i in runners if event.get_runner_status(i.id) == 'OK']
ok_runners.sort(key=lambda i: event.get_runner_time(i.id))
dsq_runners = [i for i in runners if event.get_runner_status(i.id) == 'MissingPunch' or event.get_runner_status(i.id) == 'Disqualified'] 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] other_runners = [i for i in runners if i not in ok_runners and 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 results = [RunnerResult(i.id, i.first, i.last, event.get_runner_status(i.id), ok_runners.index(i)+1, event.get_runner_time(i.id), event.get_runner_splits(i.id),
) for i in ok_runners] event.get_runner_end_clock(i.id), i.club, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in ok_runners]
return results results += [RunnerResult(i.id, i.first, i.last, event.get_runner_status(i.id), 0, event.get_runner_time(i.id), event.get_runner_splits(i.id),
event.get_runner_end_clock(i.id), i.club, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in dsq_runners]
results += [RunnerResult(i.id, i.first, i.last, event.get_runner_status(i.id), 0, event.get_runner_time(i.id), event.get_runner_splits(i.id),
event.get_runner_end_clock(i.id), i.club, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in other_runners]
return ClassResult(o_class.name, o_class.course, 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):

View File

View File

@ -1,15 +1,16 @@
import sys import sys
sys.path.insert(0, '../../otime') sys.path.insert(0, '../../otime')
import otime import otime
import pdf
def main(): def main():
event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe') event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe')
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')) pdf.create_result_list(event, 'output/result.pdf')
print(event.get_result()) print(event.get_runner_status('1400'))
event.create_start_list_pdf('output/result.pdf') results = event.get_result()
if __name__ == '__main__': if __name__ == '__main__':
main() main()