Commit e438ec23 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Added occupancies_to_run to Configuration

parent d2f8de46
Pipeline #40616 passed with stage
in 1 minute and 58 seconds
......@@ -7,3 +7,4 @@ database_gde_tiles: # Database where info on the GDE tiles is stored
password: password_of_username
exposure_entities_to_run: all # Either "all", a comma-space-separated list of entity names, or a name of a .txt or .csv file
exposure_entities_code: ISO3 # Either "ISO3" in this or a nested structure with exposure entities names and 3-character codes
occupancies_to_run: residential, commercial, industrial # Need to exist for the indicated `model_name`
......@@ -65,6 +65,7 @@ class Configuration:
"database_gde_tiles",
"exposure_entities_to_run",
"exposure_entities_code",
"occupancies_to_run",
]
def __init__(self, filepath, force_config_over_hierarchies=False):
......@@ -111,6 +112,10 @@ class Configuration:
logger.critical(error_message)
sys.exit(1)
self.occupancies_to_run = ConfigurationMethods.assign_listed_parameters(
config, "occupancies_to_run"
)
# Terminate if critical parameters are missing (not all parameters are critical)
for key_parameter in self.REQUIRES:
if getattr(self, key_parameter) is None:
......
......@@ -67,6 +67,14 @@ def main():
)
)
# Run by exposure entity and occupancy case
for exposure_entity_name in config.exposure_entities_to_run:
for occupancy_case in config.occupancies_to_run:
logger.info(
"Running exposure entity '%s', occupancy case '%s'."
% (exposure_entity_name, occupancy_case)
)
# Leave the program
logger.info("gde-core has finished")
sys.exit()
......
......@@ -6,3 +6,4 @@ database_gde_tiles:
password: some_password
exposure_entities_to_run: Italy
exposure_entities_code: ISO3
occupancies_to_run: residential, commercial
model_name: esrm20
database_gde_tiles:
host: host.somewhere.xx
dbname: some_database_name
username: some_username
password: some_password
exposure_entities_to_run: Italy
exposure_entities_code: ISO3
......@@ -36,6 +36,9 @@ def test_Configuration():
assert len(returned_config.exposure_entities_to_run) == 1
assert returned_config.exposure_entities_to_run[0] == "Italy"
assert returned_config.exposure_entities_code == "ISO3"
assert len(returned_config.occupancies_to_run) == 2
assert returned_config.occupancies_to_run[0] == "residential"
assert returned_config.occupancies_to_run[1] == "commercial"
# Test case in which the file is not found
with pytest.raises(OSError) as excinfo:
......@@ -45,6 +48,14 @@ def test_Configuration():
)
assert "OSError" in str(excinfo.type)
# Test case in which a parameter is missing
with pytest.raises(OSError) as excinfo:
returned_config = Configuration(
os.path.join(os.path.dirname(__file__), "data", "config_for_testing_missing.yml"),
force_config_over_hierarchies=True,
)
assert "OSError" in str(excinfo.type)
def test_Configuration_interpret_exposure_entities_to_run(test_db):
returned_config = Configuration(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment