Compare commits
3 Commits
ac2bdab1cf
...
63f9e40fc6
Author | SHA1 | Date | |
---|---|---|---|
63f9e40fc6 | |||
7abb532b90 | |||
66ce00d496 |
25
dev.py
25
dev.py
@ -1,16 +1,25 @@
|
|||||||
import otime
|
import otime
|
||||||
|
import mtr
|
||||||
from rich import print
|
from rich import print
|
||||||
from rich import inspect
|
from rich import inspect
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.columns import Columns
|
from rich.columns import Columns
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
event = otime.Event(0, 'supercup')
|
event = otime.Event(0, 'Jukola-testløp')
|
||||||
event.import_ttime_cnf('k2ds/tt.cnf')
|
#event.import_ttime_cnf('k2ds/tt.cnf')
|
||||||
event.import_ttime_db('k2ds/db.csv')
|
#event.import_ttime_db('k2ds/db.csv')
|
||||||
event.import_mtr_file('k2ds/mtr.txt')
|
#event.import_mtr_file('k2ds/mtr.txt')
|
||||||
#card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv')
|
#card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv')
|
||||||
event.match_runners_cards()
|
#event.match_runners_cards()
|
||||||
event.create_start_list_pdf('starttimes.pdf')
|
#event.create_start_list_pdf('starttimes.pdf')
|
||||||
#event.get_xml_res().write('Resultater.xml')
|
#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)
|
||||||
|
19
mtr.py
Normal file
19
mtr.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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
|
self.runners = runnerarray
|
||||||
|
|
||||||
def import_mtr_file(self, mtr_file):
|
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):
|
def match_runners_cards(self):
|
||||||
for n in self.runners:
|
for n in self.runners:
|
||||||
@ -89,7 +89,7 @@ class Event:
|
|||||||
# </Person>
|
# </Person>
|
||||||
# <Organisation>
|
# <Organisation>
|
||||||
org = ET.SubElement(person_result, '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)
|
xml_child(org, 'Name', n.club)
|
||||||
country = ET.SubElement(org, 'Country')
|
country = ET.SubElement(org, 'Country')
|
||||||
# TODO: hent land fra løperobjektet
|
# TODO: hent land fra løperobjektet
|
||||||
@ -138,7 +138,7 @@ class Event:
|
|||||||
def create_start_list_pdf(self, file_name):
|
def create_start_list_pdf(self, file_name):
|
||||||
pdf = FPDF()
|
pdf = FPDF()
|
||||||
pdf.add_page()
|
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)
|
pdf.set_font("DejaVuSans", size=10)
|
||||||
line_height = pdf.font_size * 2
|
line_height = pdf.font_size * 2
|
||||||
col_width = pdf.epw / 4 # distribute content evenly
|
col_width = pdf.epw / 4 # distribute content evenly
|
||||||
@ -153,14 +153,14 @@ class Event:
|
|||||||
pdf.ln(line_height)
|
pdf.ln(line_height)
|
||||||
pdf.output(file_name)
|
pdf.output(file_name)
|
||||||
|
|
||||||
|
|
||||||
# The runner object stores all the data specific to a runner.
|
# The runner object stores all the data specific to a runner.
|
||||||
class 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.id = runner_id
|
||||||
self.first = first
|
self.first = first
|
||||||
self.last = last
|
self.last = last
|
||||||
self.club = club
|
self.club = club
|
||||||
|
self.club_id = club_id
|
||||||
self.country = country
|
self.country = country
|
||||||
self.card = card
|
self.card = card
|
||||||
self.o_class = o_class
|
self.o_class = o_class
|
||||||
@ -199,12 +199,16 @@ class Runner:
|
|||||||
else:
|
else:
|
||||||
runner_o_class = None
|
runner_o_class = None
|
||||||
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
# 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:
|
try:
|
||||||
options = tt_line[5].split(',')
|
|
||||||
start_time = options[options.index('U')+1]
|
start_time = options[options.index('U')+1]
|
||||||
except:
|
except:
|
||||||
start_time = None
|
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):
|
def fullname(self):
|
||||||
return '{} {}'.format(self.first, self.last)
|
return '{} {}'.format(self.first, self.last)
|
||||||
@ -383,6 +387,43 @@ def classes_from_ttime_conf(ttime_file, courses):
|
|||||||
loops += 1
|
loops += 1
|
||||||
return o_classes
|
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
|
# Checks if small list is in big list
|
||||||
def contains(small, big):
|
def contains(small, big):
|
||||||
valid = True
|
valid = True
|
||||||
|
Loading…
Reference in New Issue
Block a user