diff --git a/backend/Property.py b/backend/Property.py index c1568de0..98df4ceb 100644 --- a/backend/Property.py +++ b/backend/Property.py @@ -643,6 +643,15 @@ class Property: https://www.sciencedirect.com/science/article/pii/S0378778823002542 :return: """ + # We should adjust the costs first and then calculate the energy consumption + # These are the costs at the time that the EPC was created - we need a cost based on today's prices so + # we do the following: + # 1) Score the models to get kwh for heating and hot water + # 2) Adjust the kwh values with the UCL paper + # 3) Convert the kwh values to costs today using current prices + # + # For the moment, we'll just use the same cost for lighting, since the value is quite low + scoring_df = pd.DataFrame([self.epc_record.prepared_epc]) # Change columns from underscores to hyphens scoring_df.columns = [ @@ -651,30 +660,6 @@ class Property: for col in ["heating_kwh", "hot_water_kwh"]: scoring_df[col] = None - # We should adjust the costs first and then calculate the energy consumption - lighting_cost = float(self.data["lighting-cost-current"]) - heating_cost = float(self.data["heating-cost-current"]) - hot_water_cost = float(self.data["hot-water-cost-current"]) - - adjusted_heating_cost = AnnualBillSavings.adjust_energy_cost_to_metered( - epc_energy_cost=heating_cost, - current_epc_rating=self.data["current-energy-rating"], - ) - - adjusted_hot_water_cost = AnnualBillSavings.adjust_energy_cost_to_metered( - epc_energy_cost=hot_water_cost, - current_epc_rating=self.data["current-energy-rating"], - ) - - adjusted_lighting_cost = AnnualBillSavings.adjust_energy_cost_to_metered( - epc_energy_cost=lighting_cost, - current_epc_rating=self.data["current-energy-rating"], - ) - - scoring_df["heating-cost-current"] = [adjusted_heating_cost] - scoring_df["hot-water-cost-current"] = [adjusted_hot_water_cost] - scoring_df["lighting-cost-current"] = [adjusted_lighting_cost] - energy_consumption_client.data = None heating_prediction = energy_consumption_client.score_new_data( new_data=scoring_df, target="heating_kwh" @@ -685,30 +670,82 @@ class Property: )[0] # We convert the lighting cost into kwh, just using the price cap - lighting_kwh = float(adjusted_lighting_cost) / AnnualBillSavings.ELECTRICITY_PRICE_CAP + lighting_kwh = float(self.data["lighting-cost-current"]) / AnnualBillSavings.ELECTRICITY_PRICE_CAP - appliances_energy_use = AnnualBillSavings.estimate_appliances_energy_use(total_floor_area=self.floor_area) - appliances_energy_cost = appliances_energy_use * AnnualBillSavings.ELECTRICITY_PRICE_CAP + appliances_kwh = AnnualBillSavings.estimate_appliances_energy_use(total_floor_area=self.floor_area) - total_energy_consumption = heating_prediction + hot_water_prediction + lighting_kwh + appliances_energy_use - - self.current_adjusted_energy = AnnualBillSavings.adjust_energy_to_metered( - epc_energy_consumption=total_energy_consumption, + adjusted_heating_kwh = AnnualBillSavings.adjust_energy_cost_to_metered( + epc_energy_cost=heating_prediction, current_epc_rating=self.data["current-energy-rating"], ) + adjusted_hot_water_kwh = AnnualBillSavings.adjust_energy_cost_to_metered( + epc_energy_cost=hot_water_prediction, + current_epc_rating=self.data["current-energy-rating"], + ) + + adjusted_lighting_kwh = AnnualBillSavings.adjust_energy_cost_to_metered( + epc_energy_cost=lighting_kwh, + current_epc_rating=self.data["current-energy-rating"], + ) + + adjusted_applicances_kwh = AnnualBillSavings.adjust_energy_cost_to_metered( + epc_energy_cost=appliances_kwh, + current_epc_rating=self.data["current-energy-rating"], + ) + + # Convert to cost + if self.heating_energy_source == "Electricity": + adjusted_heating_cost = adjusted_heating_kwh * AnnualBillSavings.ELECTRICITY_PRICE_CAP + elif self.heating_energy_source == "Natural Gas": + adjusted_heating_cost = adjusted_heating_kwh * AnnualBillSavings.GAS_PRICE_CAP + else: + raise NotImplementedError("Not implemented cost for this fuel type") + + if self.hot_water_energy_source == "Electricity": + adjusted_hot_water_cost = adjusted_hot_water_kwh * AnnualBillSavings.ELECTRICITY_PRICE_CAP + elif self.hot_water_energy_source == "Natural Gas": + adjusted_hot_water_cost = adjusted_hot_water_kwh * AnnualBillSavings.GAS_PRICE_CAP + else: + raise NotImplementedError("Not implemented cost for this fuel type") + + adjusted_lighting_cost = adjusted_lighting_kwh * AnnualBillSavings.ELECTRICITY_PRICE_CAP + + adjusted_appliances_cost = adjusted_applicances_kwh * AnnualBillSavings.ELECTRICITY_PRICE_CAP + + # Sum up the adjusted kwh figures + self.current_adjusted_energy = ( + adjusted_heating_kwh + adjusted_hot_water_kwh + adjusted_lighting_kwh + adjusted_applicances_kwh + ) + self.energy_cost_estimates = { - "heating": adjusted_heating_cost, - "hot_water": adjusted_hot_water_cost, - "lighting": adjusted_lighting_cost, - "appliances": appliances_energy_cost + "adjusted": { + "heating": adjusted_heating_cost, + "hot_water": adjusted_hot_water_cost, + "lighting": adjusted_lighting_cost, + "appliances": adjusted_appliances_cost + }, + "original": { + "heating": float(self.data["heating-cost-current"]), + "hot_water": float(self.data["hot-water-cost-current"]), + "lighting": float(self.data["lighting-cost-current"]), + "appliances": appliances_kwh + } } self.energy_consumption_estimates = { - "heating": heating_prediction, - "hot_water": hot_water_prediction, - "lighting": lighting_kwh, - "appliances": appliances_energy_use + "adjusted": { + "heating": adjusted_heating_kwh, + "hot_water": adjusted_hot_water_kwh, + "lighting": adjusted_lighting_kwh, + "appliances": adjusted_applicances_kwh + }, + "original": { + "heating": heating_prediction, + "hot_water": hot_water_prediction, + "lighting": lighting_kwh, + "appliances": appliances_kwh + } } self.expected_energy_bill = (