otime/event_mgr.py

69 lines
2.1 KiB
Python

#!/usr/bin/env python
import otime
import datetime
import os
from time import sleep
import serial
import argparse
import json
import cli
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
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"))
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)
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
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())
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
if __name__ == "__main__":
main()