Lagde funskjoner for å lese inn og ut seperate csv, mtr og db filer

This commit is contained in:
Trygve 2023-11-17 21:49:33 +01:00
parent e5a672ac70
commit 7591523b37
2 changed files with 32 additions and 5 deletions

View File

@ -19,11 +19,23 @@ def write_card_dumps(event, file_path):
card_dumps = deepcopy(event.card_dumps) card_dumps = deepcopy(event.card_dumps)
with open(file_path, 'w') as f: with open(file_path, 'w') as f:
dump(card_dumps, f) dump(card_dumps, f)
def event_from_config_and_card_dumps(config_path, mtr_path): def write_runners_csv(event, file_path):
with open(file_path, 'w') as f:
for i in event.runners:
f.write(f'{i.id};{i.status_override};{i.first}, {i.last};{i.o_class};{i.club};{i.card_id};{i.fork};{i.start_time}\n')
def event_from_yaml_and_csv(config_path, mtr_path, csv_path):
with open(mtr_path, 'r') as f: with open(mtr_path, 'r') as f:
card_dumps = load(f, Loader=Loader) card_dumps = load(f, Loader=Loader)
with open(config_path, 'r') as f: with open(config_path, 'r') as f:
event = load(f, Loader=Loader) event = load(f, Loader=Loader)
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=i[5], fork=i[6], start_time=i[7]) for i in data]
event.card_dumps = card_dumps event.card_dumps = card_dumps
event.runners = runners
return event return event

View File

@ -3,16 +3,31 @@ sys.path.insert(0, '../../otime')
import otime import otime
import pdf import pdf
import iof_xml import iof_xml
import file_io
def main(): def ttime_testing():
event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe') event = otime.Event(0, 'TEEEST', start_time=None, end_time=None,organiser='Tygbe')
event.read_ttime_cnf('tt.cnf') event.read_ttime_cnf('tt.cnf')
event.read_ttime_db('db.csv') event.read_ttime_db('db.csv')
event.read_mtr_file('mtr.csv') event.read_mtr_file('mtr.csv')
pdf.create_split_result_list(event, 'output/result.pdf') pdf.create_split_result_list(event, 'output/result.pdf')
iof_xml.create_result_file(event, 'output/result.xml') iof_xml.create_result_file(event, '/home/trygve/Prosjekter/simple-liveresults/resultater/Resultater.xml')
print(event.get_runner_status('1400')) print(event.get_runner_status('1400'))
results = event.get_result() results = event.get_result()
print([pdf.format_m_s(i) for i in event.get_runner_splits('17')])
print([pdf.format_m_s(i) for i in event.get_card_dump(event.get_runner('17').card_id).splits])
file_io.write_config(event, 'output/config.yaml')
file_io.write_card_dumps(event, 'output/mtr.yaml')
file_io.write_runners_csv(event, 'output/runners.csv')
print(file_io.event_from_yaml_and_csv('output/config.yaml', 'output/mtr.yaml', 'output/runners.csv'))
def xml_testing():
event = iof_xml.event_from_xml_entries('entries.xml')
event.courses = iof_xml.courses_from_xml('course.xml')
file_io.write_config(event, 'output/config.yaml')
file_io.write_card_dumps(event, 'output/mtr.yaml')
file_io.write_runners_csv(event, 'output/runners.csv')
print(file_io.event_from_yaml_and_csv('output/config.yaml', 'output/mtr.yaml', 'output/runners.csv'))
if __name__ == '__main__': if __name__ == '__main__':
main() xml_testing()