From 1153d19f0e7f98a97c1a8a916a404b83a8ceaa99 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 15 Apr 2026 11:57:53 +0000 Subject: [PATCH] =?UTF-8?q?include=20property=20reference=20in=20SapProper?= =?UTF-8?q?tyDetails=20and=20excel=20row=20dict=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/ecmk_fetcher/xml_processor.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/ecmk_fetcher/xml_processor.py b/backend/ecmk_fetcher/xml_processor.py index 8c9d0d1e..a9f7490f 100644 --- a/backend/ecmk_fetcher/xml_processor.py +++ b/backend/ecmk_fetcher/xml_processor.py @@ -3,6 +3,8 @@ from typing import Any, List, Optional, TypedDict from etl.xml_survey_extraction.XmlParser import PROPERTY_TYPE_LOOKUP +from backend.ecmk_fetcher.reports import build_property_id + # This file should ultimately live somewhere different, probably class Floor(TypedDict): @@ -25,6 +27,7 @@ class BuildingPart(TypedDict): class SapPropertyDetails(TypedDict): + reference: str address: str property_type: str building_parts: List[BuildingPart] @@ -69,14 +72,18 @@ def parse_rdsap(xml_string: str) -> SapPropertyDetails: if addr_elem is None: raise ValueError("Address element not found") + address_line_1: str = addr_elem.findtext("r:Address-Line-1", default="", namespaces=ns) + postcode: str = addr_elem.findtext("r:Postcode", default="", namespaces=ns) + address_parts: List[str] = [ - addr_elem.findtext("r:Address-Line-1", default="", namespaces=ns), + address_line_1, addr_elem.findtext("r:Address-Line-2", default="", namespaces=ns), addr_elem.findtext("r:Post-Town", default="", namespaces=ns), - addr_elem.findtext("r:Postcode", default="", namespaces=ns), + postcode, ] address: str = ", ".join(part for part in address_parts if part) + reference: str = build_property_id(address_line_1, postcode) # --- Property Type --- prop_type_text = root.findtext(".//r:Property-Type", namespaces=ns) @@ -164,6 +171,7 @@ def parse_rdsap(xml_string: str) -> SapPropertyDetails: building_parts.append(building_part) result: SapPropertyDetails = { + "reference": reference, "address": address, "property_type": property_type, "building_parts": building_parts, @@ -179,6 +187,7 @@ def _normalise_identifier(identifier: str) -> str: def flatten_sap_property(details: SapPropertyDetails) -> dict[str, Any]: row: dict[str, Any] = {} + row["reference"] = details["reference"] row["address"] = details["address"] row["property_type"] = details["property_type"] @@ -189,7 +198,9 @@ def flatten_sap_property(details: SapPropertyDetails) -> dict[str, Any]: floor_prefix = f"{prefix}_floor_{i}" row[f"{floor_prefix}_area_m2"] = floor["area_m2"] row[f"{floor_prefix}_height_m"] = floor["height_m"] - row[f"{floor_prefix}_heat_loss_perimeter_m"] = floor["heat_loss_perimeter_m"] + row[f"{floor_prefix}_heat_loss_perimeter_m"] = floor[ + "heat_loss_perimeter_m" + ] row[f"{floor_prefix}_party_wall_length_m"] = floor["party_wall_length_m"] roof = bp.get("roof") @@ -199,6 +210,8 @@ def flatten_sap_property(details: SapPropertyDetails) -> dict[str, Any]: if "insulation_location" in roof: row[f"{prefix}_roof_insulation_location"] = roof["insulation_location"] if "insulation_thickness_mm" in roof: - row[f"{prefix}_roof_insulation_thickness_mm"] = roof["insulation_thickness_mm"] + row[f"{prefix}_roof_insulation_thickness_mm"] = roof[ + "insulation_thickness_mm" + ] return row