1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-25 04:56:30 +00:00

Reformat code

This commit is contained in:
Ahp06 2019-01-22 13:19:46 +01:00
parent b33e96ba60
commit f00e933fe6
2 changed files with 39 additions and 42 deletions

View File

@ -15,6 +15,7 @@ import os
import sys
from model import Emission
from data import Data
class Config:
@ -27,10 +28,13 @@ class Config:
ref200 = Emission(co2=42816869.05436445, co=1128465.0343051048, nox=18389.648337283958, hc=6154.330914019103,
pmx=885.0829265236318)
def __init__(self):
def __init__(self,config_file, data : Data):
"""
Default constructor
"""
self.import_config_file(config_file)
self.init_traci(data.dir)
self.check_config()
def import_config_file(self, config_file):
"""

View File

@ -49,10 +49,9 @@ class RunProcess(multiprocessing.Process):
if not os.path.exists('files/logs'):
os.makedirs('logs')
# log_filename = f'files/logs/{logger_name}_{current_date}.log'
log_filename = f'files/logs/{current_date}.log'
conf_name = self.config.config_filename.replace('.json', '')
log_filename = f'files/logs/{self.data.dump_name}_{conf_name}_{current_date}.log'
self.logger = logging.getLogger(f'{self.data.dir}_{conf_name}')
self.logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
@ -144,34 +143,6 @@ class RunProcess(multiprocessing.Process):
self.export_data_to_csv()
self.logger.info(f'Exported data into the csv folder')
def add_options(parser):
"""
Add command line options
:param parser: The command line parser
:return:
"""
# TODO: Faire que -areas & -simulation_dir soit requis si -new_dump
# Faire que -c soit requis si -run
parser.add_argument("-new_dump", "--new_dump", type=str,
required=False, help='Load and create a new data dump with the configuration file chosen')
parser.add_argument("-areas", "--areas", type=int, required=False,
help='Will create a grid with "areas x areas" areas')
parser.add_argument("-simulation_dir", "--simulation_dir", type=str, required=False,
help='Choose the simulation directory')
parser.add_argument("-run", "--run", type=str,
help='Run a simulation with the dump chosen')
parser.add_argument("-c", "--c", nargs='+', type=str,
help='Choose your configuration file from your working directory')
parser.add_argument("-save", "--save", action="store_true",
help='Save the logs into the logs folder')
parser.add_argument("-csv", "--csv", action="store_true",
help="Export all data emissions into a CSV file")
def create_dump(dump_name, simulation_dir, areas_number):
"""
Create a new dump with config file and dump_name chosen
@ -198,8 +169,34 @@ def create_dump(dump_name, simulation_dir, areas_number):
else:
print(f'Dump with name {dump_name} already exist')
traci.close(False)
traci.close(False)
def add_options(parser):
"""
Add command line options
:param parser: The command line parser
:return:
"""
# TODO: Faire que -areas & -simulation_dir soit requis si -new_dump
# Faire que -c soit requis si -run
parser.add_argument("-new_dump", "--new_dump", type=str,
required=False, help='Load and create a new data dump with the configuration file chosen')
parser.add_argument("-areas", "--areas", type=int, required=False,
help='Will create a grid with "areas x areas" areas')
parser.add_argument("-simulation_dir", "--simulation_dir", type=str, required=False,
help='Choose the simulation directory')
parser.add_argument("-run", "--run", type=str,
help='Run a simulation with the dump chosen')
parser.add_argument("-c", "--c", nargs='+', type=str,
help='Choose your configuration file from your working directory')
parser.add_argument("-save", "--save", action="store_true",
help='Save the logs into the logs folder')
parser.add_argument("-csv", "--csv", action="store_true",
help="Export all data emissions into a CSV file")
def main(args):
"""
The entry point of the application
@ -224,16 +221,12 @@ def main(args):
if args.c is not None:
# Init all process
for conf in args.c:
config = Config()
config.import_config_file(conf)
config.init_traci(data.dir)
config.check_config()
# Init
for conf in args.c:
config = Config(conf,data)
p = RunProcess(data, config,args.save,args.csv)
p.init_logger()
#p.init_logger()
process.append(p)
p.start()