mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-21 19:16:30 +00:00
Added data to csv export
This commit is contained in:
parent
86f694756d
commit
c76eea9d76
@ -10,6 +10,7 @@ import sys
|
||||
|
||||
from model import Emission
|
||||
|
||||
|
||||
class Config:
|
||||
|
||||
# Total of emissions of all pollutants in mg for n steps of simulation without acting on areas
|
||||
|
@ -1,9 +1,12 @@
|
||||
import argparse
|
||||
import csv
|
||||
import sys
|
||||
import time
|
||||
from traci import trafficlight
|
||||
import traci
|
||||
from typing import List
|
||||
import datetime
|
||||
import os
|
||||
|
||||
from parse import search
|
||||
from shapely.geometry import LineString
|
||||
@ -121,6 +124,33 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle], current_step, confi
|
||||
|
||||
def get_reduction_percentage(ref,total):
|
||||
return (ref - total) / ref * 100
|
||||
|
||||
def export_data_to_csv(config, grid):
|
||||
|
||||
now = datetime.datetime.now()
|
||||
current_date = now.strftime("%Y_%m_%d_%H_%M_%S")
|
||||
|
||||
'''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:
|
||||
try:
|
||||
csv_writer = csv.writer(emission_file, delimiter = '', quoting=csv.QUOTE_MINIMAL)
|
||||
a = list(range(config.n_steps))
|
||||
csv_writer.writerow(['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}'])
|
||||
for emission in area.emissions_by_step:
|
||||
writer.writerow([emission.value()])
|
||||
|
||||
|
||||
finally:
|
||||
emission_file.close()'''
|
||||
|
||||
|
||||
def run(config, logger):
|
||||
grid = list()
|
||||
@ -131,6 +161,7 @@ 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)
|
||||
@ -149,8 +180,10 @@ def run(config, logger):
|
||||
|
||||
finally:
|
||||
traci.close(False)
|
||||
|
||||
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}')
|
||||
|
||||
total_emissions = Emission()
|
||||
for area in grid:
|
||||
@ -207,7 +240,7 @@ def main(args):
|
||||
config.check_config()
|
||||
|
||||
logger.info(f'Loaded configuration file : {args.configfile}')
|
||||
logger.info(f'Simulated time : {args.steps}')
|
||||
logger.info(f'Simulated time : {args.steps}s')
|
||||
run(config, logger)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,3 +1,4 @@
|
||||
import collections
|
||||
from traci._trafficlight import Logic as SUMO_Logic
|
||||
from typing import Tuple, Set
|
||||
|
||||
@ -5,8 +6,6 @@ from shapely.geometry import Point, LineString
|
||||
from shapely.geometry import Polygon
|
||||
from shapely.geometry.base import BaseGeometry
|
||||
|
||||
import collections
|
||||
|
||||
|
||||
class Lane:
|
||||
|
||||
@ -107,9 +106,8 @@ class Area:
|
||||
return sum
|
||||
|
||||
def sum_emissions_into_window(self, current_step, window_size):
|
||||
#print(self.emissions_by_step)
|
||||
em_obj = self.emissions_by_step[current_step]
|
||||
self.window.appendleft(em_obj.value())
|
||||
|
||||
self.window.appendleft(self.emissions_by_step[current_step].value())
|
||||
|
||||
sum = 0
|
||||
for i in range(self.window.__len__()):
|
||||
|
Loading…
Reference in New Issue
Block a user