Finner ut av koder som mangler

This commit is contained in:
Trygve 2023-12-06 23:04:41 +01:00
parent 6f822c52eb
commit bbcc332166
2 changed files with 37 additions and 20 deletions

View File

@ -100,26 +100,30 @@ def run(port='/dev/ttyUSB0', project_dir='./', xml_path='./output/'):
csv_path = project_dir + '/runners.csv' csv_path = project_dir + '/runners.csv'
while True: while True:
if mtr.in_waiting > 0: if mtr.in_waiting > 0:
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF') block = mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
size = mtr.read(size=1) size = block[0]
if size == b'\xe6': if size == 230:
event = file_io.event_from_yaml_and_csv(config_path, mtr_path, csv_path) event = file_io.event_from_yaml_and_csv(config_path, mtr_path, csv_path)
meat = mtr.read(229) message = b'\xFF\xFF\xFF\xFF' + block[:230]
message = b'\xFF\xFF\xFF\xFF' + size + meat
card_dump = otime.CardDump.from_mtr_bytes(message)
event.card_dumps.append(card_dump)
file_io.write_card_dumps(event, mtr_path)
print(runner_info(event, card_dump))
subprocess.run(['git', 'add', './*'], cwd=project_dir, stdout=subprocess.DEVNULL)
subprocess.run(['git', 'commit', '-m', f'Added {card_dump.card}'], cwd=project_dir, stdout=subprocess.DEVNULL)
if not is_checksum_valid(message): if not is_checksum_valid(message):
print('[red]Checksum is not valid![red]') print('[red]Checksum is not valid![red]')
iof_xml.create_result_file(event, xml_path + '/results.xml') try:
pdf.create_result_list(event, project_dir + '/output/results.pdf') print(otime.CardDump.from_mtr_bytes(message))
print(runner_info(event, card_dump))
except ValueError as error:
print(error)
else:
card_dump = otime.CardDump.from_mtr_bytes(message)
event.card_dumps.append(card_dump)
file_io.write_card_dumps(event, mtr_path)
print(runner_info(event, card_dump))
subprocess.run(['git', 'add', './*'], cwd=project_dir, stdout=subprocess.DEVNULL)
subprocess.run(['git', 'commit', '-m', f'Added {card_dump.card}'], cwd=project_dir, stdout=subprocess.DEVNULL)
iof_xml.create_result_file(event, xml_path + '/results.xml')
pdf.create_result_list(event, project_dir + '/output/results.pdf')
elif size == b'\x37': elif size == 55:
meat = mtr.read(54) message = b'\xFF\xFF\xFF\xFF' + block[:55]
message = b'\xFF\xFF\xFF\xFF' + size + meat
mtr_id = int.from_bytes(message[6:8], 'little') mtr_id = int.from_bytes(message[6:8], 'little')
year = int.from_bytes(message[8:9], 'little') year = int.from_bytes(message[8:9], 'little')
@ -132,6 +136,9 @@ def run(port='/dev/ttyUSB0', project_dir='./', xml_path='./output/'):
battery_status = int.from_bytes(message[16:17], 'little') battery_status = int.from_bytes(message[16:17], 'little')
time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds) time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds)
print(f'MTR status message: id: {mtr_id}, time: {time}, battery: {battery_status}') print(f'MTR status message: id: {mtr_id}, time: {time}, battery: {battery_status}')
else:
print('Data not found!')
print(block)
def gen(project_dir='./', xml_path='./output/'): def gen(project_dir='./', xml_path='./output/'):
@ -155,7 +162,7 @@ def runner_info(event, card_dump):
if result.status == 'OK': if result.status == 'OK':
result_text = f'[green]Place: {result.place}. Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/green]' result_text = f'[green]Place: {result.place}. Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/green]'
elif result.status == 'MissingPunch': elif result.status == 'MissingPunch':
result_text = f'[red]Missed Control! Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/red]' result_text = f'[red]Missed control(s): {result.missed_controls}! Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/red]'
else: else:
result_text = f'[blue]{result.status}, Time: [bold][yellow]{result.total_time}[/yellow][/bold][/blue]' result_text = f'[blue]{result.status}, Time: [bold][yellow]{result.total_time}[/yellow][/bold][/blue]'
return result_text + f' [blue]{result.fullname()}[/blue], {result.o_class}, {result.club}, [italic]Card: {result.card_id}[/italic]' return result_text + f' [blue]{result.fullname()}[/blue], {result.o_class}, {result.club}, [italic]Card: {result.card_id}[/italic]'

View File

@ -181,7 +181,7 @@ class OClass:
class RunnerResult: class RunnerResult:
def __init__(self, runner_id: int, first: str, last: str, status: str, place: int, total_time: int, splits: 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=datetime.datetime(1973, 1, 1), fee_id=None): club=None, club_id=None, country=None, card_id=None, o_class=None, controls=None, fork=0, start_time=datetime.datetime(1973, 1, 1), fee_id=None, missed_controls=None, ran_other_course=None):
self.id = runner_id self.id = runner_id
self.first = first self.first = first
self.last = last self.last = last
@ -200,6 +200,10 @@ class RunnerResult:
self.total_time = total_time self.total_time = total_time
self.splits = splits self.splits = splits
self.end_time = end_time self.end_time = end_time
# List of controls missed
self.missed_controls = missed_controls
# If the runner ran other course it is named here
self.ran_other_course = ran_other_course
def fullname(self): def fullname(self):
return f'{self.first} {self.last}' return f'{self.first} {self.last}'
@ -398,7 +402,10 @@ def produce_class_result(event, o_class_name) -> ClassResult:
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), 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),
event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in ok_runners] event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in ok_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), 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, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id), start_time=event.get_card_dump(i.card_id).s_time) for i in dsq_runners] event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id),
start_time=event.get_card_dump(i.card_id).s_time,
missed_controls=find_missed_controls(event.get_runner_controls(i.id), event.get_course(o_class.course).codes[i.fork]))
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), 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, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in other_runners] event.get_runner_end_clock(i.id), i.club, 0, i.country, i.card_id, i.o_class, event.get_runner_controls(i.id)) for i in other_runners]
@ -451,4 +458,7 @@ def contains(small, big):
if valid: if valid:
return map_bl return map_bl
else: else:
return False return False
def find_missed_controls(punches, codes):
return [i for i in codes if i not in punches]