Cli er nå helt porta

This commit is contained in:
Trygve 2022-03-10 16:58:31 +01:00
parent 77ea1385f9
commit 0160ffaec8

54
cli.py
View File

@ -47,14 +47,20 @@ def print_class_result(runners, o_class):
if o_class: if o_class:
runners = otime.get_runners_in_class(runners, o_class) runners = otime.get_runners_in_class(runners, o_class)
runners_ok = [] runners_ok = []
runners_dsq = []
for n in runners: for n in runners:
if n.status() == 'OK': if n.status() == 'OK':
runners_ok.append(n) runners_ok.append(n)
elif n.status() == 'Disqualified':
runners_dsq.append(n)
runners_ok.sort(key=lambda x: x.totaltime()) runners_ok.sort(key=lambda x: x.totaltime())
for i in runners_ok: for i in runners_ok:
#if i.status() == 'OK': #if i.status() == 'OK':
pos += 1 pos += 1
table.add_row(str(pos)+'.',i.fullname(), i.club, str(datetime.timedelta(seconds=i.totaltime()))) table.add_row(str(pos)+'.',i.fullname(), i.club, str(datetime.timedelta(seconds=i.totaltime())))
for i in runners_dsq:
table.add_row('Dsq',i.fullname(), i.club, '')
console = Console() console = Console()
console.print(table) console.print(table)
@ -68,15 +74,23 @@ def print_class_splits(runners, o_class):
table.add_column(str(i)) table.add_column(str(i))
runners = otime.get_runners_in_class(runners, o_class) runners = otime.get_runners_in_class(runners, o_class)
runners_ok = [] runners_ok = []
runners_dsq = []
for n in runners: for n in runners:
if n.status() == 'OK': if n.status() == 'OK':
runners_ok.append(n) runners_ok.append(n)
elif n.status() == 'Disqualified':
runners_dsq.append(n)
runners_ok.sort(key=lambda x: x.totaltime()) runners_ok.sort(key=lambda x: x.totaltime())
pos = 0 pos = 0
for i in runners_ok: for i in runners_ok:
splits = i.res_splits().values()
pos += 1 pos += 1
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), i.res_splits()) list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string) table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string)
for i in runners_dsq:
splits = i.res_splits().values()
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
table.add_row('Dsq', i.fullname(), i.club, *list_string)
console = Console() console = Console()
console.print(table) console.print(table)
@ -120,8 +134,6 @@ def main():
show_classes = subparsers.add_parser('show_classes', help='show a table of classes') show_classes = subparsers.add_parser('show_classes', help='show a table of classes')
show_classes.add_argument('--ttcnf', required=True, help='ttime configuration file') show_classes.add_argument('--ttcnf', required=True, help='ttime configuration file')
show_classes.add_argument('--ttdb', required=True, help='ttime db files')
show_classes.add_argument('--mtr', required=True, help='mtr csv file')
create_xml = subparsers.add_parser('create_xml', help='Create xml result file') create_xml = subparsers.add_parser('create_xml', help='Create xml result file')
create_xml.add_argument('--ttcnf', required=True, help='ttime configuration file') create_xml.add_argument('--ttcnf', required=True, help='ttime configuration file')
@ -152,34 +164,34 @@ def main():
elif args.command == 'show_result': elif args.command == 'show_result':
courses = otime.courses_from_ttime_conf(args.ttcnf) event = otime.event(0, 'NoName')
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses) event.import_ttime_cnf(args.ttcnf)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes) event.import_ttime_db(args.ttdb)
otime.ttime_mtr_to_class(args.mtr, runner_list) event.import_mtr_file(args.mtr)
for n in o_classes: event.match_runners_cards()
for n in event.o_classes:
if args.o_class_str == n.name: if args.o_class_str == n.name:
sel_classes = [n] sel_classes = [n]
break break
else: else:
sel_classes = o_classes sel_classes = event.o_classes
for o_class in sel_classes: for o_class in sel_classes:
if args.splits: if args.splits:
print_class_splits(runner_list, o_class) print_class_splits(event.runners, o_class)
else: else:
print_class_result(runner_list, o_class) print_class_result(event.runners, o_class)
elif args.command == 'show_classes': elif args.command == 'show_classes':
courses = otime.courses_from_ttime_conf(args.ttcnf) event = otime.event(0, 'NoName')
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses) event.import_ttime_cnf(args.ttcnf)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes) print_o_classes(event.o_classes)
otime.ttime_mtr_to_class(args.mtr, runner_list)
print_o_classes(o_classes)
elif args.command == 'create_xml': elif args.command == 'create_xml':
courses = otime.courses_from_ttime_conf(args.ttcnf) event = otime.event(0, 'NoName')
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses) event.import_ttime_cnf(args.ttcnf)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes) event.import_ttime_db(args.ttdb)
otime.ttime_mtr_to_class(args.mtr, runner_list) event.import_mtr_file(args.mtr)
otime.gen_xml_result(runner_list, o_classes).write(args.file) event.match_runners_cards()
event.get_xml_res().write(args.file)
if __name__ == "__main__": if __name__ == "__main__":
main() main()