Compare commits
2 Commits
95f10000bb
...
f1612cf838
Author | SHA1 | Date | |
---|---|---|---|
f1612cf838 | |||
24f8c30c81 |
@ -9,6 +9,7 @@ import iof_xml
|
|||||||
import pdf
|
import pdf
|
||||||
from pdf import format_m_s
|
from pdf import format_m_s
|
||||||
from rich import print
|
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
|
# 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():
|
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('--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.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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.xml_path:
|
if not args.xml_path:
|
||||||
@ -37,6 +42,8 @@ def main():
|
|||||||
init_dir(args.dir, args.entries_file, args.courses_file)
|
init_dir(args.dir, args.entries_file, args.courses_file)
|
||||||
case 'run':
|
case 'run':
|
||||||
run(args.port, args.dir, args.xml_path)
|
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):
|
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
|
# Lager mappe med en config fil, en csv fil med løpere og en fil med mtr data
|
||||||
|
@ -38,7 +38,7 @@ def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
|
|||||||
with open(csv_path, 'r') as f:
|
with open(csv_path, 'r') as f:
|
||||||
data = [i.split(';') for i in f.readlines()]
|
data = [i.split(';') for i in f.readlines()]
|
||||||
for i in data: i[2] = i[2].split(',')
|
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.card_dumps = card_dumps
|
||||||
event.runners = runners
|
event.runners = runners
|
||||||
return event
|
return event
|
@ -172,7 +172,7 @@ def courses_from_xml(xml_file):
|
|||||||
controls.remove('STA1')
|
controls.remove('STA1')
|
||||||
controls.remove('FIN1')
|
controls.remove('FIN1')
|
||||||
controls = [int(l) for l in controls]
|
controls = [int(l) for l in controls]
|
||||||
courseobjs.append(otime.Course(name, controls))
|
courseobjs.append(otime.Course(name, [controls]))
|
||||||
return courseobjs
|
return courseobjs
|
||||||
|
|
||||||
def event_from_xml_entries(xml_file):
|
def event_from_xml_entries(xml_file):
|
||||||
|
@ -161,12 +161,11 @@ class CardDump:
|
|||||||
|
|
||||||
# Stored in Event.courses
|
# Stored in Event.courses
|
||||||
class Course:
|
class Course:
|
||||||
def __init__(self, name, codes, forked=False, variations=None):
|
def __init__(self, name, codes, forked=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
# Codes is a list of courses
|
||||||
self.codes = codes
|
self.codes = codes
|
||||||
self.forked = forked
|
self.forked = forked
|
||||||
# Variations is a list
|
|
||||||
self.variations = variations
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'name({self.name})'
|
return f'name({self.name})'
|
||||||
@ -270,7 +269,7 @@ class Event:
|
|||||||
course = self.get_course(o_class.course)
|
course = self.get_course(o_class.course)
|
||||||
if not self.get_card_dump(runner.card_id):
|
if not self.get_card_dump(runner.card_id):
|
||||||
return 'Active'
|
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'
|
return 'OK'
|
||||||
else:
|
else:
|
||||||
return 'MissingPunch'
|
return 'MissingPunch'
|
||||||
@ -306,8 +305,8 @@ class Event:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
split_iter = zip(card_dump.controls, card_dump.splits).__iter__()
|
split_iter = zip(card_dump.controls, card_dump.splits).__iter__()
|
||||||
splits = [0] * len(course.codes)
|
splits = [0] * len(course.codes[runner.fork])
|
||||||
for n, control in enumerate(course.codes):
|
for n, control in enumerate(course.codes[runner.fork]):
|
||||||
if control not in card_dump.controls:
|
if control not in card_dump.controls:
|
||||||
continue
|
continue
|
||||||
while True:
|
while True:
|
||||||
@ -404,7 +403,7 @@ def courses_from_ttime_conf(ttime_file):
|
|||||||
n = n.split(',')
|
n = n.split(',')
|
||||||
loops += 1
|
loops += 1
|
||||||
n = list(map(int, n))
|
n = list(map(int, n))
|
||||||
courses.append(Course('course_'+str(loops), n))
|
courses.append(Course('course_'+str(loops), [n]))
|
||||||
return courses
|
return courses
|
||||||
|
|
||||||
def classes_from_ttime_conf(ttime_file, courses):
|
def classes_from_ttime_conf(ttime_file, courses):
|
||||||
|
30
otime/search_tui.py
Normal file
30
otime/search_tui.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user