Compare commits

...

2 Commits

Author SHA1 Message Date
f1612cf838 Starta på søke tui 2023-11-24 00:42:02 +01:00
24f8c30c81 Fiksa gaflinger 2023-11-24 00:41:38 +01:00
5 changed files with 45 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import iof_xml
import pdf
from pdf import format_m_s
from rich import print
import search_tui
# Main entrypoint for now. Cli with two options; init will make the files needed and run will start the program from the specified directory
def main():
@ -27,6 +28,10 @@ def main():
parser_init.add_argument('--port', required=False, dest='port', action='store', help='specify a serial port')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
parser_init = subparsers.add_parser('viewer', help='View otime data')
parser_init.add_argument('--dir', required=False, dest='dir', action='store', default='./', help='specify a directory')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
args = parser.parse_args()
if not args.xml_path:
@ -37,6 +42,8 @@ def main():
init_dir(args.dir, args.entries_file, args.courses_file)
case 'run':
run(args.port, args.dir, args.xml_path)
case 'viewer':
search_tui.main(args.dir)
def init_dir(project_dir, entries_xml_file, courses_xml_file):
# Lager mappe med en config fil, en csv fil med løpere og en fil med mtr data

View File

@ -38,7 +38,7 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
with open(csv_path, 'r') as f:
data = [i.split(';') for i in f.readlines()]
for i in data: i[2] = i[2].split(',')
runners = [otime.Runner(id=i[0], status_override=i[1], first=i[2][0], last=i[2][1].strip(), o_class=i[3], club=i[4], card_id=int(i[5]), fork=i[6], start_time=i[7]) for i in data]
runners = [otime.Runner(id=i[0], status_override=i[1], first=i[2][0], last=i[2][1].strip(), o_class=i[3], club=i[4], card_id=int(i[5]), fork=int(i[6]), start_time=i[7]) for i in data]
event.card_dumps = card_dumps
event.runners = runners
return event

View File

@ -172,7 +172,7 @@ def courses_from_xml(xml_file):
controls.remove('STA1')
controls.remove('FIN1')
controls = [int(l) for l in controls]
courseobjs.append(otime.Course(name, controls))
courseobjs.append(otime.Course(name, [controls]))
return courseobjs
def event_from_xml_entries(xml_file):

View File

@ -161,12 +161,11 @@ class CardDump:
# Stored in Event.courses
class Course:
def __init__(self, name, codes, forked=False, variations=None):
def __init__(self, name, codes, forked=False):
self.name = name
# Codes is a list of courses
self.codes = codes
self.forked = forked
# Variations is a list
self.variations = variations
def __repr__(self):
return f'name({self.name})'
@ -270,7 +269,7 @@ class Event:
course = self.get_course(o_class.course)
if not self.get_card_dump(runner.card_id):
return 'Active'
if contains(course.codes, self.get_card_dump(runner.card_id).controls):
if contains(course.codes[runner.fork], self.get_card_dump(runner.card_id).controls):
return 'OK'
else:
return 'MissingPunch'
@ -306,8 +305,8 @@ class Event:
return None
split_iter = zip(card_dump.controls, card_dump.splits).__iter__()
splits = [0] * len(course.codes)
for n, control in enumerate(course.codes):
splits = [0] * len(course.codes[runner.fork])
for n, control in enumerate(course.codes[runner.fork]):
if control not in card_dump.controls:
continue
while True:
@ -404,7 +403,7 @@ def courses_from_ttime_conf(ttime_file):
n = n.split(',')
loops += 1
n = list(map(int, n))
courses.append(Course('course_'+str(loops), n))
courses.append(Course('course_'+str(loops), [n]))
return courses
def classes_from_ttime_conf(ttime_file, courses):

30
otime/search_tui.py Normal file
View File

@ -0,0 +1,30 @@
from textual.app import App, ComposeResult
from textual.widgets import DataTable
import otime
import file_io
from pdf import format_m_s
global ROWS
class TableApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
global ROWS
table = self.query_one(DataTable)
table.add_columns(*ROWS[0])
table.add_rows(ROWS[1:])
def main(path):
event = file_io.event_from_yaml_and_csv(path + '/config.yaml', path + '/mtr.yaml', path + '/runners.csv')
result = event.get_result()
global ROWS
ROWS = []
for o_class in result:
ROWS += [(str(i.id), str(i.place), i.fullname(), i.o_class, i.club, str(i.card_id), format_m_s(i.total_time), str(i.controls)) for i in o_class.runner_results]
print(ROWS)
app = TableApp()
app.run()
if __name__ == "__main__":
main()