From 8bab3920cffa725afab49a3e908125e7e089ad6c Mon Sep 17 00:00:00 2001 From: yunjoonjung Date: Tue, 13 Aug 2024 11:47:41 -0700 Subject: [PATCH 1/2] Finished func dev --- ...s_associated_with_each_building_segment.py | 28 ++++++++ ...ociated_with_each_building_segment_test.py | 65 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py create mode 100644 rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment_test.py diff --git a/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py b/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py new file mode 100644 index 000000000..771e3b92c --- /dev/null +++ b/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py @@ -0,0 +1,28 @@ +from rct229.utils.jsonpath_utils import find_all + + +def get_swh_uses_associated_with_each_building_segment( + rmd: dict, building_segment_id: str +) -> list[str]: + """ + This function gets all the SWH uses connected to a building segment. This function is primarily to encapsulate getting service water heating uses in one function so that if a change is made in the schema as to how service water heating use is specified, + the RCT only needs to change in one place. + + Parameters + ---------- + rmd: dict + RMD at RuleSetModelDescription level + building_segment_id: str + building segment id + + Returns + ------- + swh_uses: list + A list containing the ids of all service water heating uses associated with a building segment + """ + + swh_uses_list = find_all( + f'$.buildings[*].building_segments[*][?(@.id="{building_segment_id}")].zones[*].spaces[*].service_water_heating_uses[*].id', + rmd, + ) + return swh_uses_list diff --git a/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment_test.py b/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment_test.py new file mode 100644 index 000000000..f1b0c546e --- /dev/null +++ b/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment_test.py @@ -0,0 +1,65 @@ +from rct229.rulesets.ashrae9012019.ruleset_functions.get_swh_uses_associated_with_each_building_segment import ( + get_swh_uses_associated_with_each_building_segment, +) +from rct229.schema.schema_utils import quantify_rmd +from rct229.schema.validate import schema_validate_rmd + +TEST_RMD = { + "id": "test_rmd", + "buildings": [ + { + "id": "Building 1", + "building_open_schedule": "Required Building Schedule 1", + "building_segments": [ + { + "id": "Building Segment 1", + "zones": [ + { + "id": "Zone 1", + "spaces": [ + { + "id": "Space 1", + "service_water_heating_uses": [ + {"id": "service water heating uses 1"}, + {"id": "service water heating uses 2"}, + ], + }, + ], + } + ], + } + ], + } + ], + "type": "BASELINE_0", +} + +TEST_RPD_FULL = { + "id": "229", + "ruleset_model_descriptions": [TEST_RMD], + "data_timestamp": "2024-02-12T09:00Z", +} + +TEST_RMD = quantify_rmd(TEST_RPD_FULL)["ruleset_model_descriptions"][0] + + +def test__TEST_RPD__is_valid(): + schema_validation_result = schema_validate_rmd(TEST_RPD_FULL) + assert schema_validation_result[ + "passed" + ], f"Schema error: {schema_validation_result['error']}" + + +def test__get_swh_uses_associated_with_each_building_segment__bldg_segment_ids_exist(): + assert get_swh_uses_associated_with_each_building_segment( + TEST_RMD, "Building Segment 1" + ) == ["service water heating uses 1", "service water heating uses 2"] + + +def test__get_swh_uses_associated_with_each_building_segment__bldg_segment_id_not_exist(): + assert ( + get_swh_uses_associated_with_each_building_segment( + TEST_RMD, "Building Segment 2" + ) + == [] + ) From b8b4656956d52019200844453803f3dd12bffb9a Mon Sep 17 00:00:00 2001 From: yunjoonjung Date: Mon, 19 Aug 2024 16:50:38 -0700 Subject: [PATCH 2/2] Addressed PR comment --- .../get_swh_uses_associated_with_each_building_segment.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py b/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py index 771e3b92c..99be00d56 100644 --- a/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py +++ b/rct229/rulesets/ashrae9012019/ruleset_functions/get_swh_uses_associated_with_each_building_segment.py @@ -5,8 +5,8 @@ def get_swh_uses_associated_with_each_building_segment( rmd: dict, building_segment_id: str ) -> list[str]: """ - This function gets all the SWH uses connected to a building segment. This function is primarily to encapsulate getting service water heating uses in one function so that if a change is made in the schema as to how service water heating use is specified, - the RCT only needs to change in one place. + This function gets all the SWH uses connected to a building segment or an empty list if no service water heating uses are found in the building segment. This function is primarily to encapsulate getting service water heating uses in one function so that if a change is made in the schema as to how service water heating use is specified, + the RCT only needs to change in one place . Parameters ---------- @@ -17,7 +17,7 @@ def get_swh_uses_associated_with_each_building_segment( Returns ------- - swh_uses: list + swh_uses_list: list A list containing the ids of all service water heating uses associated with a building segment """