From 1f53cb3d44aa812836ddc4568d85a337ddf0ea2d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 30 Nov 2023 16:54:42 +0000 Subject: [PATCH] debugging after changing recommendation types to more details versions --- backend/app/plan/router.py | 37 ++++++++++++++++--- backend/app/plan/utils.py | 12 +++--- .../optimiser/optimiser_functions.py | 4 +- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 841415b7..1b84ed72 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -261,7 +261,10 @@ async def trigger_plan(body: PlanTriggerRequest): solution = optimiser.solution selected_recommendations = {r["id"] for r in solution} - if "wall_insulation" in [r["type"] for r in solution]: + + if any(x in [r["type"] for r in solution] for x in [ + "internal_wall_insulation", "external_wall_insulation", "cavity_wall_insulation" + ]): ventilation_rec = [ r for r in recommendations_with_impact if r[0]["type"] == "mechanical_ventilation" ][0] @@ -289,6 +292,7 @@ async def trigger_plan(body: PlanTriggerRequest): recommendations[property_id] = final_recommendations # This is a temporary step, to estimate the impact of the measured on heat demand and carbon + # TODO: This needs to be cleaned up, if it happens to be kept combined_recommendations_scoring_data = [] representative_recs = {} for property_id, property_recommendations in recommendations.items(): @@ -297,6 +301,13 @@ async def trigger_plan(body: PlanTriggerRequest): # Missing types missing_types = list(set([r["type"] for r in property_recommendations if r["type"] not in default_types])) + # We might have a missing type as one of the solid wall options because for a solid wall, you might + # have ewi or iwi but only one of them will be a default + if ("internal_wall_insulation" in default_types) or ("external_wall_insaultion" in default_types): + missing_types = [ + t for t in missing_types if t not in ["internal_wall_insulation", "external_wall_insulation"] + ] + if missing_types: for missed_type in missing_types: missed = [r for r in property_recommendations if r["type"] == missed_type] @@ -393,6 +404,8 @@ async def trigger_plan(body: PlanTriggerRequest): combined_heat_demand["predictions"].values[0] * property_instance.floor_area ) + # We don't want to adjust the heat demand for mechanical ventilation so we add it back on + # We adjust the heat demand figures to align to the UCL paper current_adjusted_energy = AnnualBillSavings.adjust_energy_to_metered( epc_energy_consumption=starting_heat_demand, @@ -412,10 +425,6 @@ async def trigger_plan(body: PlanTriggerRequest): heat_demand_change = ( current_adjusted_energy - expected_adjusted_energy ) - property_instance.set_adjusted_energy( - current_adjusted_energy=current_adjusted_energy, - expected_adjusted_energy=expected_adjusted_energy - ) # update the recommendations # We need to totals for the representative recommendations @@ -450,7 +459,13 @@ async def trigger_plan(body: PlanTriggerRequest): # Finally, insert these values into the final recommendations for rec in property_recommendations: - change_data = representative_rec_data[representative_rec_data["type"] == rec["type"]] + if rec["type"] in ["external_wall_insulation", "internal_wall_insulation"]: + change_data = representative_rec_data[ + representative_rec_data["type"].isin(["external_wall_insulation", "internal_wall_insulation"]) + ] + else: + change_data = representative_rec_data[representative_rec_data["type"] == rec["type"]] + if rec["type"] == "mechanical_ventilation": rec["co2_equivalent_savings"] = 0 rec["heat_demand"] = 0 @@ -463,6 +478,16 @@ async def trigger_plan(body: PlanTriggerRequest): # Update recommendations recommendations[property_id] = property_recommendations + # For expected adjust energy, we don't include mechanical ventilation so we'll add it back on + expected_adjusted_energy = expected_adjusted_energy + representative_rec_data[ + representative_rec_data["type"] == "mechanical_ventilation" + ]["heat_demand"].values[0] + + property_instance.set_adjusted_energy( + current_adjusted_energy=current_adjusted_energy, + expected_adjusted_energy=expected_adjusted_energy + ) + # 1) the property data # 2) the property details (epc) # 3) the recommendations diff --git a/backend/app/plan/utils.py b/backend/app/plan/utils.py index b60bc20f..7aba99c9 100644 --- a/backend/app/plan/utils.py +++ b/backend/app/plan/utils.py @@ -87,7 +87,7 @@ def create_recommendation_scoring_data( scoring_dict[col] = "none" # We update the description to indicate it's insulated - if recommendation["type"] == "wall_insulation": + if recommendation["type"] in ["internal_wall_insulation", "external_wall_insulation", "cavity_wall_insulation"]: # The upgrade made here is to the u-value of the walls and the description of the # insulation thickness scoring_dict["walls_thermal_transmittance_ENDING"] = recommendation["new_u_value"] @@ -106,7 +106,7 @@ def create_recommendation_scoring_data( scoring_dict["walls_insulation_thickness_ENDING"] = "none" # Update description to indicate it's insulate - if recommendation["type"] == "floor_insulation": + if recommendation["type"] in ["solid_floor_insulation", "suspended_floor_insulation", "exposed_floor_insulation"]: if len(recommendation["parts"]) > 1: raise NotImplementedError("Have more than 1 floor insulation part - handle this case") @@ -128,7 +128,7 @@ def create_recommendation_scoring_data( if scoring_dict["floor_insulation_thickness_ENDING"] is None: scoring_dict["floor_insulation_thickness_ENDING"] = "none" - if recommendation["type"] == "roof_insulation": + if recommendation["type"] in ["loft_insulation", "room_roof_insulation", "flat_roof_insulation"]: scoring_dict["roof_thermal_transmittance_ENDING"] = recommendation["new_u_value"] parts = recommendation["parts"] @@ -176,8 +176,10 @@ def create_recommendation_scoring_data( scoring_dict["LIGHTING_ENERGY_EFF_STARTING"] = "Very Good" if recommendation["type"] not in [ - "wall_insulation", "floor_insulation", "roof_insulation", "mechanical_ventilation", "sealing_open_fireplace", - "low_energy_lighting" + "mechanical_ventilation", "sealing_open_fireplace", "low_energy_lighting", + "internal_wall_insulation", "external_wall_insulation", "cavity_wall_insulation", + "loft_insulation", "room_roof_insulation", "flat_roof_insulation", + "solid_floor_insulation", "suspended_floor_insulation", "exposed_floor_insulation" ]: raise NotImplementedError("Implement me") diff --git a/recommendations/optimiser/optimiser_functions.py b/recommendations/optimiser/optimiser_functions.py index 27267186..9b16c6b5 100644 --- a/recommendations/optimiser/optimiser_functions.py +++ b/recommendations/optimiser/optimiser_functions.py @@ -25,10 +25,10 @@ def prepare_input_measures(property_recommendations, goal): if recs[0]["type"] == "mechanical_ventilation": continue - if recs[0]["type"] == "wall_insulation": + if recs[0]["type"] in ["internal_wall_insulation", "external_wall_insulation", "cavity_wall_insulation"]: # Wall insulation and mechanical ventilation are paired. You can't have wall insulation without mechanical # ventilation - + ventilation_cost = ventilation_rec[0]["total"] if ventilation_rec else 0 ventilation_gain = ventilation_rec[0][goal_key] if ventilation_rec else 0