forked from Trygve/otime
La til xml påmeldingsimport igjen
This commit is contained in:
parent
ac2bdab1cf
commit
66ce00d496
55
otime.py
55
otime.py
@ -43,7 +43,7 @@ class Event:
|
||||
self.runners = runnerarray
|
||||
|
||||
def import_mtr_file(self, mtr_file):
|
||||
self.card_dumps = card_punch.list_from_mtr_f(mtr_file)
|
||||
self.card_dumps = CardDump.list_from_mtr_f(mtr_file)
|
||||
|
||||
def match_runners_cards(self):
|
||||
for n in self.runners:
|
||||
@ -89,7 +89,7 @@ class Event:
|
||||
# </Person>
|
||||
# <Organisation>
|
||||
org = ET.SubElement(person_result, 'Organisation')
|
||||
xml_child(org, 'Id', '0')
|
||||
xml_child(org, 'Id', n.club_id)
|
||||
xml_child(org, 'Name', n.club)
|
||||
country = ET.SubElement(org, 'Country')
|
||||
# TODO: hent land fra løperobjektet
|
||||
@ -138,7 +138,7 @@ class Event:
|
||||
def create_start_list_pdf(self, file_name):
|
||||
pdf = FPDF()
|
||||
pdf.add_page()
|
||||
pdf.add_font("DejaVuSans", fname="/usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf")
|
||||
pdf.add_font("DejaVuSans", fname="/usr/share/fonts/truetype/DejaVuSans.ttf")
|
||||
pdf.set_font("DejaVuSans", size=10)
|
||||
line_height = pdf.font_size * 2
|
||||
col_width = pdf.epw / 4 # distribute content evenly
|
||||
@ -153,14 +153,14 @@ class Event:
|
||||
pdf.ln(line_height)
|
||||
pdf.output(file_name)
|
||||
|
||||
|
||||
# The runner object stores all the data specific to a runner.
|
||||
class Runner:
|
||||
def __init__(self, runner_id, first, last, club, country, card, o_class, start_time):
|
||||
def __init__(self, runner_id, first, last, club, club_id, country, card, o_class, start_time):
|
||||
self.id = runner_id
|
||||
self.first = first
|
||||
self.last = last
|
||||
self.club = club
|
||||
self.club_id = club_id
|
||||
self.country = country
|
||||
self.card = card
|
||||
self.o_class = o_class
|
||||
@ -199,12 +199,16 @@ class Runner:
|
||||
else:
|
||||
runner_o_class = None
|
||||
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
||||
options = tt_line[5].split(',')
|
||||
try:
|
||||
club_id = options[options.index('A')+3]
|
||||
except:
|
||||
club_id = 0
|
||||
try:
|
||||
options = tt_line[5].split(',')
|
||||
start_time = options[options.index('U')+1]
|
||||
except:
|
||||
start_time = None
|
||||
return Runner(eventorid, first, last, club, country, card, runner_o_class, start_time)
|
||||
return Runner(eventorid, first, last, club, club_id, country, card, runner_o_class, start_time)
|
||||
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
@ -383,6 +387,43 @@ def classes_from_ttime_conf(ttime_file, courses):
|
||||
loops += 1
|
||||
return o_classes
|
||||
|
||||
def runners_from_xml_entries(xml_file, o_classes=[]):
|
||||
tree = ET.parse(xml_file)
|
||||
root = tree.getroot()
|
||||
runnerarray = []
|
||||
|
||||
for person_root in root[1:]:
|
||||
rid = person_root[1][0].text
|
||||
first = person_root[1][1][1].text
|
||||
last = person_root[1][1][0].text
|
||||
try:
|
||||
club_id = person_root[2][0].text
|
||||
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_classes:
|
||||
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
|
||||
|
||||
start_time = None
|
||||
runnerarray.append(Runner(rid, first, last, club, club_id, country, card, runner_o_class, start_time))
|
||||
print(rid, first, last, club_id, club, card, xml_class_str)
|
||||
|
||||
return runnerarray
|
||||
|
||||
# Checks if small list is in big list
|
||||
def contains(small, big):
|
||||
valid = True
|
||||
|
Loading…
Reference in New Issue
Block a user