From 354c8fcb279db1ed0f03fc6839f6aef5574dfa79 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 30 Mar 2026 17:51:13 +0100 Subject: [PATCH] fixing property.property and passing task id --- backend/app/plan/router.py | 4 ++ backend/export/property_scenarios/main.py | 50 ++++++++++++++++++++++- recommendations/Costs.py | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 27151437..db15b09a 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -174,6 +174,8 @@ async def trigger_plan_entrypoint(body: PlanTriggerRequest): service="plan_engine", inputs=data, task_only=True, + source=SourceEnum.PORTFOLIO, + source_id=str(body.portfolio_id), ) subtask_interface = SubTaskInterface() @@ -222,6 +224,8 @@ async def trigger_plan_entrypoint(body: PlanTriggerRequest): service="plan_engine", inputs=data, task_only=False, + source=SourceEnum.PORTFOLIO, + source_id=str(body.portfolio_id), ) data["task_id"] = str(task_id) data["subtask_id"] = str(subtask_id) diff --git a/backend/export/property_scenarios/main.py b/backend/export/property_scenarios/main.py index d38db4c9..8ba1467a 100644 --- a/backend/export/property_scenarios/main.py +++ b/backend/export/property_scenarios/main.py @@ -134,7 +134,7 @@ def handler(event: Mapping[str, Any], context: Optional[Any]) -> Mapping[str, Un body_dict = { "task_id": "test", "subtask_id": "test", - "portfolio_id": 569, + "portfolio_id": 647, "scenario_ids": [], "default_plans_only": True, } @@ -159,6 +159,54 @@ def handler(event: Mapping[str, Any], context: Optional[Any]) -> Mapping[str, Un with db_read_session() as session: exported_files = process_export(payload, session) + # Merge with input + raw_input1 = pd.read_excel( + "/Users/khalimconn-kowlessar/Downloads/eon - 20260323 address sanitisation - Standardised.xlsx", + sheet_name="Standardised Asset List", + ) + raw_input2 = pd.read_excel( + "/Users/khalimconn-kowlessar/Downloads/eon - 20260323 address sanitisation - Standardised.xlsx", + sheet_name="Addresses needing validation", + ) + raw_input = pd.concat([raw_input1, raw_input2], ignore_index=True) + raw_input["epc_os_uprn"] = np.where( + pd.isnull(raw_input["epc_os_uprn"]), + raw_input["ordnance_survey_uprn"], + raw_input["epc_os_uprn"], + ) + raw_input["epc_os_uprn"] = raw_input["epc_os_uprn"].astype(int) + + left_df = raw_input[ + ["epc_os_uprn", "domna_address_1", "landlord_property_type", "landlord_property_type"]].copy() + + combined = left_df.merge( + exported_files["default_plans"], how="right", + left_on="epc_os_uprn", right_on="uprn" + ) + raw_addresses = pd.read_excel( + "/Users/khalimconn-kowlessar/Downloads/North Tyneside Council. EPC D and Below with Type (1).xlsx") + raw_addresses = raw_addresses[["UPRN", "Address 1", "Postcode"]] + raw_addresses["Address 1"] = raw_addresses["Address 1"].str.replace(" ", " ") + raw_addresses = raw_addresses.drop_duplicates("Address 1") + + combined2 = combined.merge( + raw_addresses, how="left", left_on="domna_address_1", right_on="Address 1" + ) + + combined2 = combined2.drop(columns=["landlord_property_id"]) + combined2 = combined2.rename(columns={"UPRN": "landlord_property_id"}) + combined2["epc_os_uprn"] = combined2["epc_os_uprn"].astype("Int64") + combined2.to_excel("/Users/khalimconn-kowlessar/Downloads/EON - recommended measures for review.xlsx") + + removed = raw_addresses[~raw_addresses["UPRN"].isin(combined2["landlord_property_id"])] + + df2 = pd.read_excel( + "/Users/khalimconn-kowlessar/Downloads/20260330 EON - recommended measures for review (1).xlsx" + ) + removed2 = raw_addresses[~raw_addresses["UPRN"].isin(df2["landlord_property_id"])] + + raw_addresses[raw_addresses["Address 1"].duplicated()] + # TODO: Need to handle the exported files - e.g. upload to s3 and email a presigned url _ = exported_files return { diff --git a/recommendations/Costs.py b/recommendations/Costs.py index f2d43339..cb67a90f 100644 --- a/recommendations/Costs.py +++ b/recommendations/Costs.py @@ -209,7 +209,7 @@ class Costs: # Try and get the region after converting the keys to lower self.region = { k.lower(): v for k, v in county_to_region_map.items() - }.get(self.property.property.epc_record.local_authority_label.lower(), None) + }.get(self.property.epc_record.local_authority_label.lower(), None) if self.region is None: logger.warning("No region found for county %s, defaulting to South East England",