La til mulighet for å printe løperobjekt

This commit is contained in:
Trygve 2022-02-21 19:21:06 +01:00
parent 2d5753a31e
commit 62a067c577
2 changed files with 36 additions and 20 deletions

31
cli.py
View File

@ -4,6 +4,7 @@ import otime
import argparse
import datetime
from rich import print
from rich import inspect
from rich.console import Console
from rich.columns import Columns
from rich.table import Table
@ -53,7 +54,7 @@ def print_class_result(runners, o_class):
for i in runners_ok:
#if i.status() == 'OK':
pos += 1
table.add_row(str(pos)+'.',i.fullname(), i.status(), str(datetime.timedelta(seconds=i.totaltime())))
table.add_row(str(pos)+'.',i.fullname(), i.club, str(datetime.timedelta(seconds=i.totaltime())))
console = Console()
console.print(table)
@ -104,6 +105,12 @@ def main():
show_runners.add_argument('--ttdb', required=True, help='ttime database file')
show_runners.add_argument('--mtr', required=True, help='mtr csv file')
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')
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')
@ -129,17 +136,31 @@ def main():
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)
otime.ttime_mtr_to_class(args.mtr, runner_list)
print_runners(runner_list)
if args.command == 'show_result':
elif args.command == 'show_runner':
courses = otime.courses_from_ttime_conf(args.ttcnf)
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)
otime.ttime_mtr_to_class(args.mtr, runner_list)
for n in runner_list:
if args.runner == n.fullname():
inspect(n)
break
else:
print('Runner not found. Use full name.')
elif args.command == 'show_result':
courses = otime.courses_from_ttime_conf(args.ttcnf)
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)
otime.ttime_mtr_to_class(args.mtr, runner_list)
for n in o_classes:
if args.o_class_str == n.name:
o_class = n
sel_classes = [n]
break
else:
print('Class not found')
sel_classes = o_classes
for o_class in sel_classes:
if args.splits:
print_class_splits(runner_list, o_class)
else:
@ -151,7 +172,7 @@ def main():
otime.ttime_mtr_to_class(args.mtr, runner_list)
print_o_classes(o_classes)
if args.command == 'create_xml':
elif args.command == 'create_xml':
courses = otime.courses_from_ttime_conf(args.ttcnf)
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)

View File

@ -37,27 +37,22 @@ class runner:
def res_splits(self):
control_map = self.check_codes()
splits = []
lastn = 0
for n in control_map:
if n != lastn+1:
splits.append(self.splits[n])
else:
# Dette må testes ordentlig seinere!
gap = n - lastn
split = 0
for i in range(gap):
split += self.splits[n-gap]
splits.append(split)
return splits
class course:
def __init__(self, name, codes):
self.name = name
self.codes = codes
def __repr__(self):
return f'name({self.name})'
class o_class:
def __init__(self, name, course):
self.name = name
self.course = course
def __repr__(self):
return f'name({self.name})'
def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
courses = []
@ -125,7 +120,7 @@ def ttime_db_to_class(ttime_file, o_class_list=[]):
eventorid = row[0]
country = ''
name = row[2].split(',')
first = name[1]
first = name[1].strip()
last = name[0]
try:
club = row[4]