diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 135b877d..8c8f309b 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -31,6 +31,7 @@ from etl.epc.DataProcessor import DataProcessor from etl.epc.settings import COLUMNS_TO_MERGE_ON from recommendations.FloorRecommendations import FloorRecommendations from recommendations.VentilationRecommendations import VentilationRecommendations +from recommendations.FireplaceRecommendations import FireplaceRecommendations from recommendations.optimiser.CostOptimiser import CostOptimiser from recommendations.optimiser.GainOptimiser import GainOptimiser from recommendations.optimiser.optimiser_functions import prepare_input_measures @@ -168,6 +169,15 @@ async def trigger_plan(body: PlanTriggerRequest): if ventilation_recomender.recommendation: property_recommendations.append(ventilation_recomender.recommendation) + # Fireplace sealing recommendations + fireplace_recommender = FireplaceRecommendations( + property_instance=p + ) + fireplace_recommender.recommend() + + if fireplace_recommender.recommendation: + property_recommendations.append(fireplace_recommender.recommendation) + # We insert temporary ids into the recommendations which is important for the optimiser later property_recommendations = insert_temp_recommendation_id(property_recommendations) diff --git a/backend/app/plan/utils.py b/backend/app/plan/utils.py index 0a1eaa72..2d9659e1 100644 --- a/backend/app/plan/utils.py +++ b/backend/app/plan/utils.py @@ -168,7 +168,12 @@ def create_recommendation_scoring_data( if recommendation["type"] == "mechanical_ventilation": scoring_dict["MECHANICAL_VENTILATION_ENDING"] = 'mechanical, extract only' - if recommendation["type"] not in ["wall_insulation", "floor_insulation", "mechanical_ventilation"]: + if recommendation["type"] == "sealing_open_fireplace": + scoring_dict["NUMBER_OPEN_FIREPLACES_ENDING"] = 0 + + if recommendation["type"] not in [ + "wall_insulation", "floor_insulation", "mechanical_ventilation", "sealing_open_fireplace" + ]: raise NotImplementedError("Implement me") # Fill missing roof u-values - this fill is not based on recommended upgrades diff --git a/backend/tests/test_sap_model_prep.py b/backend/tests/test_sap_model_prep.py index 1ba59fa0..93567920 100644 --- a/backend/tests/test_sap_model_prep.py +++ b/backend/tests/test_sap_model_prep.py @@ -9,13 +9,25 @@ import pytest from utils.s3 import read_dataframe_from_s3_parquet from tqdm import tqdm - # Handy code for selecting testin data -# import pickle -# -# with open("sap_change_dataset.pickle", "rb") as f: -# sap_change_dataset = pickle.load(f) -# +import pickle + +with open("sap_change_dataset.pickle", "rb") as f: + sap_change_dataset = pickle.load(f) + +sap_change_dataset.columns.tolist() +z = sap_change_dataset[(sap_change_dataset["NUMBER_OPEN_FIREPLACES_ENDING"] > 0) & ( + sap_change_dataset["NUMBER_OPEN_FIREPLACES_STARTING"] > 0)].head(2).tail(1) +z["UPRN"] +z["SAP_STARTING"] +z["SAP_ENDING"] +z["NUMBER_OPEN_FIREPLACES_STARTING"] +z["NUMBER_OPEN_FIREPLACES_ENDING"] + + +# 10002083298 + +# m # search_from = sap_change_dataset[ # (sap_change_dataset["walls_thermal_transmittance_ENDING"] == sap_change_dataset["walls_thermal_transmittance"]) # ] diff --git a/recommendations/FireplaceRecommendations.py b/recommendations/FireplaceRecommendations.py new file mode 100644 index 00000000..3e82b9d1 --- /dev/null +++ b/recommendations/FireplaceRecommendations.py @@ -0,0 +1,48 @@ +import pandas as pd +from BaseUtility import Definitions +from backend.Property import Property + + +class FireplaceRecommendations(Definitions): + """ + For properties that have open fireplaces, we recommend sealing the fireplaces + """ + + # This is our base assumption for the cost of the work + COST_OF_WORK = 300 + + def __init__( + self, + property_instance: Property, + ): + self.property = property_instance + + self.has_ventilaion = None + self.recommendation = None + + def recommend(self): + """ + Based on the number of open fireplcaes found, we recommend sealing each one at a cost of + around £500 + :return: + """ + + number_open_fireplaces = int(self.property.data["number-open-fireplaces"]) + + if number_open_fireplaces == 0: + return + + estimated_cost = number_open_fireplaces * self.COST_OF_WORK + + # We recommend installing two mechanical ventilation systems + self.recommendation = [ + { + "parts": [], + "type": "sealing_open_fireplace", + "description": "Seal %s open fireplaces" % str(number_open_fireplaces), + "starting_u_value": None, + "new_u_value": None, + "sap_points": None, + "cost": estimated_cost, + } + ]