From 8803feec5e3f54a016ff42605359d0fe5c6e14a0 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 5 Jan 2026 19:34:05 +0000 Subject: [PATCH] added enforce fabric first option --- backend/app/plan/schemas.py | 3 +++ backend/engine/engine.py | 4 ++-- recommendations/optimiser/funding_optimiser.py | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/app/plan/schemas.py b/backend/app/plan/schemas.py index 6f6db328..edac31dc 100644 --- a/backend/app/plan/schemas.py +++ b/backend/app/plan/schemas.py @@ -133,6 +133,9 @@ class PlanTriggerRequest(BaseModel): task_id: Optional[str] = None subtask_id: Optional[str] = None + # Optional flag to trigger a fabric first task + enforce_fabric_first: Optional[bool] = False + @model_validator(mode="after") def check_indexes(self): if (self.index_start is None) != (self.index_end is None): diff --git a/backend/engine/engine.py b/backend/engine/engine.py index eb933cc0..f6990c5c 100644 --- a/backend/engine/engine.py +++ b/backend/engine/engine.py @@ -1066,7 +1066,7 @@ async def model_engine(body: PlanTriggerRequest): budget=body.budget, target_gain=gain, enforce_heat_pump_insulation=True, - enforce_fabric_first=False + enforce_fabric_first=body.enforce_fabric_first ) # if handle the empty case @@ -1119,7 +1119,7 @@ async def model_engine(body: PlanTriggerRequest): # Add best practice measures (ventilation/trickle vents) selected = optimiser_functions.add_best_practice_measures(p.id, solution, recommendations, selected) - # Final flattening + # Final flattening - we pass what the battery SAP score would be, regardless if the battery was selected recommendations[p.id] = optimiser_functions.flatten_recommendations_with_defaults( p.id, recommendations, selected, battery_sap_score ) diff --git a/recommendations/optimiser/funding_optimiser.py b/recommendations/optimiser/funding_optimiser.py index 083b5e99..1d4fc682 100644 --- a/recommendations/optimiser/funding_optimiser.py +++ b/recommendations/optimiser/funding_optimiser.py @@ -681,7 +681,9 @@ def optimise_with_scenarios( # - Only once the fabric has been upgraded, do we consider heating upgrades # This should be wall insulation, roof insulation, floor insulation and windows - fabric_measures = WALL_INSULATION_MEASURES + ROOF_INSULATION_MEASURES + ECO4_ELIGIBILE_FABRIC_MEASURES + fabric_measures = WALL_INSULATION_MEASURES + ROOF_INSULATION_MEASURES + ECO4_ELIGIBILE_FABRIC_MEASURES + [ + "internal_wall_insulation+mechanical_ventilation", "external_wall_insulation+mechanical_ventilation" + ] fabric_only_measures = [ [opt for opt in group if opt["type"] in fabric_measures] for group in optimisation_measures