From 9adb03530e5e32d8da6c19c1419df6bd7a7ddb33 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 26 Jun 2023 22:36:14 +0100 Subject: [PATCH] refactoring walls --- model_data/app.py | 8 +++ .../recommendations/FloorRecommendations.py | 7 +- .../recommendations/WallRecommendations.py | 65 ++++++++++++------- .../recommendations/recommendation_utils.py | 7 +- 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/model_data/app.py b/model_data/app.py index c293c79f..8c1fddf5 100644 --- a/model_data/app.py +++ b/model_data/app.py @@ -135,10 +135,18 @@ def handler(): ) df["property-type"].unique() + from model_data.recommendations.WallRecommendations import WallRecommendations + self = WallRecommendations(property_instance=input_properties[2], uvalue_estimates=uvalue_estimates) + input_properties[2].walls + self.recommend() + df = pd.DataFrame(self.recommendations[0]["parts"]) + recommendations = pd.DataFrame(self.recommendations) + from model_data.recommendations.FloorRecommendations import FloorRecommendations self = FloorRecommendations(property_instance=input_properties[4], uvalue_estimates=uvalue_estimates) self.recommendations self.recommend() + self.recommendations # We need to deduce a U-value for "Good" energy effieciency diff --git a/model_data/recommendations/FloorRecommendations.py b/model_data/recommendations/FloorRecommendations.py index 885602b2..8b47e31e 100644 --- a/model_data/recommendations/FloorRecommendations.py +++ b/model_data/recommendations/FloorRecommendations.py @@ -333,7 +333,12 @@ class FloorRecommendations(BaseUtility): lowest_selected_u_value = update_lowest_selected_u_value(lowest_selected_u_value, new_u_value) self.recommendations.append( - get_recommended_part(part, depth, new_u_value) + { + "parts": [ + get_recommended_part(part, depth), + ], + "new_u_value": new_u_value, + } ) @staticmethod diff --git a/model_data/recommendations/WallRecommendations.py b/model_data/recommendations/WallRecommendations.py index f3e78e65..61a1878a 100644 --- a/model_data/recommendations/WallRecommendations.py +++ b/model_data/recommendations/WallRecommendations.py @@ -293,23 +293,10 @@ class WallRecommendations(BaseUtility): raise NotImplementedError("Not implemented yet") - def find_insulation(self, u_value): - """ - This function contains the logic for finding potential insulation measures for a property, depending - on the parts available and whether the property can have external wall insulation installed - :return: - """ - - ewi_parts = [ - part for part in wall_parts if part["type"] == "external_wall_insulation" - ] if self.ewi_valid else [] - - iwi_parts = [part for part in wall_parts if part["type"] == "internal_wall_insulation"] - - # Recommend external and internal wall insulation separately - + def _find_insulation(self, parts, u_value): lowest_selected_u_value = None - for part in ewi_parts + iwi_parts: + recommendations = [] + for part in parts: for depth in part["depths"]: part_u_value = r_value_per_mm_to_u_value(depth, part["r_value_per_mm"]) @@ -324,7 +311,7 @@ class WallRecommendations(BaseUtility): # further into the diminishing returns threshold and can shouldn't be if is_diminishing_returns( - self.recommendations, new_u_value, lowest_selected_u_value, self.DIMINISHING_RETURNS_U_VALUE + recommendations, new_u_value, lowest_selected_u_value, self.DIMINISHING_RETURNS_U_VALUE ): continue @@ -332,9 +319,35 @@ class WallRecommendations(BaseUtility): if new_u_value <= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE: lowest_selected_u_value = update_lowest_selected_u_value(lowest_selected_u_value, new_u_value) - self.recommendations.append( - get_recommended_part(part, depth, new_u_value) - ) + recommendations.append({ + "parts": [get_recommended_part(part, depth)], + "new_u_value": new_u_value, + }) + + return recommendations + + def find_insulation(self, u_value): + """ + This function contains the logic for finding potential insulation measures for a property, depending + on the parts available and whether the property can have external wall insulation installed + :return: + """ + + ewi_parts = [ + part for part in wall_parts if part["type"] == "external_wall_insulation" + ] if self.ewi_valid else [] + + iwi_parts = [part for part in wall_parts if part["type"] == "internal_wall_insulation"] + + # Recommend external and internal wall insulation separately + # Since external and internal wall insulation are sufficiently different, + # we separate the logic for for recommending them, therefore we don't + # consider diminishing returns between the two + + ewi_recommendations = self._find_insulation(ewi_parts, u_value) + iwi_recommendations = self._find_insulation(iwi_parts, u_value) + + self.recommendations += ewi_recommendations + iwi_recommendations # We also can recommend both internal and external wall insulation together # By looping through ewi first, if there is nothing there, that ensures not combinations are tested @@ -358,11 +371,13 @@ class WallRecommendations(BaseUtility): if combined_new_u_value - self.U_VALUE_ERROR <= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE: # Here you might want to define a way to add both recommendations together. # For now, I'm adding them as separate items in the list - - recommendation = [ - get_recommended_part(ewi_part, ewi_depth, combined_new_u_value), - get_recommended_part(iwi_part, iwi_depth, combined_new_u_value) - ] + recommendation = { + "parts": [ + get_recommended_part(ewi_part, ewi_depth), + get_recommended_part(iwi_part, iwi_depth) + ], + "new_u_value": combined_new_u_value, + } self.recommendations.append(recommendation) self.prune_diminishing_recommendations() diff --git a/model_data/recommendations/recommendation_utils.py b/model_data/recommendations/recommendation_utils.py index d4713bb6..1e6f307a 100644 --- a/model_data/recommendations/recommendation_utils.py +++ b/model_data/recommendations/recommendation_utils.py @@ -99,17 +99,14 @@ def update_lowest_selected_u_value(lowest_selected_u_value, new_u_value): return lowest_selected_u_value -def get_recommended_part(part, selected_depth, new_u_value): +def get_recommended_part(part, selected_depth): """ Utility function to return a recommended part with the selected depth. :param part: :param selected_depth: - :param new_u_value: :return: """ recommended_part = deepcopy(part) recommended_part["depths"] = [selected_depth] - return { - **recommended_part, "new_u_value": new_u_value, - } + return recommended_part