2022-02-21 11:51:02 +00:00
|
|
|
#!/usr/bin/env python
|
2022-02-06 00:12:32 +00:00
|
|
|
import otime
|
|
|
|
|
2022-02-21 11:51:02 +00:00
|
|
|
import argparse
|
2022-02-08 20:56:44 +00:00
|
|
|
import datetime
|
2022-02-21 11:51:02 +00:00
|
|
|
from rich import print
|
2022-02-21 18:21:06 +00:00
|
|
|
from rich import inspect
|
2022-02-06 00:12:32 +00:00
|
|
|
from rich.console import Console
|
2022-02-21 11:51:02 +00:00
|
|
|
from rich.columns import Columns
|
2022-02-06 00:12:32 +00:00
|
|
|
from rich.table import Table
|
|
|
|
def print_runners(Runners):
|
|
|
|
table = Table(title="Runners")
|
|
|
|
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
|
|
|
|
table.add_column("club", style="magenta")
|
|
|
|
table.add_column("card", style="red")
|
|
|
|
table.add_column("class", justify="right", style="green")
|
2022-03-09 17:06:59 +00:00
|
|
|
table.add_column("Status", justify="right", style="blue")
|
2022-02-06 00:12:32 +00:00
|
|
|
|
|
|
|
for i in Runners:
|
2022-05-11 13:07:33 +00:00
|
|
|
try:
|
|
|
|
o_class = i.o_class.name
|
|
|
|
except:
|
|
|
|
o_class = ''
|
|
|
|
table.add_row(i.fullname(), i.club ,str(i.card), o_class, i.status())
|
2022-02-06 00:12:32 +00:00
|
|
|
|
2022-02-08 20:56:44 +00:00
|
|
|
console = Console()
|
|
|
|
console.print(table)
|
|
|
|
def print_time(Runners):
|
2022-02-10 14:02:35 +00:00
|
|
|
table = Table(title="Time")
|
2022-02-08 20:56:44 +00:00
|
|
|
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
|
|
|
|
table.add_column("club", style="magenta")
|
2022-02-10 14:02:35 +00:00
|
|
|
table.add_column("splits", style="red")
|
|
|
|
table.add_column("Check", style="green")
|
|
|
|
table.add_column("Time", justify="right", style="blue")
|
2022-02-08 20:56:44 +00:00
|
|
|
for i in Runners:
|
|
|
|
try:
|
|
|
|
tottime = datetime.timedelta(seconds = i.totaltime())
|
|
|
|
except:
|
|
|
|
tottime = 0
|
|
|
|
table.add_row(i.fullname(), i.o_class.name, str(i.splits), str(i.check_codes()), str(tottime))
|
|
|
|
|
2022-02-21 11:51:02 +00:00
|
|
|
console = Console()
|
|
|
|
console.print(table)
|
|
|
|
def print_class_result(runners, o_class):
|
|
|
|
table = Table(title=o_class.name)
|
|
|
|
table.add_column("Pos", style="red", no_wrap=True)
|
|
|
|
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
|
|
|
|
table.add_column("Club", style="magenta")
|
|
|
|
table.add_column("Time", justify="right", style="blue")
|
|
|
|
pos = 0
|
|
|
|
if o_class:
|
|
|
|
runners = otime.get_runners_in_class(runners, o_class)
|
|
|
|
runners_ok = []
|
2022-03-10 15:58:31 +00:00
|
|
|
runners_dsq = []
|
2022-02-21 11:51:02 +00:00
|
|
|
for n in runners:
|
|
|
|
if n.status() == 'OK':
|
|
|
|
runners_ok.append(n)
|
2022-03-10 15:58:31 +00:00
|
|
|
elif n.status() == 'Disqualified':
|
|
|
|
runners_dsq.append(n)
|
2022-02-21 11:51:02 +00:00
|
|
|
runners_ok.sort(key=lambda x: x.totaltime())
|
2022-03-10 15:58:31 +00:00
|
|
|
|
2022-02-21 11:51:02 +00:00
|
|
|
for i in runners_ok:
|
|
|
|
#if i.status() == 'OK':
|
|
|
|
pos += 1
|
2022-02-21 18:21:06 +00:00
|
|
|
table.add_row(str(pos)+'.',i.fullname(), i.club, str(datetime.timedelta(seconds=i.totaltime())))
|
2022-03-10 15:58:31 +00:00
|
|
|
for i in runners_dsq:
|
|
|
|
table.add_row('Dsq',i.fullname(), i.club, '')
|
2022-02-21 11:51:02 +00:00
|
|
|
|
2022-02-10 14:02:35 +00:00
|
|
|
console = Console()
|
|
|
|
console.print(table)
|
|
|
|
def print_class_splits(runners, o_class):
|
|
|
|
table = Table(title=o_class.name)
|
2022-02-21 11:51:02 +00:00
|
|
|
table.add_column("Pos", style="red", no_wrap=True)
|
2022-02-10 14:02:35 +00:00
|
|
|
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
|
|
|
|
table.add_column("club", style="magenta")
|
2022-02-21 11:51:02 +00:00
|
|
|
if o_class:
|
|
|
|
for i in o_class.course.codes:
|
|
|
|
table.add_column(str(i))
|
|
|
|
runners = otime.get_runners_in_class(runners, o_class)
|
|
|
|
runners_ok = []
|
2022-03-10 15:58:31 +00:00
|
|
|
runners_dsq = []
|
2022-02-21 11:51:02 +00:00
|
|
|
for n in runners:
|
|
|
|
if n.status() == 'OK':
|
|
|
|
runners_ok.append(n)
|
2022-03-10 15:58:31 +00:00
|
|
|
elif n.status() == 'Disqualified':
|
|
|
|
runners_dsq.append(n)
|
2022-02-21 11:51:02 +00:00
|
|
|
runners_ok.sort(key=lambda x: x.totaltime())
|
|
|
|
pos = 0
|
|
|
|
for i in runners_ok:
|
2022-03-10 17:18:59 +00:00
|
|
|
splits = i.res_splits()
|
2022-02-21 11:51:02 +00:00
|
|
|
pos += 1
|
2022-03-10 15:58:31 +00:00
|
|
|
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
|
2022-02-21 11:51:02 +00:00
|
|
|
table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string)
|
2022-03-10 15:58:31 +00:00
|
|
|
for i in runners_dsq:
|
2022-03-10 17:18:59 +00:00
|
|
|
splits = i.res_splits()
|
2022-03-10 15:58:31 +00:00
|
|
|
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), splits)
|
|
|
|
table.add_row('Dsq', i.fullname(), i.club, *list_string)
|
2022-02-06 00:12:32 +00:00
|
|
|
console = Console()
|
|
|
|
console.print(table)
|
|
|
|
def print_o_classes(class_list):
|
|
|
|
table = Table(title="Classes")
|
|
|
|
table.add_column("Class", justify="right", style="cyan", no_wrap=True)
|
|
|
|
table.add_column("Course", style="magenta")
|
|
|
|
table.add_column("Controls", justify="right", style="green")
|
|
|
|
|
|
|
|
for i in class_list:
|
2022-03-10 17:18:59 +00:00
|
|
|
table.add_row(i.name, i.course.name , str(i.course.codes))
|
2022-02-06 00:12:32 +00:00
|
|
|
|
|
|
|
console = Console()
|
|
|
|
console.print(table)
|
|
|
|
|
2022-02-21 11:51:02 +00:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
'--debug',
|
|
|
|
action='store_true',
|
|
|
|
help='Print debug info'
|
|
|
|
)
|
|
|
|
subparsers = parser.add_subparsers(dest='command')
|
|
|
|
show_runners = subparsers.add_parser('show_runners', help='show a table of runners')
|
|
|
|
show_runners.add_argument('--ttcnf', required=True, help='ttime configuration file')
|
|
|
|
show_runners.add_argument('--ttdb', required=True, help='ttime database file')
|
|
|
|
show_runners.add_argument('--mtr', required=True, help='mtr csv file')
|
|
|
|
|
2022-02-21 18:21:06 +00:00
|
|
|
show_runner = subparsers.add_parser('show_runner', help='show a table of runners')
|
|
|
|
show_runner.add_argument('--ttcnf', required=True, help='ttime configuration file')
|
|
|
|
show_runner.add_argument('--ttdb', required=True, help='ttime database file')
|
|
|
|
show_runner.add_argument('--mtr', required=True, help='mtr csv file')
|
|
|
|
show_runner.add_argument('--runner', required=True, help='Which runner to print')
|
|
|
|
|
2022-02-21 11:51:02 +00:00
|
|
|
show_runners = subparsers.add_parser('show_result', help='show a table of runners')
|
|
|
|
show_runners.add_argument('--ttcnf', required=True, help='ttime configuration file')
|
|
|
|
show_runners.add_argument('--ttdb', required=True, help='ttime database file')
|
|
|
|
show_runners.add_argument('--mtr', required=True, help='mtr csv file')
|
|
|
|
show_runners.add_argument('--class', dest='o_class_str', help='Which class to show. Prints all classes if not set')
|
|
|
|
show_runners.add_argument('--splits', action='store_true', help='Shows split times')
|
|
|
|
|
|
|
|
show_classes = subparsers.add_parser('show_classes', help='show a table of classes')
|
|
|
|
show_classes.add_argument('--ttcnf', required=True, help='ttime configuration 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('--ttdb', required=True, help='ttime database file')
|
|
|
|
create_xml.add_argument('--mtr', required=True, help='mtr csv file')
|
|
|
|
create_xml.add_argument('--file', required=True, help='Filename for result file')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.command == 'show_runners':
|
2022-05-11 13:07:33 +00:00
|
|
|
event = otime.Event(0, 'NoName')
|
2022-03-09 17:06:59 +00:00
|
|
|
event.import_ttime_cnf(args.ttcnf)
|
|
|
|
event.import_ttime_db(args.ttdb)
|
|
|
|
event.import_mtr_file(args.mtr)
|
|
|
|
event.match_runners_cards()
|
|
|
|
print_runners(event.runners)
|
2022-02-21 18:21:06 +00:00
|
|
|
elif args.command == 'show_runner':
|
2022-05-11 13:07:33 +00:00
|
|
|
event = otime.Event(0, 'NoName')
|
2022-03-09 17:06:59 +00:00
|
|
|
event.import_ttime_cnf(args.ttcnf)
|
|
|
|
event.import_ttime_db(args.ttdb)
|
|
|
|
event.import_mtr_file(args.mtr)
|
|
|
|
event.match_runners_cards()
|
|
|
|
for n in event.runners:
|
2022-02-21 18:21:06 +00:00
|
|
|
if args.runner == n.fullname():
|
|
|
|
inspect(n)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
print('Runner not found. Use full name.')
|
|
|
|
|
|
|
|
|
|
|
|
elif args.command == 'show_result':
|
2022-05-11 13:07:33 +00:00
|
|
|
event = otime.Event(0, 'NoName')
|
2022-03-10 15:58:31 +00:00
|
|
|
event.import_ttime_cnf(args.ttcnf)
|
|
|
|
event.import_ttime_db(args.ttdb)
|
|
|
|
event.import_mtr_file(args.mtr)
|
|
|
|
event.match_runners_cards()
|
|
|
|
for n in event.o_classes:
|
2022-02-21 11:51:02 +00:00
|
|
|
if args.o_class_str == n.name:
|
2022-02-21 18:21:06 +00:00
|
|
|
sel_classes = [n]
|
2022-02-21 11:51:02 +00:00
|
|
|
break
|
|
|
|
else:
|
2022-03-10 15:58:31 +00:00
|
|
|
sel_classes = event.o_classes
|
2022-02-21 18:21:06 +00:00
|
|
|
for o_class in sel_classes:
|
|
|
|
if args.splits:
|
2022-03-10 15:58:31 +00:00
|
|
|
print_class_splits(event.runners, o_class)
|
2022-02-21 18:21:06 +00:00
|
|
|
else:
|
2022-03-10 15:58:31 +00:00
|
|
|
print_class_result(event.runners, o_class)
|
2022-02-21 11:51:02 +00:00
|
|
|
elif args.command == 'show_classes':
|
2022-05-11 13:07:33 +00:00
|
|
|
event = otime.Event(0, 'NoName')
|
2022-03-10 15:58:31 +00:00
|
|
|
event.import_ttime_cnf(args.ttcnf)
|
|
|
|
print_o_classes(event.o_classes)
|
2022-02-21 11:51:02 +00:00
|
|
|
|
2022-02-21 18:21:06 +00:00
|
|
|
elif args.command == 'create_xml':
|
2022-05-11 13:07:33 +00:00
|
|
|
event = otime.Event(0, 'NoName')
|
2022-03-10 15:58:31 +00:00
|
|
|
event.import_ttime_cnf(args.ttcnf)
|
|
|
|
event.import_ttime_db(args.ttdb)
|
|
|
|
event.import_mtr_file(args.mtr)
|
|
|
|
event.match_runners_cards()
|
|
|
|
event.get_xml_res().write(args.file)
|
2022-02-21 11:51:02 +00:00
|
|
|
|
2022-02-06 00:12:32 +00:00
|
|
|
if __name__ == "__main__":
|
2022-02-21 11:51:02 +00:00
|
|
|
main()
|