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

39
cli.py
View File

@ -4,6 +4,7 @@ import otime
import argparse import argparse
import datetime import datetime
from rich import print from rich import print
from rich import inspect
from rich.console import Console from rich.console import Console
from rich.columns import Columns from rich.columns import Columns
from rich.table import Table from rich.table import Table
@ -53,7 +54,7 @@ def print_class_result(runners, o_class):
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.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 = Console()
console.print(table) console.print(table)
@ -104,6 +105,12 @@ def main():
show_runners.add_argument('--ttdb', required=True, help='ttime database 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('--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 = 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('--ttcnf', required=True, help='ttime configuration file')
show_runners.add_argument('--ttdb', required=True, help='ttime database file') show_runners.add_argument('--ttdb', required=True, help='ttime database file')
@ -129,21 +136,35 @@ def main():
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes) runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)
otime.ttime_mtr_to_class(args.mtr, runner_list) otime.ttime_mtr_to_class(args.mtr, runner_list)
print_runners(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) courses = otime.courses_from_ttime_conf(args.ttcnf)
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses) o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes) runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)
otime.ttime_mtr_to_class(args.mtr, runner_list) otime.ttime_mtr_to_class(args.mtr, runner_list)
for n in o_classes: for n in o_classes:
if args.o_class_str == n.name: if args.o_class_str == n.name:
o_class = n sel_classes = [n]
break break
else: else:
print('Class not found') sel_classes = o_classes
if args.splits: for o_class in sel_classes:
print_class_splits(runner_list, o_class) if args.splits:
else: print_class_splits(runner_list, o_class)
print_class_result(runner_list, o_class) else:
print_class_result(runner_list, o_class)
elif args.command == 'show_classes': elif args.command == 'show_classes':
courses = otime.courses_from_ttime_conf(args.ttcnf) courses = otime.courses_from_ttime_conf(args.ttcnf)
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses) o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses)
@ -151,7 +172,7 @@ def main():
otime.ttime_mtr_to_class(args.mtr, runner_list) otime.ttime_mtr_to_class(args.mtr, runner_list)
print_o_classes(o_classes) print_o_classes(o_classes)
if args.command == 'create_xml': elif args.command == 'create_xml':
courses = otime.courses_from_ttime_conf(args.ttcnf) courses = otime.courses_from_ttime_conf(args.ttcnf)
o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses) o_classes = otime.classes_from_ttime_conf(args.ttcnf, courses)
runner_list = otime.ttime_db_to_class(args.ttdb, o_classes) runner_list = otime.ttime_db_to_class(args.ttdb, o_classes)

View File

@ -37,27 +37,22 @@ class runner:
def res_splits(self): def res_splits(self):
control_map = self.check_codes() control_map = self.check_codes()
splits = [] splits = []
lastn = 0
for n in control_map: for n in control_map:
if n != lastn+1: splits.append(self.splits[n])
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 return splits
class course: class course:
def __init__(self, name, codes): def __init__(self, name, codes):
self.name = name self.name = name
self.codes = codes self.codes = codes
def __repr__(self):
return f'name({self.name})'
class o_class: class o_class:
def __init__(self, name, course): def __init__(self, name, course):
self.name = name self.name = name
self.course = course self.course = course
def __repr__(self):
return f'name({self.name})'
def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'): def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
courses = [] courses = []
@ -125,7 +120,7 @@ def ttime_db_to_class(ttime_file, o_class_list=[]):
eventorid = row[0] eventorid = row[0]
country = '' country = ''
name = row[2].split(',') name = row[2].split(',')
first = name[1] first = name[1].strip()
last = name[0] last = name[0]
try: try:
club = row[4] club = row[4]