diff --git a/otime/otime.py b/otime/otime.py index a1d7823..33a1e13 100644 --- a/otime/otime.py +++ b/otime/otime.py @@ -259,7 +259,7 @@ class OClass: return f'name({self.name})' 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, splits: list[int], end_time, 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.first = first @@ -276,7 +276,7 @@ class RunnerResult: self.status = status self.place = place self.total_time = total_time - self.split_times = split_times + self.splits = splits self.end_time = end_time def fullname(self): @@ -366,10 +366,33 @@ class Event: def get_runner_splits(self, id): try: - return self.get_card_dump(self.get_runner(id).card_id).splits + runner = self.get_runner(id) + card_dump = self.get_card_dump(runner.card_id) + course = self.get_course(self.get_o_class(runner.o_class).course) except AttributeError: return None - + + if card_dump == None: + return None + + split_iter = zip(card_dump.controls, card_dump.splits).__iter__() + splits = [0] * len(course.codes) + for n, control in enumerate(course.codes): + if control not in card_dump.controls: + continue + split_debt = 0 + while True: + try: + punched_control, split = next(split_iter) + except StopIteration: + break + if punched_control == control: + splits[n] = split + split_debt + break + else: + split_debt += split + return splits + def get_runner_controls(self, id): try: return self.get_card_dump(self.get_runner(id).card_id).controls @@ -712,4 +735,4 @@ def rank_runners(allrunners, o_class): # Used to make creating xml files easier def xml_child(parent, tag, content): e = ET.SubElement(parent, tag) - e.text = str(content) + e.text = str(content) \ No newline at end of file diff --git a/otime/pdf.py b/otime/pdf.py index b4c0bdb..6bec629 100644 --- a/otime/pdf.py +++ b/otime/pdf.py @@ -1,6 +1,11 @@ import datetime from fpdf import FPDF +def format_m_s(seconds): + if seconds == 0: return '' + minutes, seconds = divmod(seconds, 60) + return f'{minutes:02}:{seconds:02}' + def create_result_list(event, file_path, o_classes=[]): results = event.get_result(o_classes) @@ -22,12 +27,41 @@ def create_result_list(event, file_path, o_classes=[]): pdf.multi_cell(col_width, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L') pdf.multi_cell(col_width, line_height, runner.club, border=1, ln=3, max_line_height=pdf.font_size) if runner.status == 'OK': - pdf.multi_cell(col_width, line_height, str(datetime.timedelta(seconds = runner.total_time)), border=1, ln=3, max_line_height=pdf.font_size) + pdf.multi_cell(col_width, line_height, format_m_s(runner.total_time), border=1, ln=3, max_line_height=pdf.font_size) else: pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size) pdf.ln(line_height) pdf.output(file_path) +def create_split_result_list(event, file_path, o_classes=[]): + results = event.get_result(o_classes) + + pdf = FPDF() + pdf.add_page(orientation='L') + pdf.add_font("LiberationSans", fname="../../otime/data/fonts/LiberationSans-Regular.ttf") + pdf.set_font("LiberationSans", size=8) + line_height = pdf.font_size * 1.5 + col_width = pdf.epw / 4 # distribute content evenly + + for class_result in results: + col_width = pdf.epw / (21+len(class_result.course)) + pdf.write(txt=class_result.name) + pdf.ln(line_height) + for runner in class_result.runner_results: + if runner.status == 'OK': + pdf.multi_cell(5, line_height, str(runner.place), border=1, ln=3, max_line_height=pdf.font_size, align='L') + else: + pdf.multi_cell(5, line_height, runner.status, border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(30, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(30, line_height, runner.club, border=1, ln=3, max_line_height=pdf.font_size) + if runner.status == 'OK' or runner.status == 'MissingPunch': + for split in runner.splits: + pdf.multi_cell(col_width, line_height, format_m_s(split), border=1, ln=3, max_line_height=pdf.font_size) + else: + pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size) + pdf.ln(line_height) + pdf.output(file_path) + def create_all_invoices(self, filename_prefix): clubs = [x.club for x in self.runners if x.club != self.runners[self.runners.index(x)-1].club and x.club is not None] for club in clubs: diff --git a/test_files/sc3_23/lenker.txt b/test_files/sc3_23/lenker.txt index e69de29..360dc56 100644 --- a/test_files/sc3_23/lenker.txt +++ b/test_files/sc3_23/lenker.txt @@ -0,0 +1 @@ +https://eventor.orientering.no/Events/Show/18618 \ No newline at end of file diff --git a/test_files/sc3_23/sc3_test.py b/test_files/sc3_23/sc3_test.py index 4dd93eb..6bcd60f 100644 --- a/test_files/sc3_23/sc3_test.py +++ b/test_files/sc3_23/sc3_test.py @@ -8,7 +8,7 @@ def main(): event.read_ttime_cnf('tt.cnf') event.read_ttime_db('db.csv') event.read_mtr_file('mtr.csv') - pdf.create_result_list(event, 'output/result.pdf') + pdf.create_split_result_list(event, 'output/result.pdf') print(event.get_runner_status('1400')) results = event.get_result()