diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 6954d89f..b5acb3c0 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -415,12 +415,10 @@ async def trigger_plan(body: PlanTriggerRequest): # We sum up the SAP points of the default recommendations and calculate a new EPC category. This # category is then used to produce adjusted energy figures - total_sap_points = sum([x["sap_points"] for x in representative_recs[property_id]]) - expected_epc = sap_to_epc(float(property_instance.data["current-energy-efficiency"]) + total_sap_points) expected_adjusted_energy = AnnualBillSavings.adjust_energy_to_metered( epc_energy_consumption=expected_heat_demand, - current_epc_rating=expected_epc, + current_epc_rating=property_instance.data["current-energy-rating"], ) heat_demand_change = ( diff --git a/backend/ml_models/AnnualBillSavings.py b/backend/ml_models/AnnualBillSavings.py index 1519a866..f3e5074a 100644 --- a/backend/ml_models/AnnualBillSavings.py +++ b/backend/ml_models/AnnualBillSavings.py @@ -18,6 +18,8 @@ class AnnualBillSavings: # This is a weighted mean of the price caps, using the consumption figures above as weights PRICE_FACTOR = 0.11183098591549295 + EPC_BANDS = ["G", "F", "E", "D", "C", "B", "A"] + @classmethod def estimate(cls, kwh: float): """ @@ -70,3 +72,22 @@ class AnnualBillSavings: adjusted_consumption = (epc_energy_consumption + consumption_difference) return adjusted_consumption + + @classmethod + def adjust_expected_band(cls, expected_epc_rating, current_epc_rating): + """ + Because of the differing intercepts and intercepts when adjusting, it's possible for + expected_adjusted_energy to be bigger than current_adjusted_energy. In this case, we'll + adjust, against at most 1 EPC band above the curent. This function performs the EPC adjustment + :param expected_epc_rating: The expected EPC rating + :param current_epc_rating: The current EPC rating + """ + + # Find index of expected EPC rating + expected_index = cls.EPC_BANDS.index(expected_epc_rating) + current_index = cls.EPC_BANDS.index(current_epc_rating) + + if expected_index - 1 < current_index: + return current_epc_rating + + return cls.EPC_BANDS[expected_index - 1]