mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
include property reference in SapPropertyDetails and excel row dict 🟩
This commit is contained in:
parent
ede2eb970b
commit
1153d19f0e
1 changed files with 17 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue