Model/domain/epc/property_overlays/construction_age_band_overlay.py
Jun-te Kim 406365753b Resolve a landlord age-band override onto the main building part 🟩
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 13:41:35 +00:00

39 lines
1.3 KiB
Python

"""Map a Landlord-Override construction-age-band value to a fabric Simulation
Overlay.
A construction-age-band value is the RdSAP England-&-Wales letter code (A..M)
the calculator's U-value cascades key on (`SapBuildingPart.construction_age_band`,
read via `.strip().upper()` against the letter-code bands). The overlay targets
the override's building part and sets the band; an unrecognised code produces no
overlay. Re-dating a part re-derives its construction-default U-values, so this
is the highest-leverage fabric override.
"""
from __future__ import annotations
from typing import Optional
from datatypes.epc.domain.epc_property_data import BuildingPartIdentifier
from domain.modelling.simulation import BuildingPartOverlay, EpcSimulation
# RdSAP England-&-Wales construction age bands (letter codes A..M).
_VALID_AGE_BANDS: frozenset[str] = frozenset("ABCDEFGHIJKLM")
def age_band_overlay_for(
age_band_value: str, building_part: int
) -> Optional[EpcSimulation]:
band = age_band_value.strip().upper()
if band not in _VALID_AGE_BANDS:
return None
identifier = (
BuildingPartIdentifier.MAIN
if building_part == 0
else BuildingPartIdentifier.extension(building_part)
)
return EpcSimulation(
building_parts={
identifier: BuildingPartOverlay(construction_age_band=band)
}
)