forked from Trygve/otime
Begynte å legge til oppdatering av løpere gjennom ttime fil
This commit is contained in:
parent
3a9be6b974
commit
387d04e379
41
event_mgr.py
41
event_mgr.py
@ -11,28 +11,59 @@ from rich.console import Console
|
||||
from rich.columns import Columns
|
||||
from rich.table import Table
|
||||
|
||||
|
||||
def start():
|
||||
global event
|
||||
event = otime.event(0, config['event_name'])
|
||||
event.import_ttime_cnf('/home/trygve/Documents/sprintcup040330/sprintcup040330.cnf')
|
||||
event.import_ttime_db(config['db_file'])
|
||||
event.import_mtr_file('/home/trygve/Documents/sprintcup040330/sprintcup040330.log')
|
||||
event.match_runners_cards()
|
||||
event.get_xml_res().write(config['xml_res_file'])
|
||||
#event.get_xml_res().write(config['xml_res_file'])
|
||||
global db_file
|
||||
global db_file_u
|
||||
db_file = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
||||
|
||||
async def main():
|
||||
db_file = open(config['db_file'], 'r', encoding='latin_1').readlines()
|
||||
async for changes in awatch(config['db_file']):
|
||||
#print(dir(changes))
|
||||
#print(changes.difference())
|
||||
db_file_u = open(config['db_file'], 'r', encoding='latin_1').readlines()
|
||||
#print(changes.difference()
|
||||
global event
|
||||
global db_file
|
||||
global db_file_u
|
||||
db_file_u = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
||||
d = Differ()
|
||||
result = list(d.compare(db_file, db_file_u))
|
||||
db_file = db_file_u
|
||||
|
||||
for line in result:
|
||||
if line[:1] == '+':
|
||||
print(line)
|
||||
clean = str(line).replace('+ ', '').split(';')
|
||||
runner = otime.runner.from_string(clean, event.o_classes)
|
||||
inspect(runner)
|
||||
for i, n in enumerate(event.runners):
|
||||
if n.id == runner.id:
|
||||
inspect(n)
|
||||
event.runners[i] = runner
|
||||
inspect(n)
|
||||
event.match_runners_cards()
|
||||
inspect(n)
|
||||
|
||||
elif line[:1] == '-':
|
||||
print(line)
|
||||
print('MINUS')
|
||||
clean = str(line).replace('- ', '').split(';')
|
||||
r_id = clean[1]
|
||||
print(r_id)
|
||||
for i, n in enumerate(event.runners):
|
||||
if n.id == r_id:
|
||||
inspect(n)
|
||||
print(len(event.runners))
|
||||
event.runners.remove(n)
|
||||
print(len(event.runners))
|
||||
|
||||
|
||||
db_file_u = None
|
||||
if __name__ == "__main__":
|
||||
start()
|
||||
asyncio.run(main())
|
||||
|
72
otime.py
72
otime.py
@ -32,39 +32,9 @@ class event:
|
||||
csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',)
|
||||
runnerarray = []
|
||||
for row in csvreader:
|
||||
if len(row) == 0 or row [1] == '':
|
||||
if len(row) == 0 or row[1] == '':
|
||||
continue
|
||||
eventorid = row[0]
|
||||
country = ''
|
||||
name = row[2].split(',')
|
||||
try:
|
||||
first = name[1].strip()
|
||||
except:
|
||||
first = ''
|
||||
last = name[0]
|
||||
try:
|
||||
club = row[4]
|
||||
except:
|
||||
club = "None"
|
||||
try:
|
||||
card = int(row[6])
|
||||
except:
|
||||
card = 0
|
||||
try:
|
||||
raw_class_str = row[3]
|
||||
except:
|
||||
# VELDIG MIDLERTIDIG
|
||||
runner_o_class = None
|
||||
else:
|
||||
if raw_class_str != '':
|
||||
for i in self.o_classes:
|
||||
if i.name == raw_class_str:
|
||||
runner_o_class = i
|
||||
break
|
||||
else:
|
||||
runner_o_class = None
|
||||
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
||||
runnerarray.append(runner(eventorid, first, last, club, country, card, runner_o_class, [], []))
|
||||
runnerarray.append(runner.from_string(row, self.o_classes))
|
||||
self.runners = runnerarray
|
||||
def import_mtr_file(self, mtr_file):
|
||||
self.card_punches = card_punch.list_from_mtr_f(mtr_file)
|
||||
@ -155,14 +125,46 @@ class event:
|
||||
ET.indent(root, space=' ', level=0)
|
||||
return tree
|
||||
class runner:
|
||||
def __init__(self, eventorid, first, last, club, country, card, o_class, controls, splits):
|
||||
self.id = eventorid
|
||||
def __init__(self, runner_id, first, last, club, country, card, o_class):
|
||||
self.id = runner_id
|
||||
self.first = first
|
||||
self.last = last
|
||||
self.club = club
|
||||
self.country = country
|
||||
self.card = card
|
||||
self.o_class = o_class
|
||||
def from_string(tt_line, o_classes):
|
||||
eventorid = tt_line[0]
|
||||
country = ''
|
||||
name = tt_line[2].split(',')
|
||||
try:
|
||||
first = name[1].strip()
|
||||
except:
|
||||
first = ''
|
||||
last = name[0]
|
||||
try:
|
||||
club = tt_line[4]
|
||||
except:
|
||||
club = "None"
|
||||
try:
|
||||
card = int(tt_line[6])
|
||||
except:
|
||||
card = 0
|
||||
try:
|
||||
raw_class_str = tt_line[3]
|
||||
except:
|
||||
# VELDIG MIDLERTIDIG
|
||||
runner_o_class = None
|
||||
else:
|
||||
if raw_class_str != '':
|
||||
for i in o_classes:
|
||||
if i.name == raw_class_str:
|
||||
runner_o_class = i
|
||||
break
|
||||
else:
|
||||
runner_o_class = None
|
||||
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
||||
return runner(eventorid, first, last, club, country, card, runner_o_class)
|
||||
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
@ -204,7 +206,7 @@ class card_punch:
|
||||
self.s_time = s_time
|
||||
self.f_time = f_time
|
||||
def __repr__(self):
|
||||
return f'card({self.card}) punches({self.punches})'
|
||||
return f'card({self.card}) controls({self.controls}) splits({self.splits})'
|
||||
|
||||
def list_from_mtr_f(mtr_f):
|
||||
csvreader = csv.reader(open(mtr_f))
|
||||
|
Loading…
Reference in New Issue
Block a user