From 6f1159e871b7339ec248c4ad9192bd3564b5e9a8 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 14 Jan 2026 00:01:01 +0000 Subject: [PATCH] made adjustment to force any already installed properties to be included in a plan --- .../h_reset_estimated_epcs.py | 15 +++++----- .../k_deck_stats.py | 30 +++++++++++++++++++ .../n_fixing_already_installed_bug.py | 0 recommendations/Recommendations.py | 12 ++++++++ sfr/principal_pitch/2_export_data.py | 12 ++++---- 5 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 etl/customers/peabody/Nov 2025 Consulting Project/n_fixing_already_installed_bug.py diff --git a/etl/customers/peabody/Nov 2025 Consulting Project/h_reset_estimated_epcs.py b/etl/customers/peabody/Nov 2025 Consulting Project/h_reset_estimated_epcs.py index d22d0f9e..67ff2c85 100644 --- a/etl/customers/peabody/Nov 2025 Consulting Project/h_reset_estimated_epcs.py +++ b/etl/customers/peabody/Nov 2025 Consulting Project/h_reset_estimated_epcs.py @@ -5,7 +5,7 @@ from backend.app.db.connection import db_read_session from backend.app.db.models.portfolio import PropertyModel, PropertyDetailsEpcModel from backend.app.db.models.recommendations import Plan -PORTFOLIO_ID = 433 +PORTFOLIO_ID = 435 with db_read_session() as session: # Get all properties from PropertyDetailsEpcModel, where estimated is True, for portfolio 419 @@ -49,12 +49,13 @@ sal = sal.drop_duplicates(subset=['epc_os_uprn']) estimated_to_refresh = sal[sal["epc_os_uprn"].isin(estimated_uprns_list)].copy() SCENARIOS = [ - 871, # EPC C - fabric first, no solid floor, ashp 3.0 - 863, # EPC B, No EWI/IWI, No Solid Floor, ASHP 3.0 COP - 862, # EPC B - No solid floor, ASHP COP 3.0 - 861, # EPC C, No EWI/IWI, No Solid Floor, ASHP 3.0 COP - 859, # EPC C - no solid floor, ashp 3.0 - 885, # EPC B - fabric first, no solid floor, ashp 3.0 + # 871, # EPC C - fabric first, no solid floor, ashp 3.0 + # 863, # EPC B, No EWI/IWI, No Solid Floor, ASHP 3.0 COP + # 862, # EPC B - No solid floor, ASHP COP 3.0 + # 861, # EPC C, No EWI/IWI, No Solid Floor, ASHP 3.0 COP + # 859, # EPC C - no solid floor, ashp 3.0 + # 885, # EPC B - fabric first, no solid floor, ashp 3.0 + 908, 909, 910 ] # Get all plans, associated to these properties - the property IDs are in estimated_epc_ids diff --git a/etl/customers/peabody/Nov 2025 Consulting Project/k_deck_stats.py b/etl/customers/peabody/Nov 2025 Consulting Project/k_deck_stats.py index 179c0878..cd7fba63 100644 --- a/etl/customers/peabody/Nov 2025 Consulting Project/k_deck_stats.py +++ b/etl/customers/peabody/Nov 2025 Consulting Project/k_deck_stats.py @@ -459,3 +459,33 @@ modelled_epc_band_comparison = reduced_sample["SAP Band"].value_counts( right_on="SAP Band", suffixes=("_reduced_sample", "_overall") ) + +# Testing measures +m1 = pd.read_excel( + "/Users/khalimconn-kowlessar/Documents/hestia/Customers/Peabody/Nov 2025 Consulting Project/Final SAL/EPC C - no " + "solid floor, ashp 3.0 - 20250113 final.xlsx" +) +m2 = pd.read_excel( + "/Users/khalimconn-kowlessar/Documents/hestia/Customers/Peabody/Nov 2025 Consulting Project/Final SAL/EPC C - no " + "solid floor, no EWI or IWI, ashp 3.0 - 20250113 final.xlsx" +) + +compare = m1.merge( + m2, + left_on="uprn", + right_on="uprn", + suffixes=("_ewi_iwi", "_no_ewi_iwi") +) + +# Which properties get done under the no EWI/IWI scenario that do not under the EWI/IWI scenario +only_no_ewi_iwi = compare[ + (compare["total_retrofit_cost_ewi_iwi"] == 0) & + (compare["total_retrofit_cost_no_ewi_iwi"] != 0) + ] + +(m1["total_retrofit_cost"] > 0).sum() +(m2["total_retrofit_cost"] > 0).sum() + +with_ewi_projects = compare[compare["total_retrofit_cost_no_ewi_iwi"] > 0] + +z = with_ewi_projects[pd.isnull(with_ewi_projects["total_retrofit_cost_ewi_iwi"])] diff --git a/etl/customers/peabody/Nov 2025 Consulting Project/n_fixing_already_installed_bug.py b/etl/customers/peabody/Nov 2025 Consulting Project/n_fixing_already_installed_bug.py new file mode 100644 index 00000000..e69de29b diff --git a/recommendations/Recommendations.py b/recommendations/Recommendations.py index 2466ea4e..ab13134d 100644 --- a/recommendations/Recommendations.py +++ b/recommendations/Recommendations.py @@ -86,6 +86,18 @@ class Recommendations: inclusions_full = [MEASURE_MAP[x] if x in MEASURE_MAP else x for x in self.inclusions] exclusions_full = [MEASURE_MAP[x] if x in MEASURE_MAP else x for x in self.exclusions] + + # if we have already installed measures, we need to include them so they get factored into the baseline + # this is something we'll likely need to remove + if self.property_instance.already_installed: + # We make sure that any already installed measures are included + for rec in self.property_instance.already_installed: + if rec not in inclusions_full: + inclusions_full.append(rec) + + # We remove them from the exclusions if they are there + exclusions_full = [e for e in exclusions_full if e not in self.property_instance.already_installed] + # We need to unlist any lists, but we should check if they're lists first inclusions_full = [ item for sublist in inclusions_full for item in (sublist if isinstance(sublist, list) else [sublist]) diff --git a/sfr/principal_pitch/2_export_data.py b/sfr/principal_pitch/2_export_data.py index e36a6297..a3042a56 100644 --- a/sfr/principal_pitch/2_export_data.py +++ b/sfr/principal_pitch/2_export_data.py @@ -16,14 +16,14 @@ from collections import defaultdict # SCENARIOS = [389] PORTFOLIO_ID = 435 # Peabody SCENARIOS = [ - 908, - 909, - # 910, + # 908, + # 909, + 910, ] scenario_names = { - 908: "EPC C - no solid floor, ashp 3.0", - 909: "EPC C - no solid floor, no EWI or IWI, ashp 3.0", - # 910: "EPC B - no solid floor, no EWI, ashp 3.0" + # 908: "EPC C - no solid floor, ashp 3.0", + # 909: "EPC C - no solid floor, no EWI or IWI, ashp 3.0", + 910: "EPC B - no solid floor, no EWI, ashp 3.0" }