Compare commits

..

2 Commits

Author SHA1 Message Date
0098c7fe2a La til GTK frontend for å generere xml filer 2022-02-22 18:06:31 +01:00
62a067c577 La til mulighet for å printe løperobjekt 2022-02-21 19:21:06 +01:00
3 changed files with 184 additions and 20 deletions

31
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,17 +136,31 @@ 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
for o_class in sel_classes:
if args.splits: if args.splits:
print_class_splits(runner_list, o_class) print_class_splits(runner_list, o_class)
else: else:
@ -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]

148
xml_results_gui.py Normal file
View File

@ -0,0 +1,148 @@
import sys
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw
import otime
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.set_default_size(500, 300)
self.set_title("ttime xml resultat generator")
self.box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.box1.set_halign(Gtk.Align.CENTER)
self.box2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.mclamp = Adw.Clamp()
self.box1.append(self.mclamp)
self.mclamp.set_child(self.box2)
self.mainlist = Gtk.ListBox()
self.mainlist.set_selection_mode(Gtk.SelectionMode.NONE)
self.mainlist.set_margin_top(16)
self.mainlist.set_margin_bottom(8)
self.mainlist.get_style_context().add_class('boxed-list')
self.set_child(self.box1)
self.box2.append(self.mainlist)
self.cnf_row = Adw.ActionRow()
self.cnf_row.set_title('tTime konfigurasjons-fil')
self.cnf_row.set_subtitle('Ingen fil valgt')
self.mainlist.append(self.cnf_row)
self.cnf_btn_box = Gtk.Box()
self.cnf_f_btn = Gtk.Button(label='tTime konfigurasjon')
self.cnf_f_btn.set_valign(Gtk.Align.CENTER)
self.cnf_f_btn.set_icon_name("document-open-symbolic")
self.cnf_btn_box.append(self.cnf_f_btn)
self.cnf_row.add_suffix(self.cnf_btn_box)
self.cnf_f_dialog = Gtk.FileChooserNative.new(title="Velg konfigurasfila",
parent=self, action=Gtk.FileChooserAction.OPEN)
self.cnf_f_dialog.connect("response", self.sel_cnf)
self.cnf_f_btn.connect("clicked", self.show_cnf_dialog)
self.db_row = Adw.ActionRow()
self.db_row.set_title('tTime database-fil')
self.db_row.set_subtitle('Ingen fil valgt')
self.mainlist.append(self.db_row)
self.db_btn_box = Gtk.Box()
self.db_f_btn = Gtk.Button(label='tTime database')
self.db_f_btn.set_valign(Gtk.Align.CENTER)
self.db_f_btn.set_icon_name("document-open-symbolic")
self.db_btn_box.append(self.db_f_btn)
self.db_row.add_suffix(self.db_btn_box)
self.db_f_dialog = Gtk.FileChooserNative.new(title="Velg databasefila",
parent=self, action=Gtk.FileChooserAction.OPEN)
self.db_f_dialog.connect("response", self.sel_db)
self.db_f_btn.connect("clicked", self.show_db_dialog)
self.mtr_row = Adw.ActionRow()
self.mtr_row.set_title('MTR fil')
self.mtr_row.set_subtitle('Ingen fil valgt')
self.mainlist.append(self.mtr_row)
self.mtr_btn_box = Gtk.Box()
self.mtr_f_btn = Gtk.Button(label='mtr')
self.mtr_f_btn.set_valign(Gtk.Align.CENTER)
self.mtr_f_btn.set_icon_name("document-open-symbolic")
self.mtr_btn_box.append(self.mtr_f_btn)
self.mtr_row.add_suffix(self.mtr_btn_box)
self.mtr_f_dialog = Gtk.FileChooserNative.new(title="Velg mtr fila",
parent=self, action=Gtk.FileChooserAction.OPEN)
self.mtr_f_dialog.connect("response", self.sel_mtr)
self.mtr_f_btn.connect("clicked", self.show_mtr_dialog)
self.save_btn = Gtk.Button(label="Generer xml fil")
self.save_btn.set_halign(Gtk.Align.CENTER)
self.save_btn.get_style_context().add_class('suggested-action')
self.box2.append(self.save_btn)
self.save_dialog = Gtk.FileChooserNative.new(title="lagre xml resultat fil",
parent=self, action=Gtk.FileChooserAction.SAVE)
self.save_dialog.connect("response", self.save_xml)
self.save_btn.connect("clicked", self.show_save_dialog)
def show_cnf_dialog(self, button):
self.cnf_f_dialog.show()
def show_db_dialog(self, button):
self.db_f_dialog.show()
def show_mtr_dialog(self, button):
self.mtr_f_dialog.show()
def show_save_dialog(self, button):
self.save_dialog.show()
def sel_cnf(self, dialog, response):
print('test')
if response == Gtk.ResponseType.ACCEPT:
file = dialog.get_file()
filename = file.get_path()
self.cnf_row.set_subtitle(filename)
global ttime_cnf_file
ttime_cnf_file = filename # Here you could handle opening or saving the file
def sel_db(self, dialog, response):
if response == Gtk.ResponseType.ACCEPT:
file = dialog.get_file()
filename = file.get_path()
self.db_row.set_subtitle(filename)
global ttime_db_file
ttime_db_file = filename # Here you could handle opening or saving the file
def sel_mtr(self, dialog, response):
if response == Gtk.ResponseType.ACCEPT:
file = dialog.get_file()
filename = file.get_path()
self.mtr_row.set_subtitle(filename)
global mtr_file
mtr_file = filename
def save_xml(self, dialog, response):
print(ttime_cnf_file, ttime_db_file, mtr_file)
if response == Gtk.ResponseType.ACCEPT:
file = dialog.get_file()
filename = file.get_path()
courses = otime.courses_from_ttime_conf(ttime_cnf_file)
o_classes = otime.classes_from_ttime_conf(ttime_cnf_file, courses)
runners = otime.ttime_db_to_class(ttime_db_file, o_classes)
otime.ttime_mtr_to_class(mtr_file, runners)
otime.gen_xml_result(runners, o_classes).write(filename)
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.win = MainWindow(application=app)
self.win.present()
ttime_cnf_file = ''
ttime_db_file = ''
mtr_file = ''
def main():
app = MyApp(application_id='me.trygve.gtktest')
app.run(sys.argv)
if __name__ == '__main__':
main()