diff --git a/otime/yaml_io.py b/otime/file_io.py similarity index 54% rename from otime/yaml_io.py rename to otime/file_io.py index 8b8714b..0607a13 100644 --- a/otime/yaml_io.py +++ b/otime/file_io.py @@ -19,11 +19,23 @@ def write_card_dumps(event, file_path): card_dumps = deepcopy(event.card_dumps) with open(file_path, 'w') as 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: card_dumps = load(f, Loader=Loader) + with open(config_path, 'r') as f: 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.runners = runners return event \ No newline at end of file diff --git a/test_files/sc3_23/sc3_test.py b/test_files/sc3_23/sc3_test.py index c4cf475..5b7d6d7 100644 --- a/test_files/sc3_23/sc3_test.py +++ b/test_files/sc3_23/sc3_test.py @@ -3,16 +3,31 @@ sys.path.insert(0, '../../otime') import otime import pdf 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.read_ttime_cnf('tt.cnf') event.read_ttime_db('db.csv') event.read_mtr_file('mtr.csv') 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')) 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__': - main() \ No newline at end of file + xml_testing() \ No newline at end of file