Compare commits
2 Commits
80aec702ec
...
b62661c339
Author | SHA1 | Date | |
---|---|---|---|
b62661c339 | |||
ec9f9338fa |
19
event_mgr.py
Normal file
19
event_mgr.py
Normal file
@ -0,0 +1,19 @@
|
||||
import otime
|
||||
import pickle
|
||||
from config import config
|
||||
from rich import print
|
||||
from rich import inspect
|
||||
from rich.console import Console
|
||||
from rich.columns import Columns
|
||||
from rich.table import Table
|
||||
|
||||
def main():
|
||||
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'])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
111
otime.py
111
otime.py
@ -29,7 +29,43 @@ class event:
|
||||
self.add_o_class(*classes_from_ttime_conf(ttime_file, self.courses))
|
||||
|
||||
def import_ttime_db(self, ttime_file):
|
||||
self.add_runners(*ttime_db_to_class(ttime_file, self.o_classes))
|
||||
csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',)
|
||||
runnerarray = []
|
||||
for row in csvreader:
|
||||
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, [], []))
|
||||
self.runners = runnerarray
|
||||
def import_mtr_file(self, mtr_file):
|
||||
self.card_punches = card_punch.list_from_mtr_f(mtr_file)
|
||||
def match_runners_cards(self):
|
||||
@ -142,7 +178,7 @@ class runner:
|
||||
return self.card_r.splits[-1]
|
||||
|
||||
def status(self):
|
||||
if hasattr(self, 'card_r') == False:
|
||||
if hasattr(self, 'card_r') == False or self.o_class == None:
|
||||
return 'Active'
|
||||
elif self.check_codes():
|
||||
return 'OK'
|
||||
@ -210,7 +246,7 @@ class card_punch:
|
||||
tl[1][2] = float(tl[1][2])
|
||||
tl[1] = list(map(int, tl[1]))
|
||||
f_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2])
|
||||
if controls[-1] == 250:
|
||||
if len(controls) > 2:
|
||||
s_time = f_time - datetime.timedelta(seconds = splits[-2])
|
||||
else:
|
||||
s_time = f_time
|
||||
@ -259,74 +295,10 @@ def classes_from_ttime_conf(ttime_file, courses):
|
||||
|
||||
return o_classes
|
||||
|
||||
def xml_to_class(xml_file, o_class_list=[]):
|
||||
tree = ET.parse(xml_file)
|
||||
root = tree.getroot()
|
||||
runnerarray = []
|
||||
|
||||
for person_root in root[1:]:
|
||||
first = person_root[1][1][1].text
|
||||
last = person_root[1][1][0].text
|
||||
try:
|
||||
club = person_root[2][1].text
|
||||
except:
|
||||
club = "None"
|
||||
country = person_root[1][3].text
|
||||
try:
|
||||
card = int(person_root[3].text)
|
||||
except:
|
||||
card = 0
|
||||
try:
|
||||
xml_class_str = person_root[4][1].text
|
||||
except:
|
||||
# VELDIG MIDLERTIDIG
|
||||
runner_o_class = o_class_list[0]
|
||||
else:
|
||||
for i in o_class_list:
|
||||
if i.name == xml_class_str:
|
||||
runner_o_class = i
|
||||
break
|
||||
# Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
||||
runnerarray.append(runner(first, last, club, country, card, runner_o_class, [], []))
|
||||
return runnerarray
|
||||
def ttime_db_to_class(ttime_file, o_class_list=[]):
|
||||
csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',)
|
||||
runnerarray = []
|
||||
for row in csvreader:
|
||||
if len(row) == 0:
|
||||
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 = o_class_list[0]
|
||||
else:
|
||||
for i in o_class_list:
|
||||
if i.name == raw_class_str:
|
||||
runner_o_class = i
|
||||
break
|
||||
# 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, [], []))
|
||||
return runnerarray
|
||||
|
||||
|
||||
def contains(small, big):
|
||||
# Checks if small list is in big list
|
||||
valid = True
|
||||
mark = 0
|
||||
map_bl = []
|
||||
@ -344,12 +316,12 @@ def contains(small, big):
|
||||
return False
|
||||
|
||||
def get_runners_in_class(runners, o_class):
|
||||
# Filters out runner objects that dont have the correct o_class
|
||||
list_filtrd = []
|
||||
for i in runners:
|
||||
marker = 0
|
||||
if i.o_class == o_class:
|
||||
list_filtrd.append(i)
|
||||
|
||||
return list_filtrd
|
||||
|
||||
def rank_runners(allrunners, o_class):
|
||||
@ -362,5 +334,6 @@ def rank_runners(allrunners, o_class):
|
||||
return runners_ranked
|
||||
|
||||
def xml_child(parent, tag, content):
|
||||
# Used to make creating xml files easier
|
||||
e = ET.SubElement(parent, tag)
|
||||
e.text = str(content)
|
||||
|
Loading…
Reference in New Issue
Block a user