commit
4051ed3c98
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"arguments": {"output-format": "csv", "output-file": "test"},
|
"arguments": {
|
||||||
|
"output-format": "csv",
|
||||||
|
"output-file": "test"
|
||||||
|
},
|
||||||
"simulation": {
|
"simulation": {
|
||||||
"consensus_settings": {
|
"consensus_settings": {
|
||||||
"snow_ball": {
|
"snow_ball": {
|
||||||
|
@ -38,7 +41,23 @@
|
||||||
],
|
],
|
||||||
"seed": 18042022
|
"seed": 18042022
|
||||||
},
|
},
|
||||||
"plotting": {
|
"plotter": {
|
||||||
"test": "test"
|
"countplot": {
|
||||||
|
"plot_options": {
|
||||||
|
"x": "vote"
|
||||||
|
},
|
||||||
|
"save_options": {
|
||||||
|
"name": "test.png"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scatterplot": {
|
||||||
|
"plot_options": {
|
||||||
|
"x": "id",
|
||||||
|
"y": "vote"
|
||||||
|
},
|
||||||
|
"save_options": {
|
||||||
|
"name": "test2.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
# Project Imports
|
# Project Imports
|
||||||
|
from src.plotter.run_plotter import run_plotter
|
||||||
from src.simulation_runner.runner import run_simulation
|
from src.simulation_runner.runner import run_simulation
|
||||||
from src.utilities.files.json.simulation_config_parser import SimulationConfigParser
|
from src.utilities.files.json.simulation_config_parser import SimulationConfigParser
|
||||||
|
|
||||||
|
@ -16,11 +17,10 @@ def main(
|
||||||
if run_type == "simulation":
|
if run_type == "simulation":
|
||||||
run_simulation(arguments_config, simulation_config)
|
run_simulation(arguments_config, simulation_config)
|
||||||
elif run_type == "plotter":
|
elif run_type == "plotter":
|
||||||
# run_plotter()
|
run_plotter(arguments_config, plotter_config)
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
run_simulation()
|
run_simulation()
|
||||||
# run_plotter()
|
run_plotter()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
# Python Imports
|
# Python Imports
|
||||||
import typer
|
import seaborn as sns
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
# Project Imports
|
||||||
|
from src.utilities.env_variables import SHARED_FOLDER
|
||||||
|
from src.utilities.files.simulation_data_parser import SimulationDataParser
|
||||||
|
|
||||||
|
|
||||||
def main(
|
def run_plotter(arguments_config: dict, plotter_config: dict):
|
||||||
input_data: str = typer.Option(..., "--input-data", "-i"),
|
file_name = f"{arguments_config['output-file']}.{arguments_config['output-format']}"
|
||||||
plot_type: str = typer.Option(..., "--plot-type", "-p"),
|
# Read file given in arguments config
|
||||||
plot_settings: str = typer.Option(..., "--plot-settings", "-s"),
|
parser = SimulationDataParser()
|
||||||
):
|
polars_df = parser.read_content(SHARED_FOLDER + file_name)
|
||||||
# Parse data file
|
|
||||||
print("")
|
|
||||||
# Accept plot type
|
|
||||||
|
|
||||||
# Handle Plot arguments
|
pandas_df = polars_df.to_pandas()
|
||||||
|
|
||||||
|
# Loop through all plots given in plotting section
|
||||||
'''
|
for plot, options in plotter_config.items():
|
||||||
import foo
|
print(plot)
|
||||||
bar = getattr(foo, 'bar')
|
print(options)
|
||||||
result = bar()
|
method = getattr(sns, plot)
|
||||||
'''
|
method(pandas_df, **options["plot_options"])
|
||||||
|
plt.savefig(SHARED_FOLDER + options["save_options"]["name"])
|
||||||
if __name__ == '__main__':
|
|
||||||
typer.run(main)
|
|
||||||
|
|
|
@ -6,6 +6,12 @@ CONFIGURATION_SETTINGS = "shared/configuration_settings.json"
|
||||||
# Schemas
|
# Schemas
|
||||||
ARGUMENTS_SCHEMA_PATH = "src/utilities/files/schemas/arguments_schema.json"
|
ARGUMENTS_SCHEMA_PATH = "src/utilities/files/schemas/arguments_schema.json"
|
||||||
CONFIGURATION_SCHEMA_PATH = "src/utilities/files/schemas/snow_family_configuration_schema.json"
|
CONFIGURATION_SCHEMA_PATH = "src/utilities/files/schemas/snow_family_configuration_schema.json"
|
||||||
|
PLOTTER_SCHEMA_PATH = "src/utilities/files/schemas/plotter_schema.json"
|
||||||
|
|
||||||
# Shared folder
|
# Shared folder
|
||||||
SHARED_FOLDER = "shared/"
|
SHARED_FOLDER = "shared/"
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
ARGUMENTS_BLOCK = "arguments"
|
||||||
|
SIMULATION_BLOCK = "simulation"
|
||||||
|
PLOTTER_BLOCK = "plotter"
|
||||||
|
|
|
@ -16,17 +16,16 @@ class SimulationConfigParser:
|
||||||
# Split two parts
|
# Split two parts
|
||||||
arguments_config = json_configuration["arguments"]
|
arguments_config = json_configuration["arguments"]
|
||||||
simulation_config = json_configuration["simulation"]
|
simulation_config = json_configuration["simulation"]
|
||||||
# plotter_config = json_configuration["plotter"]
|
plotter_config = json_configuration["plotter"]
|
||||||
|
|
||||||
# Retrieve valid schemas
|
# Retrieve valid schemas
|
||||||
arguments_json_schema = read_json(env_variables.ARGUMENTS_SCHEMA_PATH)
|
arguments_json_schema = read_json(env_variables.ARGUMENTS_SCHEMA_PATH)
|
||||||
config_json_schema = read_json(env_variables.CONFIGURATION_SCHEMA_PATH)
|
config_json_schema = read_json(env_variables.CONFIGURATION_SCHEMA_PATH)
|
||||||
# plotter_json_schema = read_json(env_variables.plotter_schema_path)
|
# plotter_json_schema = read_json(env_variables.plotter_schema_path) todo uncomment
|
||||||
|
|
||||||
# Validate
|
# Validate
|
||||||
validate_json(arguments_config, arguments_json_schema)
|
validate_json(arguments_config, arguments_json_schema)
|
||||||
validate_json(simulation_config, config_json_schema)
|
validate_json(simulation_config, config_json_schema)
|
||||||
# validate_json(plotter_config, plotter_json_schema)
|
# validate_json(plotter_config, plotter_json_schema) todo uncomment
|
||||||
|
|
||||||
# return simulation_config, plotter_config
|
return arguments_config, simulation_config, plotter_config
|
||||||
return arguments_config, simulation_config, {}
|
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"scatterplot": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"plot_options": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"save_options": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"plot_options",
|
||||||
|
"save_options"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"lineplot": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"plot_options": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"save_options": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"plot_options",
|
||||||
|
"save_options"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"histplot": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"plot_options": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"save_options": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"plot_options",
|
||||||
|
"save_options"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"countplot": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"plot_options": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"save_options": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"plot_options",
|
||||||
|
"save_options"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"aditionalProperties": false
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
# Python Imports
|
# Python Imports
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
import polars
|
||||||
|
|
||||||
# Project Imports
|
# Project Imports
|
||||||
from src.utilities.files.simulation_data_types.json_data_simulation_handler import JsonDataSimulationHandler
|
from src.utilities.files.simulation_data_types.json_data_simulation_handler import JsonDataSimulationHandler
|
||||||
from src.utilities.files.simulation_data_types.csv_data_simulation_handler import CsvDataSimulationHandler
|
from src.utilities.files.simulation_data_types.csv_data_simulation_handler import CsvDataSimulationHandler
|
||||||
|
@ -8,17 +10,18 @@ from src.utilities.files.simulation_data_types.parquet_simulation_data_handler i
|
||||||
|
|
||||||
handlers = {'.csv': CsvDataSimulationHandler,
|
handlers = {'.csv': CsvDataSimulationHandler,
|
||||||
'.json': JsonDataSimulationHandler,
|
'.json': JsonDataSimulationHandler,
|
||||||
'parquet': ParquetDataSimulationHandler
|
'.parquet': ParquetDataSimulationHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SimulationDataParser:
|
class SimulationDataParser:
|
||||||
|
|
||||||
def __init__(self, file_path):
|
def __init__(self):
|
||||||
self._file_path = file_path
|
self._file_path = None
|
||||||
self._file_extension = None
|
self._file_extension = None
|
||||||
|
|
||||||
def read_content(self):
|
def read_content(self, file_path: str) -> polars.DataFrame:
|
||||||
|
self._file_path = file_path
|
||||||
# Check file exists
|
# Check file exists
|
||||||
self._check_file()
|
self._check_file()
|
||||||
# Check extension
|
# Check extension
|
||||||
|
@ -26,10 +29,9 @@ class SimulationDataParser:
|
||||||
# Get correct handler
|
# Get correct handler
|
||||||
handler = self._get_data_handler()
|
handler = self._get_data_handler()
|
||||||
# Load content
|
# Load content
|
||||||
handler.load_data()
|
polars_df = handler.load_data(self._file_path)
|
||||||
# Convert it to dataframe
|
|
||||||
dataframe = handler.convert_into_dataframe()
|
|
||||||
# Return
|
# Return
|
||||||
|
return polars_df
|
||||||
|
|
||||||
def _check_file(self):
|
def _check_file(self):
|
||||||
exists = os.path.exists(self._file_path)
|
exists = os.path.exists(self._file_path)
|
||||||
|
@ -39,7 +41,7 @@ class SimulationDataParser:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def _check_extension(self):
|
def _check_extension(self):
|
||||||
return os.path.splitext(self._file_path)[1]
|
self._file_extension = os.path.splitext(self._file_path)[1]
|
||||||
|
|
||||||
def _get_data_handler(self):
|
def _get_data_handler(self):
|
||||||
handler = handlers.get(self._file_extension)
|
handler = handlers.get(self._file_extension)
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
|
# Python Imports
|
||||||
import abc
|
import abc
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
import polars as pl
|
||||||
|
|
||||||
|
|
||||||
class BaseDataSimulationHandler(ABC):
|
class BaseDataSimulationHandler(ABC):
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self._data = None
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def load_data(self, path):
|
def load_data(self, path: str) -> pl.DataFrame:
|
||||||
pass
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def convert_into_dataframe(self):
|
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
# Python Imports
|
||||||
|
import polars as pl
|
||||||
|
|
||||||
|
# Project Imports
|
||||||
from src.utilities.files.simulation_data_types.base_data_simulation_handler import BaseDataSimulationHandler
|
from src.utilities.files.simulation_data_types.base_data_simulation_handler import BaseDataSimulationHandler
|
||||||
|
|
||||||
|
|
||||||
class CsvDataSimulationHandler(BaseDataSimulationHandler):
|
class CsvDataSimulationHandler(BaseDataSimulationHandler):
|
||||||
|
|
||||||
def load_data(self, path):
|
def load_data(self, path: str) -> pl.DataFrame:
|
||||||
pass
|
polars_df = pl.read_csv(path)
|
||||||
|
|
||||||
|
return polars_df
|
||||||
|
|
||||||
def convert_into_dataframe(self):
|
|
||||||
pass
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
# Python Imports
|
||||||
|
import polars as pl
|
||||||
|
|
||||||
|
# Project Imports
|
||||||
from src.utilities.files.simulation_data_types.base_data_simulation_handler import BaseDataSimulationHandler
|
from src.utilities.files.simulation_data_types.base_data_simulation_handler import BaseDataSimulationHandler
|
||||||
|
|
||||||
|
|
||||||
class JsonDataSimulationHandler(BaseDataSimulationHandler):
|
class JsonDataSimulationHandler(BaseDataSimulationHandler):
|
||||||
|
|
||||||
def load_data(self, path):
|
def load_data(self, path: str) -> pl.DataFrame:
|
||||||
pass
|
polars_df = pl.read_json(path)
|
||||||
|
|
||||||
def convert_into_dataframe(self):
|
return polars_df
|
||||||
pass
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
# Python Imports
|
||||||
|
import polars as pl
|
||||||
|
|
||||||
|
# Project Imports
|
||||||
from src.utilities.files.simulation_data_types.base_data_simulation_handler import BaseDataSimulationHandler
|
from src.utilities.files.simulation_data_types.base_data_simulation_handler import BaseDataSimulationHandler
|
||||||
|
|
||||||
|
|
||||||
class ParquetDataSimulationHandler(BaseDataSimulationHandler):
|
class ParquetDataSimulationHandler(BaseDataSimulationHandler):
|
||||||
|
|
||||||
def load_data(self, path):
|
def load_data(self, path: str) -> pl.DataFrame:
|
||||||
pass
|
polars_df = pl.read_parquet(path)
|
||||||
|
|
||||||
def convert_into_dataframe(self):
|
return polars_df
|
||||||
pass
|
|
||||||
|
|
Loading…
Reference in New Issue