Compare commits
No commits in common. "63f9e40fc64150fac39546134d5e706d0964eeee" and "ac2bdab1cf65fddf6d5bb0a710fa4ee7693108b0" have entirely different histories.
63f9e40fc6
...
ac2bdab1cf
25
dev.py
25
dev.py
@ -1,25 +1,16 @@
|
||||
import otime
|
||||
import mtr
|
||||
from rich import print
|
||||
from rich import inspect
|
||||
from rich.console import Console
|
||||
from rich.columns import Columns
|
||||
from rich.table import Table
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
event = otime.Event(0, 'Jukola-testløp')
|
||||
#event.import_ttime_cnf('k2ds/tt.cnf')
|
||||
#event.import_ttime_db('k2ds/db.csv')
|
||||
#event.import_mtr_file('k2ds/mtr.txt')
|
||||
#card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv')
|
||||
#event.match_runners_cards()
|
||||
#event.create_start_list_pdf('starttimes.pdf')
|
||||
#event.get_xml_res().write('Resultater.xml')
|
||||
event.import_ttime_cnf('/home/trygve/Dokumenter/Jukola_uttak/tt.cnf')
|
||||
event.runners = otime.runners_from_xml_entries('/home/trygve/Dokumenter/Jukola_uttak/entries_Nattøkt,_Jukola-testløp.xml', event.o_classes)
|
||||
event.card_dumps = mtr.dump_all('/dev/ttyUSB0')
|
||||
event.match_runners_cards()
|
||||
event.get_xml_res().write('Resultater_uttak.xml')
|
||||
for n in event.card_dumps:
|
||||
print(n.card, n.controls)
|
||||
event = otime.Event(0, 'supercup')
|
||||
event.import_ttime_cnf('k2ds/tt.cnf')
|
||||
event.import_ttime_db('k2ds/db.csv')
|
||||
event.import_mtr_file('k2ds/mtr.txt')
|
||||
#card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv')
|
||||
event.match_runners_cards()
|
||||
event.create_start_list_pdf('starttimes.pdf')
|
||||
#event.get_xml_res().write('Resultater.xml')
|
||||
|
19
mtr.py
19
mtr.py
@ -1,19 +0,0 @@
|
||||
import otime
|
||||
import serial
|
||||
from time import sleep
|
||||
|
||||
def dump_all(port):
|
||||
mtr = serial.Serial(port, baudrate=9600, timeout=40)
|
||||
# dump all command
|
||||
mtr.write(b'/SA')
|
||||
card_dumps = []
|
||||
sleep(0.4)
|
||||
while mtr.in_waiting > 0:
|
||||
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
||||
size = mtr.read(size=1)
|
||||
if size == b'\xe6':
|
||||
meat = mtr.read(229)
|
||||
full = b'\xFF\xFF\xFF\xFF' + size + meat
|
||||
card_r = otime.CardDump.from_mtr_bytes(full)
|
||||
card_dumps.append(card_r)
|
||||
return card_dumps
|
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 = CardDump.list_from_mtr_f(mtr_file)
|
||||
self.card_dumps = card_punch.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', n.club_id)
|
||||
xml_child(org, 'Id', '0')
|
||||
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/truetype/DejaVuSans.ttf")
|
||||
pdf.add_font("DejaVuSans", fname="/usr/share/fonts/dejavu-sans-fonts/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, club_id, country, card, o_class, start_time):
|
||||
def __init__(self, runner_id, first, last, club, 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,16 +199,12 @@ 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, club_id, country, card, runner_o_class, start_time)
|
||||
return Runner(eventorid, first, last, club, country, card, runner_o_class, start_time)
|
||||
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
@ -387,43 +383,6 @@ 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