Compare commits
No commits in common. "3894eb72848fb59f7d4e79a919deb0522cbfc7a1" and "bf0b400708e4fcb045ed834d92484869648a900e" have entirely different histories.
3894eb7284
...
bf0b400708
@ -1,41 +0,0 @@
|
|||||||
from yaml import load, dump
|
|
||||||
try:
|
|
||||||
from yaml import CLoader as Loader, CDumper as Dumper
|
|
||||||
except ImportError:
|
|
||||||
from yaml import Loader, Dumper
|
|
||||||
|
|
||||||
from copy import deepcopy
|
|
||||||
import otime
|
|
||||||
|
|
||||||
# Disse funksjonene er for å kunne lese og skrive seperate config, mtr og databasefiler.
|
|
||||||
def write_config(event, file_path):
|
|
||||||
output_event = deepcopy(event)
|
|
||||||
output_event.runners = []
|
|
||||||
output_event.card_dumps = []
|
|
||||||
with open(file_path, 'w') as f:
|
|
||||||
dump(output_event, f)
|
|
||||||
|
|
||||||
def write_card_dumps(event, file_path):
|
|
||||||
card_dumps = deepcopy(event.card_dumps)
|
|
||||||
with open(file_path, 'w') as f:
|
|
||||||
dump(card_dumps, f)
|
|
||||||
|
|
||||||
def write_runners_csv(event, file_path):
|
|
||||||
with open(file_path, 'w') as f:
|
|
||||||
for i in event.runners:
|
|
||||||
f.write(f'{i.id};{i.status_override};{i.first}, {i.last};{i.o_class};{i.club};{i.card_id};{i.fork};{i.start_time}\n')
|
|
||||||
|
|
||||||
def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
|
|
||||||
with open(mtr_path, 'r') as f:
|
|
||||||
card_dumps = load(f, Loader=Loader)
|
|
||||||
|
|
||||||
with open(config_path, 'r') as f:
|
|
||||||
event = load(f, Loader=Loader)
|
|
||||||
|
|
||||||
with open(csv_path, 'r') as f:
|
|
||||||
data = [i.split(';') for i in f.readlines()]
|
|
||||||
for i in data: i[2] = i[2].split(',')
|
|
||||||
runners = [otime.Runner(id=i[0], status_override=i[1], first=i[2][0], last=i[2][1].strip(), o_class=i[3], club=i[4], card_id=i[5], fork=i[6], start_time=i[7]) for i in data]
|
|
||||||
event.card_dumps = card_dumps
|
|
||||||
event.runners = runners
|
|
||||||
return event
|
|
@ -1,6 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import otime
|
|
||||||
|
|
||||||
def xml_child(parent, tag, content):
|
def xml_child(parent, tag, content):
|
||||||
# Used to make creating xml files easier
|
# Used to make creating xml files easier
|
||||||
@ -74,7 +73,6 @@ def create_result_file(event, file_path, o_classes=[]):
|
|||||||
for code, split in zip(i.course.codes, n.splits):
|
for code, split in zip(i.course.codes, n.splits):
|
||||||
st = ET.SubElement(result, 'SplitTime')
|
st = ET.SubElement(result, 'SplitTime')
|
||||||
xml_child(st, 'ControlCode', code)
|
xml_child(st, 'ControlCode', code)
|
||||||
if split != 0: xml_child(st, 'Time', split)
|
|
||||||
else:
|
else:
|
||||||
xml_child(result, 'Status', n.status)
|
xml_child(result, 'Status', n.status)
|
||||||
else:
|
else:
|
||||||
@ -121,8 +119,8 @@ def runners_from_xml_entries(xml_file):
|
|||||||
card = None
|
card = None
|
||||||
|
|
||||||
start_time = None
|
start_time = None
|
||||||
runners.append(otime.Runner(rid, first, last, club=club_name, club_id=club_id,
|
runners.append(Runner(rid, first, last, club=club_name, club_id=club_id,
|
||||||
country=country,card_id=card, o_class_str=class_str,
|
country=country,card=card, o_class_str=class_str,
|
||||||
start_time=start_time, fee_id=fee_id))
|
start_time=start_time, fee_id=fee_id))
|
||||||
return runners
|
return runners
|
||||||
|
|
||||||
@ -152,7 +150,7 @@ def fees_from_xml_entries(xml_file):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
to_birth_date = None
|
to_birth_date = None
|
||||||
|
|
||||||
fee_objs.append(otime.Fee(fee_id, name, currency, amount,
|
fee_objs.append(Fee(fee_id, name, currency, amount,
|
||||||
from_birth_date=from_birth_date, to_birth_date=to_birth_date))
|
from_birth_date=from_birth_date, to_birth_date=to_birth_date))
|
||||||
return fee_objs
|
return fee_objs
|
||||||
|
|
||||||
@ -172,36 +170,5 @@ def courses_from_xml(xml_file):
|
|||||||
controls.remove('STA1')
|
controls.remove('STA1')
|
||||||
controls.remove('FIN1')
|
controls.remove('FIN1')
|
||||||
controls = [int(l) for l in controls]
|
controls = [int(l) for l in controls]
|
||||||
courseobjs.append(otime.Course(name, controls))
|
courseobjs.append(Course(name, controls))
|
||||||
return courseobjs
|
return courseobjs
|
||||||
|
|
||||||
def event_from_xml_entries(xml_file):
|
|
||||||
tree = ET.parse(xml_file)
|
|
||||||
root = tree.getroot()
|
|
||||||
|
|
||||||
url = '{http://www.orienteering.org/datastandard/3.0}'
|
|
||||||
event_el = root.find(f'./{url}Event')
|
|
||||||
event_id = int(event_el.find(f'./{url}Id').text)
|
|
||||||
name = event_el.find(f'./{url}Name').text
|
|
||||||
organiser = event_el.find(f'./{url}Organiser/{url}Name').text
|
|
||||||
|
|
||||||
start_ds = event_el.find(f'./{url}StartTime/{url}Date').text
|
|
||||||
start_ts = event_el.find(f'./{url}StartTime/{url}Time').text[:-1]
|
|
||||||
start_time = datetime.datetime.fromisoformat(f'{start_ds}T{start_ts}')
|
|
||||||
|
|
||||||
end_ds = event_el.find(f'./{url}EndTime/{url}Date').text
|
|
||||||
end_ts = event_el.find(f'./{url}EndTime/{url}Time').text[:-1]
|
|
||||||
end_time = datetime.datetime.fromisoformat(f'{end_ds}T{end_ts}')
|
|
||||||
|
|
||||||
person_entries = root.findall(f'./{url}PersonEntry')
|
|
||||||
|
|
||||||
class_names = []
|
|
||||||
for p_entry in person_entries:
|
|
||||||
class_names.append(p_entry.find(f'./{url}Class/{url}Name').text)
|
|
||||||
o_classes = [otime.OClass(i, []) for i in set(class_names)]
|
|
||||||
|
|
||||||
runners = runners_from_xml_entries(xml_file)
|
|
||||||
fees = fees_from_xml_entries(xml_file)
|
|
||||||
|
|
||||||
return otime.Event(event_id, name, organiser=organiser, runners=runners,
|
|
||||||
fees=fees, start_time=start_time, end_time=end_time, o_classes=o_classes)
|
|
@ -1,36 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import file_io
|
|
||||||
import iof_xml
|
|
||||||
|
|
||||||
# Main entrypoint for now. Cli with two options; init will make the files needed and run will start the program from the specified directory
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description='Otime very alpha version 😁')
|
|
||||||
subparsers = parser.add_subparsers(dest='command')
|
|
||||||
parser_init = subparsers.add_parser('init', help='INIT')
|
|
||||||
parser_init.add_argument('--entries', required=True, dest='entries_file', action='store', default='./',
|
|
||||||
help='The xml file with entries')
|
|
||||||
parser_init.add_argument('--courses', required=True, dest='courses_file', action='store', default='./',
|
|
||||||
help='The xml with courses')
|
|
||||||
parser_init.add_argument('--dir', required=False, dest='dir', action='store', default='./',
|
|
||||||
|
|
||||||
help='Specify a directort, if not set the files are created in the current directory')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
if args.command == 'init':
|
|
||||||
init_dir(args.dir, args.entries_file, args.courses_file)
|
|
||||||
|
|
||||||
def init_dir(project_dir, entries_xml_file, courses_xml_file):
|
|
||||||
# Lager mappe med en config fil, en csv fil med løpere og en fil med mtr data
|
|
||||||
csv_db_path = project_dir + '/runners.csv'
|
|
||||||
config_path = project_dir + '/config.yaml'
|
|
||||||
mtr_path = project_dir + 'mtr.yaml'
|
|
||||||
|
|
||||||
event = iof_xml.event_from_xml_entries(entries_xml_file)
|
|
||||||
event.courses = iof_xml.courses_from_xml(courses_xml_file)
|
|
||||||
|
|
||||||
file_io.write_runners_csv(event, csv_db_path)
|
|
||||||
file_io.write_config(event, config_path)
|
|
||||||
file_io.write_card_dumps(event, mtr_path)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
@ -7,7 +7,7 @@ import pdf
|
|||||||
class Runner:
|
class Runner:
|
||||||
def __init__(self, id: int, first: str, last: str, club=None, club_id=None,
|
def __init__(self, id: int, first: str, last: str, club=None, club_id=None,
|
||||||
country=None, card_id=None, o_class_str=None, o_class=None,
|
country=None, card_id=None, o_class_str=None, o_class=None,
|
||||||
fork=0, start_time=None, fee_id=None, fee=None, status_override=''):
|
fork=0, start_time=None, fee_id=None, fee=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.first = first
|
self.first = first
|
||||||
self.last = last
|
self.last = last
|
||||||
@ -19,7 +19,7 @@ class Runner:
|
|||||||
self.fork = fork
|
self.fork = fork
|
||||||
self.start_time = start_time
|
self.start_time = start_time
|
||||||
self.fee_id = fee_id
|
self.fee_id = fee_id
|
||||||
self.status_override = status_override
|
self.status_override = ''
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return(f'name({self.fullname()})')
|
return(f'name({self.fullname()})')
|
||||||
@ -289,7 +289,6 @@ class Event:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def get_runner_splits(self, id):
|
def get_runner_splits(self, id):
|
||||||
# Tida brukt frem til hver post, ikke tida fra forrige post
|
|
||||||
try:
|
try:
|
||||||
runner = self.get_runner(id)
|
runner = self.get_runner(id)
|
||||||
card_dump = self.get_card_dump(runner.card_id)
|
card_dump = self.get_card_dump(runner.card_id)
|
||||||
@ -305,14 +304,17 @@ class Event:
|
|||||||
for n, control in enumerate(course.codes):
|
for n, control in enumerate(course.codes):
|
||||||
if control not in card_dump.controls:
|
if control not in card_dump.controls:
|
||||||
continue
|
continue
|
||||||
|
split_debt = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
punched_control, split = next(split_iter)
|
punched_control, split = next(split_iter)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
if punched_control == control:
|
if punched_control == control:
|
||||||
splits[n] = split
|
splits[n] = split + split_debt
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
split_debt += split
|
||||||
return splits
|
return splits
|
||||||
|
|
||||||
def get_runner_controls(self, id):
|
def get_runner_controls(self, id):
|
||||||
@ -337,6 +339,29 @@ class Event:
|
|||||||
self.add_fees(*fees_from_xml_entries(xml_file))
|
self.add_fees(*fees_from_xml_entries(xml_file))
|
||||||
|
|
||||||
# Må endres
|
# Må endres
|
||||||
|
def from_xml_entries(xml_file):
|
||||||
|
tree = ET.parse(xml_file)
|
||||||
|
root = tree.getroot()
|
||||||
|
|
||||||
|
url = '{http://www.orienteering.org/datastandard/3.0}'
|
||||||
|
event_el = root.find(f'./{url}Event')
|
||||||
|
event_id = int(event_el.find(f'./{url}Id').text)
|
||||||
|
name = event_el.find(f'./{url}Name').text
|
||||||
|
organiser = event_el.find(f'./{url}Organiser/{url}Name').text
|
||||||
|
|
||||||
|
start_ds = event_el.find(f'./{url}StartTime/{url}Date').text
|
||||||
|
start_ts = event_el.find(f'./{url}StartTime/{url}Time').text[:-1]
|
||||||
|
start_time = datetime.datetime.fromisoformat(f'{start_ds}T{start_ts}')
|
||||||
|
|
||||||
|
end_ds = event_el.find(f'./{url}EndTime/{url}Date').text
|
||||||
|
end_ts = event_el.find(f'./{url}EndTime/{url}Time').text[:-1]
|
||||||
|
end_time = datetime.datetime.fromisoformat(f'{end_ds}T{end_ts}')
|
||||||
|
|
||||||
|
runners = runners_from_xml_entries(xml_file)
|
||||||
|
fees = fees_from_xml_entries(xml_file)
|
||||||
|
|
||||||
|
return Event(event_id, name, organiser=organiser, runners=runners,
|
||||||
|
fees=fees, start_time=start_time, end_time=end_time)
|
||||||
|
|
||||||
def read_xml_courses(self, xml_file):
|
def read_xml_courses(self, xml_file):
|
||||||
self.courses = courses_from_xml(xml_file)
|
self.courses = courses_from_xml(xml_file)
|
||||||
|
@ -44,7 +44,7 @@ def create_split_result_list(event, file_path, o_classes=[]):
|
|||||||
col_width = pdf.epw / 4 # distribute content evenly
|
col_width = pdf.epw / 4 # distribute content evenly
|
||||||
|
|
||||||
for class_result in results:
|
for class_result in results:
|
||||||
col_width = 10
|
col_width = pdf.epw / (21+len(class_result.course.codes))
|
||||||
pdf.write(txt=class_result.name)
|
pdf.write(txt=class_result.name)
|
||||||
pdf.ln(line_height)
|
pdf.ln(line_height)
|
||||||
for runner in class_result.runner_results:
|
for runner in class_result.runner_results:
|
||||||
|
@ -3,31 +3,16 @@ sys.path.insert(0, '../../otime')
|
|||||||
import otime
|
import otime
|
||||||
import pdf
|
import pdf
|
||||||
import iof_xml
|
import iof_xml
|
||||||
import file_io
|
|
||||||
|
|
||||||
def ttime_testing():
|
def main():
|
||||||
event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe')
|
event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe')
|
||||||
event.read_ttime_cnf('tt.cnf')
|
event.read_ttime_cnf('tt.cnf')
|
||||||
event.read_ttime_db('db.csv')
|
event.read_ttime_db('db.csv')
|
||||||
event.read_mtr_file('mtr.csv')
|
event.read_mtr_file('mtr.csv')
|
||||||
pdf.create_split_result_list(event, 'output/result.pdf')
|
pdf.create_split_result_list(event, 'output/result.pdf')
|
||||||
iof_xml.create_result_file(event, '/home/trygve/Prosjekter/simple-liveresults/resultater/Resultater.xml')
|
iof_xml.create_result_file(event, 'output/result.xml')
|
||||||
print(event.get_runner_status('1400'))
|
print(event.get_runner_status('1400'))
|
||||||
results = event.get_result()
|
results = event.get_result()
|
||||||
print([pdf.format_m_s(i) for i in event.get_runner_splits('17')])
|
|
||||||
print([pdf.format_m_s(i) for i in event.get_card_dump(event.get_runner('17').card_id).splits])
|
|
||||||
file_io.write_config(event, 'output/config.yaml')
|
|
||||||
file_io.write_card_dumps(event, 'output/mtr.yaml')
|
|
||||||
file_io.write_runners_csv(event, 'output/runners.csv')
|
|
||||||
print(file_io.event_from_yaml_and_csv('output/config.yaml', 'output/mtr.yaml', 'output/runners.csv'))
|
|
||||||
|
|
||||||
def xml_testing():
|
|
||||||
event = iof_xml.event_from_xml_entries('entries.xml')
|
|
||||||
event.courses = iof_xml.courses_from_xml('course.xml')
|
|
||||||
file_io.write_config(event, 'output/config.yaml')
|
|
||||||
file_io.write_card_dumps(event, 'output/mtr.yaml')
|
|
||||||
file_io.write_runners_csv(event, 'output/runners.csv')
|
|
||||||
print(file_io.event_from_yaml_and_csv('output/config.yaml', 'output/mtr.yaml', 'output/runners.csv'))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
xml_testing()
|
main()
|
Loading…
Reference in New Issue
Block a user