Compare commits
2 Commits
b33cf0274a
...
2d5753a31e
Author | SHA1 | Date | |
---|---|---|---|
2d5753a31e | |||
170542fbd0 |
128
cli.py
Normal file → Executable file
128
cli.py
Normal file → Executable file
@ -1,7 +1,11 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
import otime
|
import otime
|
||||||
|
|
||||||
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
|
from rich import print
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
from rich.columns import Columns
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
def print_runners(Runners):
|
def print_runners(Runners):
|
||||||
table = Table(title="Runners")
|
table = Table(title="Runners")
|
||||||
@ -30,21 +34,48 @@ def print_time(Runners):
|
|||||||
tottime = 0
|
tottime = 0
|
||||||
table.add_row(i.fullname(), i.o_class.name, str(i.splits), str(i.check_codes()), str(tottime))
|
table.add_row(i.fullname(), i.o_class.name, str(i.splits), str(i.check_codes()), str(tottime))
|
||||||
|
|
||||||
|
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 = []
|
||||||
|
for n in runners:
|
||||||
|
if n.status() == 'OK':
|
||||||
|
runners_ok.append(n)
|
||||||
|
runners_ok.sort(key=lambda x: x.totaltime())
|
||||||
|
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())))
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
console.print(table)
|
console.print(table)
|
||||||
def print_class_splits(runners, o_class):
|
def print_class_splits(runners, o_class):
|
||||||
table = Table(title=o_class.name)
|
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("Name", justify="right", style="cyan", no_wrap=True)
|
||||||
table.add_column("club", style="magenta")
|
table.add_column("club", style="magenta")
|
||||||
table.add_column("card", style="red")
|
if o_class:
|
||||||
table.add_column("class", justify="right", style="green")
|
for i in o_class.course.codes:
|
||||||
table.add_column("controls", justify="right", style="blue")
|
table.add_column(str(i))
|
||||||
for i in o_class.course.codes:
|
runners = otime.get_runners_in_class(runners, o_class)
|
||||||
table.add_column(str(i))
|
runners_ok = []
|
||||||
|
for n in runners:
|
||||||
for i in runners:
|
if n.status() == 'OK':
|
||||||
if i.o_class == o_class:
|
runners_ok.append(n)
|
||||||
table.add_row(i.fullname(), i.club ,str(i.card))
|
runners_ok.sort(key=lambda x: x.totaltime())
|
||||||
|
pos = 0
|
||||||
|
for i in runners_ok:
|
||||||
|
pos += 1
|
||||||
|
list_string = map(lambda x:str(datetime.timedelta(seconds=x)), i.res_splits())
|
||||||
|
table.add_row(str(pos)+'.', i.fullname(), i.club, *list_string)
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
console.print(table)
|
console.print(table)
|
||||||
@ -60,15 +91,72 @@ def print_o_classes(class_list):
|
|||||||
console = Console()
|
console = Console()
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
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')
|
||||||
|
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.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':
|
||||||
|
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)
|
||||||
|
print_runners(runner_list)
|
||||||
|
if 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
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print('Class not found')
|
||||||
|
if args.splits:
|
||||||
|
print_class_splits(runner_list, o_class)
|
||||||
|
else:
|
||||||
|
print_class_result(runner_list, o_class)
|
||||||
|
elif args.command == 'show_classes':
|
||||||
|
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)
|
||||||
|
print_o_classes(o_classes)
|
||||||
|
|
||||||
|
if 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)
|
||||||
|
otime.ttime_mtr_to_class(args.mtr, runner_list)
|
||||||
|
otime.gen_xml_result(runner_list, o_classes).write(args.file)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
courses = otime.courses_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt')
|
main()
|
||||||
o_classes = otime.classes_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt', courses)
|
|
||||||
runner_list = otime.ttime_db_to_class('sc_2021_ttime/db_eventor.csv', o_classes)
|
|
||||||
#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_class_splits(runner_list, o_classes[0])
|
|
||||||
#print(otime.check_codes(runner_list[1]))
|
|
||||||
otime.gen_xml_result(runner_list, o_classes)
|
|
||||||
|
35
otime.py
35
otime.py
@ -1,13 +1,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import csv
|
import csv
|
||||||
import re
|
import re
|
||||||
from rich.console import Console
|
|
||||||
from rich.table import Table
|
|
||||||
from rich.traceback import install
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
install(show_locals=True)
|
|
||||||
class runner:
|
class runner:
|
||||||
def __init__(self, first, last, club, country, card, o_class, controls, splits):
|
def __init__(self, eventorid, first, last, club, country, card, o_class, controls, splits):
|
||||||
|
self.id = eventorid
|
||||||
self.first = first
|
self.first = first
|
||||||
self.last = last
|
self.last = last
|
||||||
self.club = club
|
self.club = club
|
||||||
@ -16,7 +13,6 @@ class runner:
|
|||||||
self.o_class = o_class
|
self.o_class = o_class
|
||||||
self.controls = controls
|
self.controls = controls
|
||||||
self.splits = splits
|
self.splits = splits
|
||||||
self.id = 0
|
|
||||||
self.s_time = 0
|
self.s_time = 0
|
||||||
self.f_time = 0
|
self.f_time = 0
|
||||||
|
|
||||||
@ -65,7 +61,7 @@ class o_class:
|
|||||||
|
|
||||||
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 = []
|
||||||
conf = open(ttime_file).readlines()
|
conf = open(ttime_file, 'r', encoding='latin_1').readlines()
|
||||||
for line in conf:
|
for line in conf:
|
||||||
if '-codes' in line:
|
if '-codes' in line:
|
||||||
code_list = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
|
code_list = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
|
||||||
@ -78,7 +74,7 @@ def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
|
|||||||
return courses
|
return courses
|
||||||
def classes_from_ttime_conf(ttime_file, courses):
|
def classes_from_ttime_conf(ttime_file, courses):
|
||||||
o_classes = []
|
o_classes = []
|
||||||
conf = open(ttime_file).readlines()
|
conf = open(ttime_file, 'r', encoding='latin_1').readlines()
|
||||||
for line in conf:
|
for line in conf:
|
||||||
if '-courses' in line:
|
if '-courses' in line:
|
||||||
raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
|
raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
|
||||||
@ -126,6 +122,7 @@ def ttime_db_to_class(ttime_file, o_class_list=[]):
|
|||||||
csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',)
|
csvreader = csv.reader(open(ttime_file, 'r', encoding='latin_1'), delimiter=';',)
|
||||||
runnerarray = []
|
runnerarray = []
|
||||||
for row in csvreader:
|
for row in csvreader:
|
||||||
|
eventorid = row[0]
|
||||||
country = ''
|
country = ''
|
||||||
name = row[2].split(',')
|
name = row[2].split(',')
|
||||||
first = name[1]
|
first = name[1]
|
||||||
@ -149,7 +146,7 @@ def ttime_db_to_class(ttime_file, o_class_list=[]):
|
|||||||
runner_o_class = i
|
runner_o_class = i
|
||||||
break
|
break
|
||||||
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
# TODO: Gjør sånn at den lager nye o klasser om den ikke finnes fra før
|
||||||
runnerarray.append(runner(first, last, club, country, card, runner_o_class, [], []))
|
runnerarray.append(runner(eventorid, first, last, club, country, card, runner_o_class, [], []))
|
||||||
return runnerarray
|
return runnerarray
|
||||||
|
|
||||||
def ttime_mtr_to_class(csv_file, runnerarray):
|
def ttime_mtr_to_class(csv_file, runnerarray):
|
||||||
@ -232,6 +229,10 @@ def xml_child(parent, tag, content):
|
|||||||
|
|
||||||
def gen_xml_result(runners, o_classes):
|
def gen_xml_result(runners, o_classes):
|
||||||
root = ET.Element('ResultList')
|
root = ET.Element('ResultList')
|
||||||
|
root.set('iofVersion', '3.0')
|
||||||
|
root.set('createTime', datetime.datetime.now().isoformat())
|
||||||
|
root.set('creator', 'oTime')
|
||||||
|
root.set('status', 'Complete')
|
||||||
tree = ET.ElementTree(root)
|
tree = ET.ElementTree(root)
|
||||||
event = ET.SubElement(root, 'Event')
|
event = ET.SubElement(root, 'Event')
|
||||||
xml_child(event, 'Name', 'PLACEHOLDER')
|
xml_child(event, 'Name', 'PLACEHOLDER')
|
||||||
@ -248,7 +249,7 @@ def gen_xml_result(runners, o_classes):
|
|||||||
person_result = ET.SubElement(class_result, 'PersonResult')
|
person_result = ET.SubElement(class_result, 'PersonResult')
|
||||||
#<Person>
|
#<Person>
|
||||||
person = ET.SubElement(person_result, 'Person')
|
person = ET.SubElement(person_result, 'Person')
|
||||||
xml_child(person, 'Id', '0')
|
xml_child(person, 'Id', n.id)
|
||||||
#<Name>
|
#<Name>
|
||||||
name = ET.SubElement(person, 'Name')
|
name = ET.SubElement(person, 'Name')
|
||||||
xml_child(name, 'Family', n.last)
|
xml_child(name, 'Family', n.last)
|
||||||
@ -277,11 +278,19 @@ def gen_xml_result(runners, o_classes):
|
|||||||
xml_child(result, 'Position', n.rank(runners))
|
xml_child(result, 'Position', n.rank(runners))
|
||||||
xml_child(result, 'Status', n.status())
|
xml_child(result, 'Status', n.status())
|
||||||
#<SplitTime>
|
#<SplitTime>
|
||||||
for code,split in zip(n.o_class.course.codes, n.res_splits()):
|
for code,split in zip(n.o_class.course.codes, n.res_splits(), strict=True):
|
||||||
st = ET.SubElement(result, 'SplitTime')
|
st = ET.SubElement(result, 'SplitTime')
|
||||||
xml_child(st, 'ControlCode', code)
|
xml_child(st, 'ControlCode', code)
|
||||||
xml_child(st, 'Time', split)
|
xml_child(st, 'Time', split)
|
||||||
#</SplitTime>
|
#</SplitTime>
|
||||||
|
elif n.status() == 'Disqualified':
|
||||||
|
xml_child(result, 'Status', n.status())
|
||||||
|
for code in n.o_class.course.codes:
|
||||||
|
st = ET.SubElement(result, 'SplitTime')
|
||||||
|
xml_child(st, 'ControlCode', code)
|
||||||
|
for control,split in zip(n.controls, n.splits):
|
||||||
|
if code == control:
|
||||||
|
xml_child(st, 'Time', split)
|
||||||
else:
|
else:
|
||||||
xml_child(result, 'Status', n.status())
|
xml_child(result, 'Status', n.status())
|
||||||
else:
|
else:
|
||||||
@ -289,6 +298,6 @@ def gen_xml_result(runners, o_classes):
|
|||||||
#</Result>
|
#</Result>
|
||||||
#</PersonResult>
|
#</PersonResult>
|
||||||
#</Class>
|
#</Class>
|
||||||
|
ET.indent(root, space=' ', level=0)
|
||||||
tree.write('Resultater.xml')
|
tree.write('Resultater.xml')
|
||||||
return ET.dump(root)
|
return tree
|
||||||
|
Loading…
Reference in New Issue
Block a user