Compare commits
No commits in common. "8e5c5351ba6ca919f920f6939d3354983aee33c9" and "4951861751c381515ab7900bd04043ff3c26c58e" have entirely different histories.
8e5c5351ba
...
4951861751
57
event_mgr.py
57
event_mgr.py
@ -1,21 +1,18 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import otime
|
import otime
|
||||||
import datetime
|
#import mtr_log_extractor as mle
|
||||||
import serial
|
import json
|
||||||
import binascii
|
|
||||||
import pickle
|
import pickle
|
||||||
import asyncio
|
import asyncio
|
||||||
import argparse
|
import argparse
|
||||||
from difflib import Differ
|
from difflib import Differ
|
||||||
from watchfiles import awatch
|
from watchgod import awatch
|
||||||
from config import config
|
from config import config
|
||||||
from rich import print
|
from rich import print
|
||||||
from rich import inspect
|
from rich import inspect
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.columns import Columns
|
from rich.columns import Columns
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.panel import Panel
|
|
||||||
from rich.console import Group
|
|
||||||
|
|
||||||
def save(obj):
|
def save(obj):
|
||||||
f = open(config['otime_file'], "wb")
|
f = open(config['otime_file'], "wb")
|
||||||
@ -38,8 +35,10 @@ def start_parse():
|
|||||||
def start_event():
|
def start_event():
|
||||||
global event
|
global event
|
||||||
event = otime.event(0, config['event_name'])
|
event = otime.event(0, config['event_name'])
|
||||||
event.import_ttime_cnf(config['cnf_file'])
|
event.import_ttime_cnf('/home/trygve/Documents/sprintcup040330/sprintcup040330.cnf')
|
||||||
event.import_ttime_db(config['db_file'])
|
event.import_ttime_db(config['db_file'])
|
||||||
|
event.import_mtr_file('/home/trygve/Documents/sprintcup040330/sprintcup040330.log')
|
||||||
|
event.match_runners_cards()
|
||||||
save(event)
|
save(event)
|
||||||
global db_file
|
global db_file
|
||||||
global db_file_u
|
global db_file_u
|
||||||
@ -53,47 +52,8 @@ def load_event(ot_file):
|
|||||||
global db_file_u
|
global db_file_u
|
||||||
db_file = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
db_file = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
||||||
|
|
||||||
def assign_card_r_to_runner(runners, card_r):
|
|
||||||
for n in runners:
|
|
||||||
if n.card == card_r.card:
|
|
||||||
n.card_r = card_r
|
|
||||||
print(runner_info(n))
|
|
||||||
|
|
||||||
def runner_info(runner):
|
|
||||||
time = str(datetime.timedelta(seconds=runner.totaltime()))
|
|
||||||
if runner.status() == 'Disqualified':
|
|
||||||
dsqp = Panel.fit(f'Løype: {runner.o_class.course.codes}\nRegistrert: {runner.card_r.controls}', border_style='red')
|
|
||||||
cont = Group(f'Status: {runner.status()}',dsqp)
|
|
||||||
panel = Panel.fit(cont, title=runner.fullname(), border_style='red')
|
|
||||||
elif runner.status() == 'OK':
|
|
||||||
cont = f'Status: {runner.status()}\nTid: {time}'
|
|
||||||
panel = Panel.fit(cont, title=runner.fullname(), border_style='green')
|
|
||||||
elif runner.status() == 'Active':
|
|
||||||
cont = ''
|
|
||||||
panel = Panel.fit(cont, title=runner.fullname())
|
|
||||||
return panel
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async def mtr_listener():
|
|
||||||
mtr = serial.Serial(port=config['port'], baudrate=9600, timeout=40)
|
|
||||||
while True:
|
|
||||||
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.card_punch.from_mtr_bytes(full)
|
|
||||||
event.card_punches.append(card_r)
|
|
||||||
assign_card_r_to_runner(event.runners, card_r)
|
|
||||||
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())
|
|
||||||
asyncio.create_task(mtr_listener())
|
|
||||||
|
|
||||||
async for changes in awatch(config['db_file']):
|
async for changes in awatch(config['db_file']):
|
||||||
print('😵')
|
|
||||||
global event
|
global event
|
||||||
global db_file
|
global db_file
|
||||||
global db_file_u
|
global db_file_u
|
||||||
@ -113,14 +73,14 @@ async def main():
|
|||||||
clean = str(line).replace('+ ', '').split(';')
|
clean = str(line).replace('+ ', '').split(';')
|
||||||
runner = otime.runner.from_string(clean, event.o_classes)
|
runner = otime.runner.from_string(clean, event.o_classes)
|
||||||
inspect(runner)
|
inspect(runner)
|
||||||
if runner.first != None:
|
if runner.firstname:
|
||||||
added_raw.append(runner)
|
added_raw.append(runner)
|
||||||
|
|
||||||
elif line[:1] == '-':
|
elif line[:1] == '-':
|
||||||
#print(line)
|
#print(line)
|
||||||
clean = str(line).replace('- ', '').split(';')
|
clean = str(line).replace('- ', '').split(';')
|
||||||
runner = otime.runner.from_string(clean, event.o_classes)
|
runner = otime.runner.from_string(clean, event.o_classes)
|
||||||
if runner.first != None:
|
if runner.firstname:
|
||||||
removed_raw.append(runner)
|
removed_raw.append(runner)
|
||||||
|
|
||||||
for plus in added_raw:
|
for plus in added_raw:
|
||||||
@ -153,6 +113,7 @@ async def main():
|
|||||||
event.match_runners_cards()
|
event.match_runners_cards()
|
||||||
event.get_xml_res().write(config['xml_res_file'])
|
event.get_xml_res().write(config['xml_res_file'])
|
||||||
|
|
||||||
|
|
||||||
db_file_u = None
|
db_file_u = None
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
start_parse()
|
start_parse()
|
||||||
|
2
otime.py
2
otime.py
@ -208,7 +208,7 @@ class runner:
|
|||||||
index = self.card_r.controls.index(f_control)
|
index = self.card_r.controls.index(f_control)
|
||||||
return self.card_r.splits[index]
|
return self.card_r.splits[index]
|
||||||
except:
|
except:
|
||||||
return 0
|
return self.card_r.splits[-1]
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
if hasattr(self, 'card_r') == False or self.o_class == None:
|
if hasattr(self, 'card_r') == False or self.o_class == None:
|
||||||
|
Loading…
Reference in New Issue
Block a user