From 229ab72279c4058ef5c120270ed2337ed95c2078 Mon Sep 17 00:00:00 2001 From: Ahp06 Date: Sun, 16 Dec 2018 15:44:33 +0100 Subject: [PATCH] Added data to csv export --- sumo_project/emissions.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index b72792b..375d57f 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -133,23 +133,21 @@ def export_data_to_csv(config, grid): '''if not os.path.exists(f'csv/{current_date}'): os.makedirs(f'csv/{current_date}')''' - '''with open(f'test.csv', mode='w', newline = '') as emission_file: + with open(f'test.csv', mode='w', newline = '') as emission_file: try: - csv_writer = csv.writer(emission_file, delimiter = '', quoting=csv.QUOTE_MINIMAL) - a = list(range(config.n_steps)) + csv_writer = csv.writer(emission_file, delimiter = ' ', quoting=csv.QUOTE_MINIMAL) csv_writer.writerow(['steps']) + a = list(range(config.n_steps)) for item in a: csv_writer.writerow([item]) for area in grid: - writer = csv.writer(emission_file, delimiter = ' ', quoting=csv.QUOTE_MINIMAL) - writer.writerow([f'{area.name}']) + csv_writer.writerow([f'{area.name}']) for emission in area.emissions_by_step: - writer.writerow([emission.value()]) - + csv_writer.writerow([emission.value()]) finally: - emission_file.close()''' + emission_file.close() def run(config, logger): @@ -161,7 +159,6 @@ def run(config, logger): start = time.perf_counter() grid = init_grid(traci.simulation.getNetBoundary(), config.areas_number, config.window_size) - export_data_to_csv(config,grid) add_data_to_areas(grid) loading_time = round(time.perf_counter() - start, 2) @@ -180,7 +177,8 @@ def run(config, logger): finally: traci.close(False) - + export_data_to_csv(config,grid) + simulation_time = round(time.perf_counter() - start, 2) logger.info(f'End of the simulation ({simulation_time}s)') logger.info(f'Real-time factor : {config.n_steps/simulation_time}')