Compare commits
2 Commits
6f822c52eb
...
71020bc340
Author | SHA1 | Date | |
---|---|---|---|
71020bc340 | |||
bbcc332166 |
43
otime/cli.py
43
otime/cli.py
@ -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 Exception 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/'):
|
||||||
@ -148,14 +155,14 @@ def gen(project_dir='./', xml_path='./output/'):
|
|||||||
def runner_info(event, card_dump):
|
def runner_info(event, card_dump):
|
||||||
runner = next((i for i in event.runners if str(i.card_id) == str(card_dump.card)), None)
|
runner = next((i for i in event.runners if str(i.card_id) == str(card_dump.card)), None)
|
||||||
if runner is None:
|
if runner is None:
|
||||||
return card_dump
|
return f'[orange_red1]No runner with ecard {card_dump.card}! It matches these courses: {otime.find_courses_matching_controls(card_dump.controls, event.courses)}[/orange_red1] {card_dump}'
|
||||||
result = event.get_runner_result(runner.id)
|
result = event.get_runner_result(runner.id)
|
||||||
if result is None:
|
if result is None:
|
||||||
return '🧐 Dette skal ikke skje...'
|
return '🧐 Dette skal ikke skje...'
|
||||||
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]'
|
||||||
|
@ -46,6 +46,9 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
|
|||||||
i[7] = i[7]
|
i[7] = i[7]
|
||||||
else:
|
else:
|
||||||
i[7] = None
|
i[7] = None
|
||||||
|
# Sjekk om brikkenummer er tomt
|
||||||
|
if i[5] == '':
|
||||||
|
i[5] = 0
|
||||||
runners = [otime.Runner(id=i[0], status_override=i[1], first=i[2][0], last=i[2][1].strip(), o_class=i[3], club=i[4], card_id=int(i[5]), fork=int(i[6]), start_time=i[7]) for i in data]
|
runners = [otime.Runner(id=i[0], status_override=i[1], first=i[2][0], last=i[2][1].strip(), o_class=i[3], club=i[4], card_id=int(i[5]), fork=int(i[6]), start_time=i[7]) for i in data]
|
||||||
event.card_dumps = card_dumps
|
event.card_dumps = card_dumps
|
||||||
event.runners = runners
|
event.runners = runners
|
||||||
|
@ -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,11 @@ 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]),
|
||||||
|
ran_other_course=find_courses_matching_controls(event.get_card_dump(i.card_id).controls, event.courses))
|
||||||
|
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 +459,15 @@ 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]
|
||||||
|
|
||||||
|
def find_courses_matching_controls(controls, courses):
|
||||||
|
matches = []
|
||||||
|
for i in courses:
|
||||||
|
for fork in i.codes:
|
||||||
|
if contains(fork, controls):
|
||||||
|
matches.append(i.name)
|
||||||
|
return matches
|
Loading…
Reference in New Issue
Block a user