Skip to content

Commit 4ac0e85

Browse files
Extract variables from scenario
1 parent b68aee3 commit 4ac0e85

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

causal_testing/json_front/json_class.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class JsonUtility:
4545

4646
def __init__(self, output_path: str, output_overwrite: bool = False):
4747
self.input_paths = None
48-
self.variables = None
48+
self.variables = {"inputs": {}, "outputs": {}, "metas": {}}
4949
self.data = []
5050
self.test_plan = None
5151
self.scenario = None
@@ -65,6 +65,7 @@ def set_paths(self, json_path: str, dag_path: str, data_paths: str):
6565
def setup(self, scenario: Scenario):
6666
"""Function to populate all the necessary parts of the json_class needed to execute tests"""
6767
self.scenario = scenario
68+
self._get_scenario_variables()
6869
self.scenario.setup_treatment_variables()
6970
self.causal_specification = CausalSpecification(
7071
scenario=self.scenario, causal_dag=CausalDAG(self.input_paths.dag_path)
@@ -232,6 +233,14 @@ def _append_to_file(self, line: str, log_level: int = None):
232233
if log_level:
233234
logger.log(level=log_level, msg=line)
234235

236+
def _get_scenario_variables(self):
237+
for input in self.scenario.inputs():
238+
self.variables["inputs"][input.name] = input
239+
for output in self.scenario.outputs():
240+
self.variables["outputs"][output.name] = output
241+
for meta in self.scenario.metas():
242+
self.variables["metas"][meta.name] = meta
243+
235244
@staticmethod
236245
def check_file_exists(output_path: Path, overwrite: bool):
237246
"""Method that checks if the given path to an output file already exists. If overwrite is true the check is
@@ -262,7 +271,7 @@ def get_args(test_args=None) -> argparse.Namespace:
262271
parser.add_argument(
263272
"-w",
264273
help="Specify to overwrite any existing output files. This can lead to the loss of existing outputs if not "
265-
"careful",
274+
"careful",
266275
action="store_true",
267276
)
268277
parser.add_argument(

0 commit comments

Comments
 (0)