Compare commits

..

No commits in common. "18f49c1a0ce79d76b37c5a05486f7dfbed90a33b" and "f1612cf83898ec5ed5fd9825d5c789bae5ab71a0" have entirely different histories.

4 changed files with 17 additions and 46 deletions

View File

@ -28,32 +28,22 @@ def main():
parser_init.add_argument('--port', required=False, dest='port', action='store', help='specify a serial port')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
parser_init = subparsers.add_parser('gen', help='Generate result files')
parser_init = subparsers.add_parser('viewer', help='View otime data')
parser_init.add_argument('--dir', required=False, dest='dir', action='store', default='./', help='specify a directory')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
parser_init = subparsers.add_parser('view', help='View otime data')
parser_init.add_argument('--dir', required=False, dest='dir', action='store', default='./', help='specify a directory')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
args = parser.parse_args()
try:
if not args.xml_path:
args.xml_path = args.dir + '/output'
except AttributeError:
pass
match args.command:
case 'init':
init_dir(args.dir, args.entries_file, args.courses_file)
case 'run':
run(args.port, args.dir, args.xml_path)
case 'view':
case 'viewer':
search_tui.main(args.dir)
case 'gen':
gen(args.dir, args.xml_path)
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
@ -103,18 +93,6 @@ def run(port='/dev/ttyUSB0', project_dir='./', xml_path='./output/'):
meat = mtr.read(55)
inspect(status)
def gen(project_dir='./', xml_path='./output/'):
config_path = project_dir + '/config.yaml'
mtr_path = project_dir + '/mtr.yaml'
csv_path = project_dir + '/runners.csv'
event = file_io.event_from_yaml_and_csv(config_path, mtr_path, csv_path)
file_io.write_card_dumps(event, mtr_path)
subprocess.run(['git', 'add', './*'], cwd=project_dir, stdout=subprocess.DEVNULL)
subprocess.run(['git', 'commit', '-m', f'Manually run'], cwd=project_dir, stdout=subprocess.DEVNULL)
iof_xml.create_result_file(event, xml_path + '/results.xml')
pdf.create_result_list(event, project_dir + '/output/results.pdf')
def runner_info(event, card_dump):
runner = next((i for i in event.runners if str(i.card_id) == str(card_dump.card)), None)
if runner is None:

View File

@ -22,7 +22,6 @@ def write_card_dumps(event, file_path):
def write_runners_csv(event, file_path):
with open(file_path, 'w') as f:
f.write('ID;Status;Fornavn, Etternavn;Klasse;klubb;Brikke;Gafling;Starttid\n')
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')
@ -38,7 +37,6 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
with open(csv_path, 'r') as f:
data = [i.split(';') for i in f.readlines()]
data.pop(0)
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=int(i[5]), fork=int(i[6]), start_time=i[7]) for i in data]
event.card_dumps = card_dumps

View File

@ -64,14 +64,14 @@ def create_result_file(event, file_path, o_classes=[]):
xml_child(result, 'Status', n.status)
# <SplitTime>
# TODO: ta utgangspunkt i løypa, ikke det brikka har stempla
for code, split in zip(i.course.codes[n.fork], n.splits):
for code, split in zip(i.course.codes, n.splits):
st = ET.SubElement(result, 'SplitTime')
xml_child(st, 'ControlCode', code)
xml_child(st, 'Time', split)
# </SplitTime>
elif n.status == 'MissingPunch':
xml_child(result, 'Status', n.status)
for code, split in zip(i.course.codes[n.fork], n.splits):
for code, split in zip(i.course.codes, n.splits):
st = ET.SubElement(result, 'SplitTime')
xml_child(st, 'ControlCode', code)
if split != 0: xml_child(st, 'Time', split)
@ -122,7 +122,7 @@ def runners_from_xml_entries(xml_file):
start_time = None
runners.append(otime.Runner(rid, first, last, club=club_name, club_id=club_id,
country=country,card_id=card, o_class=class_str,
country=country,card_id=card, o_class_str=class_str,
start_time=start_time, fee_id=fee_id))
return runners
@ -201,9 +201,7 @@ def event_from_xml_entries(xml_file):
o_classes = [otime.OClass(i, []) for i in set(class_names)]
runners = runners_from_xml_entries(xml_file)
# TODO: fiks fees
#fees = fees_from_xml_entries(xml_file)
fees = []
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)

View File

@ -278,21 +278,19 @@ class Event:
runner = self.get_runner(runner_id)
return next((i for i in produce_class_result(self, runner.o_class).runner_results if i.id == runner_id), None)
def get_runner_o_class(self, id):
runner = self.get_runner(id)
return next((copy.copy(i) for i in self.o_classes if i.name == runner.o_class), None)
def get_runner_time(self, id):
runner = self.get_runner(id)
card_dump = self.get_card_dump(runner.card_id)
course = self.get_course(self.get_runner_o_class(id).course)
if card_dump == None or course == None:
if card_dump == None:
return False
f_control = course.codes[runner.fork][-1]
f_control = card_dump.controls[-1]
# TODO: Må gjøres mer robust
try:
index = card_dump.controls.index(f_control)
return card_dump.splits[index]
except:
return False
def get_runner_splits(self, id):
# Tida brukt frem til hver post, ikke tida fra forrige post
@ -300,7 +298,6 @@ class Event:
runner = self.get_runner(id)
card_dump = self.get_card_dump(runner.card_id)
course = self.get_course(self.get_o_class(runner.o_class).course)
codes = course.codes[runner.fork]
except AttributeError:
return None
@ -308,8 +305,8 @@ class Event:
return None
split_iter = zip(card_dump.controls, card_dump.splits).__iter__()
splits = [0] * len(codes)
for n, control in enumerate(codes):
splits = [0] * len(course.codes[runner.fork])
for n, control in enumerate(course.codes[runner.fork]):
if control not in card_dump.controls:
continue
while True: