Normalize RdSAP percent_draughtproofed on the 21.0.0 path

PRD #1385 phase 2. 21.0.0 was the last mapper still dropping the lodged
percent_draughtproofed (top-level int) — every other path (17.0/…/21.0.1) reads
it. Dropping it understated the SAP §2 draughtproofing/infiltration credit for
21.0.0 certs.

Verification: new test 1 passed (harvested 21.0.0 sample lodges 100); corpus
6002 passed; SAP-accuracy regressions pass; pyright unchanged (39 -> 39).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-07-01 14:13:17 +00:00
parent 2892ce8560
commit a3a620a7e9
2 changed files with 38 additions and 0 deletions

View file

@ -2142,6 +2142,10 @@ class EpcPropertyDataMapper:
open_chimneys_count=schema.open_chimneys_count or 0,
insulated_door_count=schema.insulated_door_count,
draughtproofed_door_count=schema.draughtproofed_door_count,
# 21.0.0 lodges percent_draughtproofed but the mapper dropped it,
# unlike every other path (17.0/…/21.0.1). Understated the §2
# draughtproofing/infiltration credit.
percent_draughtproofed=schema.percent_draughtproofed,
led_fixed_lighting_bulbs_count=schema.led_fixed_lighting_bulbs_count or 0,
cfl_fixed_lighting_bulbs_count=schema.cfl_fixed_lighting_bulbs_count or 0,
incandescent_fixed_lighting_bulbs_count=schema.incandescent_fixed_lighting_bulbs_count,

View file

@ -0,0 +1,34 @@
"""Regression: the RdSAP-Schema-21.0.0 mapper must carry the lodged
percent_draughtproofed, like every other API path (17.0//21.0.1).
PRD #1385 (mapper normalization). 21.0.0 was the last path still dropping
`percent_draughtproofed` (top-level int, lodged by the schema), understating the
§2 draughtproofing/infiltration credit.
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
# The harvested 21.0.0 sample lodges percent_draughtproofed=100.
_FIXTURE = Path("backend/epc_api/json_samples/RdSAP-Schema-21.0.0/epc.json")
def _load() -> dict[str, Any]:
data: dict[str, Any] = json.loads(_FIXTURE.read_text())
assert data["schema_type"] == "RdSAP-Schema-21.0.0"
return data
def test_21_0_0_carries_percent_draughtproofed() -> None:
data = _load()
assert data["percent_draughtproofed"] == 100
epc = EpcPropertyDataMapper.from_api_response(data)
# Was dropped to None on the 21.0.0 path; now carried through.
assert epc.percent_draughtproofed == 100