diff --git a/backend/documents_parser/tests/test_summary_pdf_mapper_chain.py b/backend/documents_parser/tests/test_summary_pdf_mapper_chain.py index fa79dabe..a9ad62b0 100644 --- a/backend/documents_parser/tests/test_summary_pdf_mapper_chain.py +++ b/backend/documents_parser/tests/test_summary_pdf_mapper_chain.py @@ -789,6 +789,33 @@ def test_summary_2225_full_chain_sap_within_spec_floor_of_worksheet() -> None: assert abs(result.sap_score_continuous - worksheet_unrounded_sap) < _ASHP_COHORT_CHAIN_TOLERANCE +def test_summary_2636_full_chain_sap_within_spec_floor_of_worksheet() -> None: + # Arrange — cert 2636-0525-2600-0401-2296 (Summary_000898.pdf): + # Mitsubishi PUZ-WM50VHA, mid-terrace house with **alt-wall + + # cantilever** — the most complex geometry in the ASHP cohort. + # Worksheet "SAP value" lodges 86.2641. + # + # Closed by two combined slices: + # - S0380.12: alt-wall window-location parser fix (walls W/K + # 20.5595 → 20.0240 = worksheet exact). + # - S0380.13: cantilever gate accepts "House" descriptive form + # in addition to the schema enum "0" (allowing the Summary + # mapper's descriptive property_type to trigger the cantilever + # detection that slice 102f-prep.9 added on the API path). + pages = _summary_pdf_to_textract_style_pages(_SUMMARY_000898_PDF) + site_notes = ElmhurstSiteNotesExtractor(pages).extract() + epc = EpcPropertyDataMapper.from_elmhurst_site_notes(site_notes) + + # Act + result = calculate_sap_from_inputs( + cert_to_inputs(epc, prices=SAP_10_2_SPEC_PRICES) + ) + + # Assert — ±0.07 ASHP-cohort spec-floor tolerance. + worksheet_unrounded_sap = 86.2641 + assert abs(result.sap_score_continuous - worksheet_unrounded_sap) < _ASHP_COHORT_CHAIN_TOLERANCE + + def test_summary_3800_full_chain_sap_within_spec_floor_of_worksheet() -> None: # Arrange — cert 3800-8515-0922-3398-3563 (Summary_000901.pdf / # dr87-0001-000901.pdf) is the third ASHP cohort cert to close on diff --git a/domain/sap10_calculator/worksheet/heat_transmission.py b/domain/sap10_calculator/worksheet/heat_transmission.py index 82077dbb..0baf31a4 100644 --- a/domain/sap10_calculator/worksheet/heat_transmission.py +++ b/domain/sap10_calculator/worksheet/heat_transmission.py @@ -109,10 +109,23 @@ _COS_30_DEG: Final[float] = cos(radians(30.0)) # BP0: 195%), neither of which the worksheet treats as cantilever. _CANTILEVER_MIN_AREA_M2: Final[float] = 1.0 _CANTILEVER_MAX_RATIO: Final[float] = 0.25 -# EPC API `property_type` strings that flag a dwelling as a house (not -# flat). Cantilever detection only fires for houses — flats with very -# small floor=0 areas (stairwell access) would otherwise over-count. -_PROPERTY_TYPE_HOUSE: Final[str] = "0" +# `property_type` values that flag a dwelling as a house (not flat). +# Cantilever detection only fires for houses — flats with very small +# floor=0 areas (stairwell access) would otherwise over-count. +# The API mapper produces the EPC schema enum-as-string ("0"), the +# Elmhurst Summary mapper produces the descriptive form ("House"), and +# the hand-built worksheet fixtures use the descriptive form too. The +# canonical check below accepts both so the cantilever path fires +# uniformly regardless of source-mapper encoding. +_PROPERTY_TYPES_HOUSE: Final[frozenset[str]] = frozenset({"0", "House"}) + + +def _is_house(property_type: Optional[str]) -> bool: + """True when `epc.property_type` encodes a house (not flat / maisonette + / park home). Tolerant of both the API schema's enum-as-string ("0") + and the Summary mapper / hand-built fixture descriptive form + ("House").""" + return property_type in _PROPERTY_TYPES_HOUSE @dataclass(frozen=True) @@ -765,7 +778,7 @@ def heat_transmission_from_cert( # thermal bridges via its area on (31). cantilever_area = ( _round_half_up(geom.get("cantilever_floor_area_m2", 0.0), _AREA_ROUND_DP) - if epc.property_type == _PROPERTY_TYPE_HOUSE + if _is_house(epc.property_type) else 0.0 ) if cantilever_area > 0: