From 1b3aa926715f23506ff15965b5723fea62791cee Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Sat, 10 Jan 2026 21:21:18 +0000 Subject: [PATCH] already installed working --- backend/Property.py | 4 +--- backend/engine/engine.py | 1 - .../g_rebaselining_installed_measrues.py | 15 ++++++++------- recommendations/WallRecommendations.py | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/backend/Property.py b/backend/Property.py index e0bc2199..49dc15d0 100644 --- a/backend/Property.py +++ b/backend/Property.py @@ -469,10 +469,8 @@ class Property: # It means we've recommended HHR with electric immersion, and shouldn't overwrite # the hot water description continue + # Set the new value otherwise as it's due to already installed measures - do nothing - raise NotImplementedError( - "Already have this key in the phase_epc_transformation - implement me" - ) phase_epc_transformation[k] = v simulation_epc.update(phase_epc_transformation) self.simulation_epcs[rec["recommendation_id"]] = simulation_epc diff --git a/backend/engine/engine.py b/backend/engine/engine.py index 740b9581..4a503a08 100644 --- a/backend/engine/engine.py +++ b/backend/engine/engine.py @@ -1073,7 +1073,6 @@ async def model_engine(body: PlanTriggerRequest): # We insert the innovation uplift measures_to_optimise_with_uplift = deepcopy(measures_to_optimise) - # TODO: Turn this into a function and store the innovaiton uplift for group in measures_to_optimise_with_uplift: for r in group: (r["partial_project_score"], r["partial_project_funding"], r["innovation_uplift"], diff --git a/etl/customers/peabody/Nov 2025 Consulting Project/g_rebaselining_installed_measrues.py b/etl/customers/peabody/Nov 2025 Consulting Project/g_rebaselining_installed_measrues.py index 8d4bc9da..4405d113 100644 --- a/etl/customers/peabody/Nov 2025 Consulting Project/g_rebaselining_installed_measrues.py +++ b/etl/customers/peabody/Nov 2025 Consulting Project/g_rebaselining_installed_measrues.py @@ -196,7 +196,7 @@ sustainability_data["double_glazing"] = sustainability_data["Glazing"].isin( ["Double 2002 or later", "Double but age unknown", "Triple", "DoubleKnownData", "Secondary", "TripleKnownData"] ) sustainability_data["secondary_glazing"] = sustainability_data["Glazing"].isin( - ["Double 2002 or later", "Double but age unknown", "Triple", "DoubleKnownData", "Secondary", "TripleKnownData"] + ["Secondary"] ) sustainability_data["suspended_floor_insulation"] = sustainability_data["Floor Insulation"].isin( @@ -262,8 +262,9 @@ loft_conflicting["conflict_loft_insulation"] = True # ------------ Windows ------------ double_glazing_conflicting = comparison[ - (comparison["double_glazing"]) & - (pd.isnull(comparison["double_glazing_from_recs"]) == False) + (comparison["double_glazing"] | comparison["secondary_glazing"]) & + (pd.isnull(comparison["double_glazing_from_recs"]) == False) & + (pd.isnull(comparison["secondary_glazing_from_recs"]) == True) ].copy() double_glazing_conflicting["conflict_double_glazing"] = True secondary_glazing_conflicting = comparison[ @@ -445,10 +446,10 @@ def add_mechanical_ventilation_for_fabric(installed_measures_df, recs_with_uprn) ) -installed_measures_df = add_mechanical_ventilation_for_fabric( - installed_measures_df, - recs_with_uprn -) +# installed_measures_df = add_mechanical_ventilation_for_fabric( +# installed_measures_df, +# recs_with_uprn +# ) assert installed_measures_df[["uprn", "measure_type"]].duplicated().sum() == 0 diff --git a/recommendations/WallRecommendations.py b/recommendations/WallRecommendations.py index 49483d2f..e1770838 100644 --- a/recommendations/WallRecommendations.py +++ b/recommendations/WallRecommendations.py @@ -8,6 +8,7 @@ from datatypes.enums import QuantityUnits from backend.Property import Property from backend.app.plan.schemas import MEASURE_MAP from BaseUtility import Definitions +from etl.customers.vander_elliot.non_intrusives import already_installed from etl.epc_clean.epc_attributes.WallAttributes import WallAttributes from recommendations.recommendation_utils import ( r_value_per_mm_to_u_value, calculate_u_value_uplift, is_diminishing_returns, update_lowest_selected_u_value, @@ -641,8 +642,18 @@ class WallRecommendations(Definitions): # we separate the logic for for recommending them, therefore we don't # consider diminishing returns between the two as they are considered to be separate measures + prop_already_installed = self.property.already_installed + # So, we'll end up with problems if e.g. an external wall insulation is already installed and we try and + # recommend internal wall insulation. To avoid this, we check if either measure is already installed + # and: + # 1) If EWI is installed, we don't recommend IWI + # 2) If IWI is installed, we don't recommend EWI + # We only produce the recommendation for the moment, for the purpose of re-baselining + ewi_recommendations = [] - if self.ewi_valid() and "external_wall_insulation" in measures: + if self.ewi_valid() and "external_wall_insulation" in measures and ( + "internal_wall_insulation" not in prop_already_installed + ): ewi_recommendations = self._find_insulation( u_value=u_value, insulation_materials=pd.DataFrame( @@ -653,7 +664,7 @@ class WallRecommendations(Definitions): ) iwi_recommendations = [] - if "internal_wall_insulation" in measures: + if "internal_wall_insulation" in measures and "external_wall_insulation" not in prop_already_installed: iwi_recommendations = self._find_insulation( u_value=u_value, insulation_materials=pd.DataFrame(self.internal_wall_insulation_materials),