Compare commits
No commits in common. "71020bc340cfe8ce5361e1f4128d475b8cb77a72" and "6f822c52ebb8f29692d2d02a22912150ce4331ec" have entirely different histories.
71020bc340
...
6f822c52eb
43
otime/cli.py
43
otime/cli.py
@ -100,30 +100,26 @@ def run(port='/dev/ttyUSB0', project_dir='./', xml_path='./output/'):
|
||||
csv_path = project_dir + '/runners.csv'
|
||||
while True:
|
||||
if mtr.in_waiting > 0:
|
||||
block = mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
||||
size = block[0]
|
||||
if size == 230:
|
||||
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
||||
size = mtr.read(size=1)
|
||||
if size == b'\xe6':
|
||||
event = file_io.event_from_yaml_and_csv(config_path, mtr_path, csv_path)
|
||||
message = b'\xFF\xFF\xFF\xFF' + block[:230]
|
||||
meat = mtr.read(229)
|
||||
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):
|
||||
print('[red]Checksum is not valid![red]')
|
||||
try:
|
||||
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')
|
||||
iof_xml.create_result_file(event, xml_path + '/results.xml')
|
||||
pdf.create_result_list(event, project_dir + '/output/results.pdf')
|
||||
|
||||
elif size == 55:
|
||||
message = b'\xFF\xFF\xFF\xFF' + block[:55]
|
||||
elif size == b'\x37':
|
||||
meat = mtr.read(54)
|
||||
message = b'\xFF\xFF\xFF\xFF' + size + meat
|
||||
|
||||
mtr_id = int.from_bytes(message[6:8], 'little')
|
||||
year = int.from_bytes(message[8:9], 'little')
|
||||
@ -136,9 +132,6 @@ def run(port='/dev/ttyUSB0', project_dir='./', xml_path='./output/'):
|
||||
battery_status = int.from_bytes(message[16:17], 'little')
|
||||
time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds)
|
||||
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/'):
|
||||
@ -155,14 +148,14 @@ def gen(project_dir='./', xml_path='./output/'):
|
||||
def runner_info(event, card_dump):
|
||||
runner = next((i for i in event.runners if str(i.card_id) == str(card_dump.card)), None)
|
||||
if runner is None:
|
||||
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}'
|
||||
return card_dump
|
||||
result = event.get_runner_result(runner.id)
|
||||
if result is None:
|
||||
return '🧐 Dette skal ikke skje...'
|
||||
if result.status == 'OK':
|
||||
result_text = f'[green]Place: {result.place}. Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/green]'
|
||||
elif result.status == 'MissingPunch':
|
||||
result_text = f'[red]Missed control(s): {result.missed_controls}! Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/red]'
|
||||
result_text = f'[red]Missed Control! Time: [bold][yellow]{format_m_s(result.total_time)}[/yellow][/bold][/red]'
|
||||
else:
|
||||
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]'
|
||||
|
@ -46,9 +46,6 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
|
||||
i[7] = i[7]
|
||||
else:
|
||||
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]
|
||||
event.card_dumps = card_dumps
|
||||
event.runners = runners
|
||||
|
@ -181,7 +181,7 @@ class OClass:
|
||||
|
||||
class RunnerResult:
|
||||
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, missed_controls=None, ran_other_course=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):
|
||||
self.id = runner_id
|
||||
self.first = first
|
||||
self.last = last
|
||||
@ -200,10 +200,6 @@ class RunnerResult:
|
||||
self.total_time = total_time
|
||||
self.splits = splits
|
||||
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):
|
||||
return f'{self.first} {self.last}'
|
||||
@ -402,11 +398,7 @@ 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),
|
||||
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),
|
||||
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]
|
||||
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]
|
||||
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]
|
||||
|
||||
@ -459,15 +451,4 @@ def contains(small, big):
|
||||
if valid:
|
||||
return map_bl
|
||||
else:
|
||||
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
|
||||
return False
|
Loading…
Reference in New Issue
Block a user