Flytta db import til evennt objektet
This commit is contained in:
parent
80aec702ec
commit
ec9f9338fa
111
otime.py
111
otime.py
@ -29,7 +29,43 @@ 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):
|
||||||
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):
|
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):
|
||||||
@ -142,7 +178,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:
|
if hasattr(self, 'card_r') == False or self.o_class == None:
|
||||||
return 'Active'
|
return 'Active'
|
||||||
elif self.check_codes():
|
elif self.check_codes():
|
||||||
return 'OK'
|
return 'OK'
|
||||||
@ -210,7 +246,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 controls[-1] == 250:
|
if len(controls) > 2:
|
||||||
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
|
||||||
@ -259,74 +295,10 @@ 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 = []
|
||||||
@ -344,12 +316,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):
|
||||||
@ -362,5 +334,6 @@ 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user