Compare commits

..

No commits in common. "b62661c339819f91b90de1f0ada01dd2e88cd8e2" and "80aec702ec00dbb11d83f33eaf73f6a3ab2df025" have entirely different histories.

2 changed files with 69 additions and 61 deletions

View File

@ -1,19 +0,0 @@
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
View File

@ -29,43 +29,7 @@ class event:
self.add_o_class(*classes_from_ttime_conf(ttime_file, self.courses)) self.add_o_class(*classes_from_ttime_conf(ttime_file, self.courses))
def import_ttime_db(self, ttime_file): def import_ttime_db(self, ttime_file):
csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',) self.add_runners(*ttime_db_to_class(ttime_file, self.o_classes))
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): def import_mtr_file(self, mtr_file):
self.card_punches = card_punch.list_from_mtr_f(mtr_file) self.card_punches = card_punch.list_from_mtr_f(mtr_file)
def match_runners_cards(self): def match_runners_cards(self):
@ -178,7 +142,7 @@ class runner:
return self.card_r.splits[-1] 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:
return 'Active' return 'Active'
elif self.check_codes(): elif self.check_codes():
return 'OK' return 'OK'
@ -246,7 +210,7 @@ class card_punch:
tl[1][2] = float(tl[1][2]) tl[1][2] = float(tl[1][2])
tl[1] = list(map(int, tl[1])) 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]) f_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2])
if len(controls) > 2: if controls[-1] == 250:
s_time = f_time - datetime.timedelta(seconds = splits[-2]) s_time = f_time - datetime.timedelta(seconds = splits[-2])
else: else:
s_time = f_time s_time = f_time
@ -295,10 +259,74 @@ def classes_from_ttime_conf(ttime_file, courses):
return o_classes 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): def contains(small, big):
# Checks if small list is in big list
valid = True valid = True
mark = 0 mark = 0
map_bl = [] map_bl = []
@ -316,12 +344,12 @@ def contains(small, big):
return False return False
def get_runners_in_class(runners, o_class): def get_runners_in_class(runners, o_class):
# Filters out runner objects that dont have the correct o_class
list_filtrd = [] list_filtrd = []
for i in runners: for i in runners:
marker = 0 marker = 0
if i.o_class == o_class: if i.o_class == o_class:
list_filtrd.append(i) list_filtrd.append(i)
return list_filtrd return list_filtrd
def rank_runners(allrunners, o_class): def rank_runners(allrunners, o_class):
@ -334,6 +362,5 @@ def rank_runners(allrunners, o_class):
return runners_ranked return runners_ranked
def xml_child(parent, tag, content): def xml_child(parent, tag, content):
# Used to make creating xml files easier
e = ET.SubElement(parent, tag) e = ET.SubElement(parent, tag)
e.text = str(content) e.text = str(content)