Model/c6_cohort.py
Daniel Roth bd3a7ac317 Charge the C6 half heat-network standing charge on a water-only dwelling's fuel cost worksheet 🟥
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 13:37:19 +00:00

41 lines
1.7 KiB
Python

"""Which 21.0.1-corpus certs are in #1606's C6 half-charge cohort?
Cohort = WHC in {950,951,952} AND space main is NOT a heat network.
"""
import json
from pathlib import Path
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
from datatypes.epc.domain.field_mappings import is_heat_network_main
from domain.sap10_calculator.rdsap.cert_to_inputs import (
_first_main_heating, _heat_network_standing_charge_gbp,
_WATER_HEAT_NETWORK_ONLY_CODES,
)
path = Path("backend/epc_api/json_samples/RdSAP-Schema-21.0.1/corpus.jsonl")
certs = [json.loads(l) for l in path.read_text().splitlines() if l.strip()]
hits = []
for c in certs:
epc = EpcPropertyDataMapper.from_api_response(c)
whc = epc.sap_heating.water_heating_code if epc.sap_heating else None
if whc not in _WATER_HEAT_NETWORK_ONLY_CODES:
continue
m1 = _first_main_heating(epc)
net = is_heat_network_main(m1)
hits.append({
"rrn": c.get("rrn") or c.get("lmk_key"),
"uprn": c.get("uprn"),
"addr": (c.get("address1") or "")[:34],
"whc": whc,
"main_code": m1.sap_main_heating_code if m1 else None,
"main_is_network": net,
"net_standing": _heat_network_standing_charge_gbp(epc, m1),
"in_C6_half_cohort": not net,
})
print(f"WHC 950/951/952 certs in 21.0.1 corpus: {len(hits)}\n")
for h in hits:
flag = " <== C6 HALF COHORT" if h["in_C6_half_cohort"] else ""
print(f" rrn={h['rrn']} uprn={h['uprn']}")
print(f" addr={h['addr']!r} whc={h['whc']} main={h['main_code']} "
f"network_main={h['main_is_network']} net_standing={h['net_standing']}{flag}")
print(f"\nIn C6 half cohort: {sum(h['in_C6_half_cohort'] for h in hits)}")