otime/event_mgr.py

69 lines
2.1 KiB
Python
Raw Normal View History

2022-03-13 20:19:07 +00:00
#!/usr/bin/env python
2022-03-11 14:33:09 +00:00
import otime
import datetime
import os
from time import sleep
import serial
2022-03-23 16:54:48 +00:00
import argparse
import json
import cli
2022-03-11 14:33:09 +00:00
from rich import print
from rich import inspect
from rich.console import Console
from rich.columns import Columns
from rich.table import Table
from rich.panel import Panel
from rich.console import Group
2022-03-11 14:33:09 +00:00
2022-05-11 13:07:33 +00:00
2022-03-23 16:54:48 +00:00
def run_otime():
event = otime.Event.from_toml(open("/home/trygve/Prosjekter/otime-testing/sc3/sc3.toml", "rb"))
event.import_ttime_db(open("/home/trygve/Prosjekter/otime-testing/sc3/db.csv"))
2022-03-23 16:54:48 +00:00
data = (open("/home/trygve/Prosjekter/otime-testing/sc3/mtr.json")).readlines()
for l in data:
d = json.loads(l)
#print(l)
event.card_dumps.append(otime.CardDump(d['card'], d['controls'], d['splits'],
datetime.datetime.fromisoformat(d['read_time']),
datetime.datetime.fromisoformat(d['s_time']),
datetime.datetime.fromisoformat(d['f_time'])))
print('Ecards:'+str(len(event.card_dumps)))
print('Løpere:'+str(len(event.runners)))
event.match_all()
#cli.print_runners(event.runners)
for n in event.o_classes:
cli.print_class_result(event.runners, n)
2022-05-11 13:07:33 +00:00
def read_mtr(mtr):
global event
if mtr.in_waiting > 0:
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
size = mtr.read(size=1)
if size == b'\xe6':
meat = mtr.read(229)
full = b'\xFF\xFF\xFF\xFF' + size + meat
2022-05-11 13:07:33 +00:00
card_r = otime.CardDump.from_mtr_bytes(full)
print(json.dumps(card_r.asdict()))
with open("sc3/mtr.json", "a") as myfile:
myfile.write('\n' + json.dumps(card_r.asdict()))
run_otime()
elif size == b'\x37':
meat = mtr.read(55)
status = mtrreader.MtrStatusMessage(meat)
inspect(status)
print(status.year(),status.month(),status.day(),status.hours(),status.minutes())
2022-05-11 13:07:33 +00:00
def main():
mtr = serial.Serial(port="/dev/pts/2", baudrate=9600, timeout=40)
# mtr.write(b'/SA')
while True:
read_mtr(mtr)
sleep(0.1)
db_file_u = None
2022-03-11 14:33:09 +00:00
if __name__ == "__main__":
main()