From c6247f331a11a3ebb5150d413661a3822d9222c3 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 21 Dec 2023 15:33:17 +0000 Subject: [PATCH] integrating windows recommendations into engine api --- .idea/Model.iml | 2 +- .idea/misc.xml | 2 +- backend/app/plan/router.py | 4 +--- backend/app/plan/utils.py | 15 +++++++++++++-- backend/ml_models/Valuation.py | 9 ++++++++- recommendations/WindowsRecommendations.py | 3 ++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.idea/Model.iml b/.idea/Model.iml index b0f9c00d..4413bb06 100644 --- a/.idea/Model.iml +++ b/.idea/Model.iml @@ -7,7 +7,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 1122b380..6f308057 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 952d4982..a284e50b 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -544,9 +544,7 @@ async def trigger_plan(body: PlanTriggerRequest): valuations = PropertyValuation.estimate(property_instance=p, target_epc=new_epc) - property_valuation_increases.append( - valuations["average_increased_value"] - valuations["current_value"] - ) + property_valuation_increases.append(valuations["average_increase"]) # Commit the session after each batch session.commit() diff --git a/backend/app/plan/utils.py b/backend/app/plan/utils.py index 90042fa2..b82be297 100644 --- a/backend/app/plan/utils.py +++ b/backend/app/plan/utils.py @@ -178,10 +178,21 @@ def create_recommendation_scoring_data( if recommendation["type"] == "windows_glazing": scoring_dict["MULTI_GLAZE_PROPORTION_ENDING"] = 100 scoring_dict["WINDOWS_ENERGY_EFF_ENDING"] = "Average" - if scoring_dict["glazing_type_ENDING"] in ["multiple", "double"]: + + is_secondary_glazing = recommendation["is_secondary_glazing"] + + if scoring_dict["glazing_type_ENDING"] == "multiple": pass + elif scoring_dict["glazing_type_ENDING"] == "single": + scoring_dict["glazing_type_ENDING"] = "secondary" if is_secondary_glazing else "double" + elif scoring_dict["glazing_type_ENDING"] == "double": + scoring_dict["glazing_type_ENDING"] = "multiple" if is_secondary_glazing else "double" + elif scoring_dict["glazing_type_ENDING"] == "secondary": + scoring_dict["glazing_type_ENDING"] = "secondary" if is_secondary_glazing else "multiple" + elif scoring_dict["glazing_type_ENDING"] in ["triple", "high performance"]: + scoring_dict["glazing_type_ENDING"] = "multiple" else: - raise NotImplementedError("Implement me") + raise ValueError("Invalid glazing type - implement me") if recommendation["type"] not in [ "mechanical_ventilation", "sealing_open_fireplace", "low_energy_lighting", diff --git a/backend/ml_models/Valuation.py b/backend/ml_models/Valuation.py index f5a7e2bb..cdbbe698 100644 --- a/backend/ml_models/Valuation.py +++ b/backend/ml_models/Valuation.py @@ -93,7 +93,13 @@ class PropertyValuation: value = cls.UPRN_VALUE_LOOKUP.get(property_instance.uprn) if not value: - raise ValueError("Have not implemented valuation for this property") + return { + "current_value": None, + "lower_bound_increased_value": None, + "upper_bound_increased_value": None, + "average_increased_value": None, + "average_increase": None + } current_epc = property_instance.data["current-energy-rating"] # We get the spectrum of ratings between the current and target EPC @@ -119,4 +125,5 @@ class PropertyValuation: "lower_bound_increased_value": value * (1 + min_increase), "upper_bound_increased_value": value * (1 + max_increase), "average_increased_value": value * (1 + avg_increase), + "average_increase": value * (1 + avg_increase) - value } diff --git a/recommendations/WindowsRecommendations.py b/recommendations/WindowsRecommendations.py index 6246fd95..b6ecd099 100644 --- a/recommendations/WindowsRecommendations.py +++ b/recommendations/WindowsRecommendations.py @@ -91,6 +91,7 @@ class WindowsRecommendations: "starting_u_value": None, "new_u_value": None, "sap_points": None, - **cost_result + **cost_result, + "is_secondary_glazing": is_secondary_glazing } ]