Model/datatypes/epc/schema
Jun-te Kim 5e0963593a Route full-SAP certs lodged under SAP-Schema-16.x to the full-SAP mapper
A full-SAP cert (assessment_type=SAP, the as-designed LIG-* new-builds) lodged
under a SAP-Schema-16.x version failed to map with:

  ValueError: RdSapSchema17_1: missing required field 'door_count'

— crashing the property's modelling_e2e subtask. 89 distinct properties in the
2026-06-24 run hit this; ~22 of every 30 sampled are this full-SAP shape.

Root cause: from_api_response dispatches on the schema_type STRING only, and the
SAP-Schema-16.x branch assumed a single shape — "reduced-field (RdSAP-shaped)" —
sending every 16.x cert through _normalize_sap_schema_16_x -> RdSapSchema17_1.
But the SAP-Schema-16.x name covers two structurally different certs:

  * reduced RdSAP (assessment_type=RdSAP): top-level door_count / glazed_area
    band / construction-code building parts.
  * full SAP    (assessment_type=SAP): measured shape — sap_opening_types +
    structured sap_building_parts carrying measured U-values and door/window
    OPENINGS, with NO top-level door_count (the door is an opening). These omit
    the reduced-only count fields, so the reduced normaliser failed loud on the
    first one it checks (door_count) — and 14 others behind it.

Force-fitting a full-SAP cert to the reduced RdSAP schema was the bug: the data
was never missing, it was being validated against the wrong schema.

Fix: discriminate on shape (_is_full_sap_cert: assessment_type=SAP AND
sap_opening_types present) and route full-SAP 16.x certs to the existing
full-SAP 17.1 mapper, which reads the real measured openings (the lodged
0.9x2.1m door -> door_count 1) — no reduced-field defaulting. The only field the
16.x full-SAP shape omits that SapSchema17_1 needs is `tenure` (register
metadata, no SAP effect), defaulted. Reduced 16.x certs (assessment_type=RdSAP,
no opening types) are untouched — all pinned reduced 16.x fixtures stay on the
RdSAP path.

Regression test pins a real full-SAP-16.0 cert (0293-...-8795, lodged 83) mapping
via the full-SAP path + the reduced 16.2 cert staying on the RdSAP path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 15:16:51 +00:00
..
tests Route full-SAP certs lodged under SAP-Schema-16.x to the full-SAP mapper 2026-06-24 15:16:51 +00:00
__init__.py first draft dataclasses with loading tests 2026-04-10 11:33:17 +00:00
common.py first draft dataclasses with loading tests 2026-04-10 11:33:17 +00:00
helpers.py slice 10.5: PhotovoltaicArray on SAP10 schema + EpcPropertyData 2026-05-16 16:00:25 +00:00
rdsap_schema_17_0.py Map RdSAP-Schema-17.0 certs to EpcPropertyData 🟩 2026-06-12 12:45:19 +00:00
rdsap_schema_17_1.py Dispatch and map RdSAP-Schema-17.1 certs end-to-end 🟩 2026-06-11 12:21:17 +00:00
rdsap_schema_18_0.py Map Not-Defined glazing code to a valid type for windowless 18.0 certs 🟩 2026-06-11 11:55:46 +00:00
rdsap_schema_19_0.py Map RdSAP-Schema-19.0 certs to EpcPropertyData 🟩 2026-06-12 12:29:36 +00:00
rdsap_schema_20_0_0.py fix(mapper): handle 'ND' multiple_glazing_type on RdSAP-Schema-20.0.0 2026-06-15 06:43:55 +00:00
rdsap_schema_21_0_0.py Scope 21.0.0 widening to fields the skipped certs actually omit 2026-06-24 08:35:36 +00:00
rdsap_schema_21_0_1.py fix(mapper): map dropped §6.1 non-separated conservatory (API) 2026-06-16 23:37:25 +00:00
sap_schema_17_1.py Fall back to nested has_hot_water_cylinder for full-SAP certs 2026-06-24 10:43:18 +00:00