Model/domain/epc/property_overlays/glazing_overlay.py
Jun-te Kim 88a4badbf7 Decode single/double/triple glazing overrides to SAP codes 🟩
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 13:19:44 +00:00

36 lines
1.4 KiB
Python

"""Map a Landlord-Override glazing value to a glazing Simulation Overlay.
A glazing value is one canonical glazing description carrying type + era
("Double glazing, 2002 or later", "Single glazing", "Triple glazing, 2002 or
later"). The calculator derives each window's U-value from its SAP10
`glazing_type` code via the RdSAP Table 24 cascade, so the overlay decomposes
the value into that code and emits a whole-dwelling `GlazingOverlay` (a landlord
describes the dwelling's glazing as a whole, with no per-window geometry, so
`building_part` is ignored). `_fold_glazing` expands it across every window.
Unresolvable values produce no overlay.
"""
from __future__ import annotations
from typing import Optional
from domain.modelling.simulation import EpcSimulation, GlazingOverlay
# Canonical glazing description → SAP10 glazing-type code (the Table 24 /
# `u_window` cascade enum, `_GLAZING_CODE_TO_UWINDOW` in heat_transmission).
_GLAZING_CODES: dict[str, int] = {
"Single glazing": 1,
"Double glazing, 2002 or later": 2,
"Double glazing, pre-2002": 3,
"Triple glazing, pre-2002": 6,
"Triple glazing, 2002 or later": 9,
}
def glazing_overlay_for(
glazing_value: str, building_part: int
) -> Optional[EpcSimulation]:
code = _GLAZING_CODES.get(glazing_value)
if code is None:
return None
return EpcSimulation(glazing=GlazingOverlay(glazing_type=code))