otime-testing/cli.py

56 lines
2.0 KiB
Python
Raw Normal View History

2022-02-06 00:12:32 +00:00
import otime
import datetime
2022-02-06 00:12:32 +00:00
from rich.console import Console
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")
table.add_column("controls", justify="right", style="blue")
2022-02-06 00:12:32 +00:00
for i in Runners:
table.add_row(i.fullname(), i.club ,str(i.card), i.o_class.name, str(i.controls))
2022-02-06 00:12:32 +00:00
console = Console()
console.print(table)
def print_time(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", style="green")
table.add_column("controls", justify="right", style="blue")
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-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:
table.add_row(i.name, i.course.name , str(i.course.codes))
console = Console()
console.print(table)
if __name__ == "__main__":
courses = otime.courses_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt')
o_classes = otime.classes_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt', courses)
runner_list = otime.xml_to_class('entries_KOK_Sommercup,_løp_2.xml', o_classes)
otime.ttime_mtr_to_class('sc_2021_ttime/mtr.csv', runner_list)
print_runners(runner_list)
print_time(runner_list)
#print_o_classes(o_classes)
#print(otime.check_codes(runner_list[1]))