diff --git a/SimulationRunner/main.py b/SimulationRunner/run_simulation.py similarity index 54% rename from SimulationRunner/main.py rename to SimulationRunner/run_simulation.py index 091d86d..7ba7d99 100644 --- a/SimulationRunner/main.py +++ b/SimulationRunner/run_simulation.py @@ -2,24 +2,22 @@ import typer # Project Imports -from Utilities.file_parser import ConfigurationFileParser +from Utilities.Files.Json.simulation_config_parser import SimulationConfigParser +from runner import run_simulation def main( # todo put in output format possible names (-f --output-format) - output_format: str = typer.Argument("parquet"), + output_format: str = typer.Option(..., "--output-format", "-f"), input_settings: str = typer.Option(..., "--input-settings", "-i"), output_file: str = typer.Option(..., "--output-file", "-o") ): # Check config file - parser = ConfigurationFileParser(input_settings) - config = parser.read_content() + parser = SimulationConfigParser(input_settings) + parser.read_content() # Calls simulation with configuration + run_simulation(output_format, input_settings, output_file) if __name__ == '__main__': typer.run(main) - - # Run simulation with arguments - - pass diff --git a/SimulationRunner/runner.py b/SimulationRunner/runner.py index 239bcf2..066a94d 100644 --- a/SimulationRunner/runner.py +++ b/SimulationRunner/runner.py @@ -1,4 +1,9 @@ +# Python Imports +import os + +# Project Imports +from Utilities.env_variables import binary_path -def run_simulation(): - pass +def run_simulation(output_format, input_settings, output_file): + os.system(binary_path + " -f " + output_format + " -i " + input_settings + " -o " + output_file) diff --git a/Utilities/Files/Json/simulation_config_parser.py b/Utilities/Files/Json/simulation_config_parser.py new file mode 100644 index 0000000..1312b21 --- /dev/null +++ b/Utilities/Files/Json/simulation_config_parser.py @@ -0,0 +1,20 @@ +from Utilities import env_variables +from Utilities.Files.Json.json_utils import read_json, validate_json + + +class SimulationConfigParser: + + def __init__(self, file_path): + self._file_path = file_path + self._configuration = None + + def read_content(self): + # Retrieve raw info + json_configuration = read_json(self._file_path) + + # Retrieve valid schema + json_schema = read_json(env_variables.schema_path) + + # Validate + validate_json(json_configuration, json_schema) + self._configuration = json_configuration diff --git a/Utilities/Schemas/__init__.py b/Utilities/Files/Schemas/__init__.py similarity index 100% rename from Utilities/Schemas/__init__.py rename to Utilities/Files/Schemas/__init__.py diff --git a/Utilities/Schemas/configuration_schema.json b/Utilities/Files/Schemas/configuration_schema.json similarity index 100% rename from Utilities/Schemas/configuration_schema.json rename to Utilities/Files/Schemas/configuration_schema.json diff --git a/Utilities/env_variables.py b/Utilities/env_variables.py new file mode 100644 index 0000000..4dc45dc --- /dev/null +++ b/Utilities/env_variables.py @@ -0,0 +1,4 @@ +# Workaround while docker is not set up + +binary_path = "C:/Users/Alberto/Desktop/Status/consensus-prototypes/target/release-opt/consensus-simulations.exe" +schema_path = "../Utilities/Files/Schemas/configuration_schema.json"