Compare commits
2 Commits
18f49c1a0c
...
5e899fca62
Author | SHA1 | Date | |
---|---|---|---|
5e899fca62 | |||
a75af1a99b |
@ -11,6 +11,9 @@ from pdf import format_m_s
|
||||
from rich import print
|
||||
import search_tui
|
||||
|
||||
from rich.traceback import install
|
||||
install(show_locals=True)
|
||||
|
||||
# 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 😁')
|
||||
@ -36,6 +39,8 @@ def main():
|
||||
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('mtr', help='run mtr commands')
|
||||
parser_init.add_argument('--port', required=False, dest='port', action='store', help='specify a serial port')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -54,6 +59,9 @@ def main():
|
||||
search_tui.main(args.dir)
|
||||
case 'gen':
|
||||
gen(args.dir, args.xml_path)
|
||||
case 'mtr':
|
||||
mtr = serial.Serial(port=args.port, baudrate=9600, timeout=40)
|
||||
mtr.write(b'/SA')
|
||||
|
||||
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
|
||||
@ -108,7 +116,6 @@ def gen(project_dir='./', xml_path='./output/'):
|
||||
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)
|
||||
|
||||
|
@ -40,6 +40,12 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
|
||||
data = [i.split(';') for i in f.readlines()]
|
||||
data.pop(0)
|
||||
for i in data: i[2] = i[2].split(',')
|
||||
for i in data:
|
||||
# Setter starttid til None hvis den ikke er satt
|
||||
if len(i[7]) > 8:
|
||||
i[7] = i[7]
|
||||
else:
|
||||
i[7] = None
|
||||
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
|
||||
event.runners = runners
|
||||
|
@ -30,6 +30,9 @@ def create_result_file(event, file_path, o_classes=[]):
|
||||
# <PersonResult>
|
||||
|
||||
for n in i.runner_results:
|
||||
if n.status == 'DidNotStart':
|
||||
continue
|
||||
|
||||
person_result = ET.SubElement(class_result, 'PersonResult')
|
||||
# <Person>
|
||||
person = ET.SubElement(person_result, 'Person')
|
||||
@ -64,14 +67,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.fork][:-1], n.splits[:-1]):
|
||||
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.fork][:-1], n.splits[:-1]):
|
||||
st = ET.SubElement(result, 'SplitTime')
|
||||
xml_child(st, 'ControlCode', code)
|
||||
if split != 0: xml_child(st, 'Time', split)
|
||||
|
@ -291,8 +291,19 @@ class Event:
|
||||
|
||||
f_control = course.codes[runner.fork][-1]
|
||||
# TODO: Må gjøres mer robust
|
||||
if f_control not in card_dump.controls:
|
||||
# Hvis løperen ikke har vært på sistepost tar vi siste stempling istedet
|
||||
return card_dump.splits[-1]
|
||||
index = card_dump.controls.index(f_control)
|
||||
return card_dump.splits[index]
|
||||
# Hvis løperen ikke har en startid spesifisert brukes brikketid
|
||||
if runner.start_time is None:
|
||||
return card_dump.splits[index]
|
||||
#Hvis det er en startid finner jeg tidsforskjellen mellom brikkestart og faktisk start og trekker den fra totaltida
|
||||
else:
|
||||
time_list = runner.start_time.split(':') # hour, minute, second
|
||||
start_datetime = self.start_time.replace(hour=int(time_list[0]), minute=int(time_list[1]), second=int(time_list[2]))
|
||||
diff = start_datetime - card_dump.s_time
|
||||
return card_dump.splits[index] - diff.total_seconds()
|
||||
|
||||
def get_runner_splits(self, id):
|
||||
# Tida brukt frem til hver post, ikke tida fra forrige post
|
||||
|
Loading…
Reference in New Issue
Block a user