Commit graph

5504 commits

Author SHA1 Message Date
Khalim Conn-Kowlessar
7901dda455 Slice S0380.167: EES codes WEA/REA/OEA → electricity (electric storage 11-14 unblock)
Adds three Elmhurst EES (Energy Efficiency Standard) codes to
`_ELMHURST_MAIN_HEATING_EES_TO_FUEL_CODE` so the mapper can derive the
main heating fuel for electric storage / direct-acting certs whose
Elmhurst Summary §14.0 does not lodge a "Main Heating Fuel Type"
string (same pattern as the solid-fuel block above):

  "WEA": 30,  # electric warm-air storage
  "REA": 30,  # resistive electric (corpus electric 12 SAP 691)
  "OEA": 30,  # other electric (corpus electric 13/14 SAP 701)

All route to Table 32 standard-electricity code 30; the cascade
resolves the actual price tier (high vs low rate) downstream via
`_rdsap_tariff(epc)` keyed off `meter_type`.

The corpus carries 4 electric-storage variants on the 18-hour tariff:

  electric 11 — WEA + SAP 515 (warm-air electric)
  electric 12 — REA + SAP 691
  electric 13 — OEA + SAP 701
  electric 14 — OEA + SAP 701  (differs from 13 by emitter / controls)

Pre-slice all 4 raised `MissingMainFuelType` per S0380.132. Post-slice
all 4 EXACT on first try across all 4 metrics:

  electric 11: ΔSAP_c +0.0000  Δcost +£0.0000  ΔCO2 −0.0000  ΔPE −0.0000
  electric 12: ΔSAP_c +0.0000  Δcost +£0.0000  ΔCO2 −0.0000  ΔPE −0.0000
  electric 13: ΔSAP_c +0.0000  Δcost −£0.0000  ΔCO2 +0.0000  ΔPE −0.0000
  electric 14: ΔSAP_c +0.0000  Δcost −£0.0000  ΔCO2 +0.0000  ΔPE −0.0000

Closure on first try because the cascade was already wired for the
electric-storage path (SAP 10.2 Table 4a codes 515 / 691 / 701, Table
4e Group 4 storage controls, Table 5a pump-gain wet-gate from S0380.160,
S0380.144 secondary-fraction by sub-row); only the Elmhurst EES → fuel
mapping was missing.

Moves electric 11/12/13/14 out of `_BLOCKED_BY_MISSING_MAIN_FUEL_TYPE`
into `_EXPECTATIONS` at ±0.0000. Blocked tier now: 11 variants
(community heating × 5, no system, oil 2-6).

Tests:
  - test_elmhurst_main_heating_ees_maps_electric_storage_codes_to_electricity
  - corpus pins: electric 11/12/13/14 expected residuals = ±0.0000

Cascade-OK tier: 30 variants (up from 25), all SAP / cost / CO2 / PE
EXACT (< 1e-4) vs Elmhurst worksheet on every metric.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 09:53:01 +00:00
Khalim Conn-Kowlessar
589a8631b7 Slice S0380.166: Elmhurst "Bulk LPG" label → API code 27 (mapper unblock)
Adds the single missing dict entry that lets cert `pcdb 3` cascade:

  `_ELMHURST_MAIN_FUEL_TO_SAP10["Bulk LPG"] = 27`

API code 27 = "LPG (not community)" — routes via:
  - `API_FUEL_TO_TABLE_12[27] = 2` (SAP 10.2 Table 12 bulk LPG: £62
    standing, 6.74 p/kWh, 0.241 CO2, 1.141 PE; spec PDF p.189)
  - `API_FUEL_TO_TABLE_32[27] = 2` (RdSAP 10 Table 32 bulk LPG: £70
    standing, 7.60 p/kWh; spec PDF p.95)

Pre-slice the mapper produced `main_fuel_type=''` for any Elmhurst
fixture lodging "Bulk LPG" as fuel type, so the cascade strict-raised
`MissingMainFuelType` per S0380.132. The legacy `"LPG bulk"` label
(different word order) maps to API code 6 = wood logs — a pre-existing
oddity unexercised by any live fixture; left untouched per
[[feedback-bigger-slices-for-uniform-work]] (different label, different
fix).

Cascade closure `pcdb 3` (Vokera Linea LPG combi 83.10 %, PCDB index
8262, no cylinder, 18-hour tariff) — EXACT on first try across all 4
metrics:

  cascade  SAP_c = 49.2953    worksheet = 49.2953    Δ = +0.0000
  cascade  cost  = £1165.81   worksheet = £1165.81   Δ = +0.0000
  cascade  CO2   = 3367.95    worksheet = 3367.95    Δ = +0.0000
  cascade  PE    = 13936.60   worksheet = 13936.60   Δ = +0.0000

Closure on first try because the cascade was already fully wired for
the gas/oil/LPG path; the Elmhurst label was the only gap. Moves
pcdb 3 out of `_BLOCKED_BY_MISSING_MAIN_FUEL_TYPE` into `_EXPECTATIONS`
at ±0.0000.

Blocked tier now: 15 variants (community heating × 5, electric storage
11-14, no system, oil 2-6).

Tests:
  - test_elmhurst_main_fuel_to_sap10_maps_bulk_lpg_to_api_code_27
  - corpus pin: pcdb 3 expected residuals = ±0.0000 on all 4 metrics

912 pass / 0 fail; pyright net-zero 43 → 43.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 09:48:37 +00:00
Khalim Conn-Kowlessar
3de52bcb90 Slice S0380.165: §9.4.11 boiler-interlock -5pp applies AFTER Eq D1, not before
SAP 10.2 §9.4.11 (PDF p.30): "The efficiency of gas and liquid fuel
boilers for both space and water heating is reduced by 5% if the
boiler is not interlocked for space and water heating."

S0380.141 had subtracted the -5pp from BOTH `Pwinter` and `Psummer`
PCDB / Table 4b seasonal efficiencies BEFORE running the SAP 10.2
Appendix D §D2.1 (2) Equation D1 monthly cascade. The Elmhurst P960
worksheet for `pcdb 1` (PCDB 716 oil boiler, Pwinter 65 / Psummer 53,
Cylinder Stat=No → no interlock) shows the -5pp is applied to the
η_water,monthly OUTPUT of Eq D1, NOT to its inputs. The two
interpretations diverge because Eq D1's reciprocal weighting (1/η_w
and 1/η_s) is non-linear in η.

Worked example for pcdb 1 Jan (Q_space=1409.77, Q_water=387.86):

  Old cascade:  Eq D1(60, 48, …) = 56.9292 %       (off −0.04 pp)
  Worksheet:    Eq D1(65, 53, …) = 61.9725 %
                                    −5pp = 56.9725 %  ≡ (217)m_jan ✓

Across all 12 months the post-Eq-D1 form matches worksheet (217)m to
1e-4 every month. Cascade HW kWh: 7068.41 → 7063.96 (= worksheet (219)
total exactly), Δ −4.45 kWh.

The spec text "reduced by 5%" does not explicitly state pre- vs post-
Eq D1 ordering. Per [[feedback-software-no-special-handling]] mirror
the Elmhurst engine — the worksheet output is unambiguous.

Changes:
  - `_apply_water_efficiency` gains a `interlock_penalty_pp: float = 0.0`
    kwarg. Eq D1 branch runs on raw (Pwinter, Psummer), then subtracts
    `interlock_penalty_pp / 100` from each monthly efficiency before
    dividing.
  - Caller (`cert_to_inputs` orchestrator) now passes the raw seasonal
    efficiencies in `eq_d1_winter_summer_pct` + the penalty separately.
    The pre-Eq-D1 `eq_d1_winter_summer_pct[0] -= 5` block is removed.
  - SH-side `eff -= 0.05` (line 5349) is unchanged — the SH cascade
    doesn't go through Eq D1, just `(98c)m / eff_sh`.

Closures `pcdb 1`:
  ΔSAP_c −0.0108 → +0.0000 (1e-4)
  Δcost  +£0.24  → +£0.0000
  ΔCO2   +1.33   → +0.0000
  ΔPE    +5.70   → −0.0000

No regressions on the other 25 cascade-OK variants — the gate is
`no_interlock AND eq_d1_winter_summer_pct is not None`, which fires
only when Cylinder Stat=No on a gas/oil boiler cert. The 6 Elmhurst
U985 cohort + cohort-2 Elmhurst fixtures all lodge Cylinder Stat=Yes
(interlock present) → no penalty fires; cohort-1 ASHP certs lodge no
cylinder thermostat at all but route through Appendix N3 instead of
Eq D1. 38 cohort-2 + 9 ASHP golden fixtures all PASS unchanged.

The 41-variant heating-systems corpus cascade-OK tier is now CLOSED:
all 25 variants SAP / cost / CO2 / PE EXACT vs Elmhurst worksheet at
abs < 1e-3 (most < 1e-4). Σ|ΔSAP_c| = 0.0001 (= floating-point noise).

Tests:
  - test_apply_water_efficiency_applies_interlock_penalty_after_equation_d1
  - test_apply_water_efficiency_interlock_penalty_zero_keeps_raw_eq_d1

911 pass / 0 fail; pyright net-zero 43 → 43.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 09:44:10 +00:00
Khalim Conn-Kowlessar
df4d271d3b docs: handover post S0380.164
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 09:27:54 +00:00
Khalim Conn-Kowlessar
302db131c6 Slice S0380.164: Elmhurst-mirror §12.4.4 summer-immersion CO2/PE double-count
SAP 10.2 §12.4.4 (PDF p.36-37): "With open fire back boilers or closed
room heaters with boilers, an alternative system (electric immersion)
may be provided for heating water in summer. In that case water
heating is provided by the boiler for months October to May and by the
alternative system for months June to September."

The spec-literal CO2 / PE formula multiplies summer immersion fuel by
the Table 12d / 12e monthly cascade (per Table 12 footnotes (s) and
(t): "monthly factors in Table 12d/12e should be used in the SAP
worksheet"). The BRE-approved Elmhurst engine adds an extra
`summer_fuel × Table 12 annual electric` term ON TOP of the monthly
cascade for dual-rate tariffs — same Elmhurst-mirror shape as S0380.163
(§8.1) but additive rather than substitutive. Cost is computed
cleanly per spec — the double-count quirk only affects the (264) HW
CO2 and (278) HW PE factor lines.

Worksheet evidence (heating-systems corpus property 001431,
`solid fuel 2` — Table 4a code 158 closed-room-heater + back boiler,
65 % winter η + 100 % summer η, anthracite, 18-hour off-peak tariff):

  (62)m heat        303.12 .. 168.95 .. 175.91 .. 300.40 kWh
  winter fuel (W)   = 2205.80 / 0.65 = 3393.51 kWh anthracite
  summer fuel (S)   = 684.55 / 1.00  =  684.55 kWh immersion
  total fuel        = (219) = 4078.06 kWh

  (264) HW CO2  = 4078.06 × 0.3710 = 1513.15 kg/yr
    = W × 0.395 + S × (0.116 monthly_summer + 0.136 annual)
    = 1340.43 + 79.61 + 93.10 = 1513.14 ✓ within rounding

  (278) HW PE   = 4078.06 × 1.3771 = 5616.04 kWh/yr
    = W × 1.064 + S × (1.429 monthly_summer + 1.501 annual)
    = 3610.69 + 977.84 + 1027.51 = 5616.04 ✓ exact

The +annual term is precisely `S × Table 12 electric factor` and
matches the SF2 corpus pin's ΔCO2 = −93.10 and ΔPE = −1027.51 exactly.
Per [[feedback-software-no-special-handling]] mirror the engine.

Cascade rule (post-slice):

  STANDARD tariff       → winter × anth_annual + Σ wh_summer_m × Table 12d/e
                          (spec-literal, unchanged)
  7h / 10h / 18h / 24h → winter × anth_annual + Σ wh_summer_m × Table 12d/e
                          + S_fuel × Table 12 annual electric (Elmhurst mirror)

Closures `solid fuel 2`:
  ΔCO2 −93.10 → +0.0000 EXACT
  ΔPE  −1027.51 → +0.0000 EXACT
ΔSAP and Δcost remain EXACT (cascade cost path was already correct).

The 41-variant heating-systems corpus is now closed on its 25-variant
cascade-OK tier: all 25 SAP / cost / CO2 / PE EXACT (|Δ| < 1e-3) vs
the Elmhurst worksheet. Only `pcdb 1` carries a sub-tolerance gap
(−0.011 SAP / +5.7 PE — PCDB Eq D1 cascade gap on PCDF index 716, a
separate small slice).

⚠ Single-cert evidence

SF2 is the only §12.4.4 fixture in the corpus (`solid fuel 1` =
code 156 is an empty folder; no other variant exercises a back-boiler
combo with summer immersion). Per the handover ≥2-cert rule for new
§8 divergence rows, this slice was admitted under an explicit
exception: the divergence shares its shape with §8.1 (S0380.163's
Table 12 annual mirror for dual-rate HW), and the math matches the
worksheet to within rounding. The new §8.2 row is tagged with a
"⚠ Single-cert evidence" subsection so future agents know to revisit
if a second §12.4.4 cert worksheet ever diverges from this rule.

Tests:
  - test_section_12_4_4_hw_blend_mirrors_elmhurst_summer_annual_pe_co2_double_count
  - test_section_12_4_4_hw_blend_standard_tariff_keeps_spec_literal_monthly_cascade

909 pass / 0 fail; pyright net-zero 43 → 43.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 09:27:47 +00:00
Khalim Conn-Kowlessar
ef7fe01282 docs: handover post S0380.160..163
Wraps the four slices closing the heating-systems corpus from
Σ|ΔSAP_c| 1.24 → 0 (25/25 cascade-OK variants SAP/cost/CO2/PE
EXACT, except solid fuel 2 summer-immersion-blend artifact).

Highest-leverage next slice: close solid fuel 2 (the only remaining
open variant in the cascade-OK tier) via the S0380.154 blend code
path — likely a parallel Elmhurst-mirror gate for the summer-
immersion CO2/PE factors.

Other open fronts: 16 blocked-tier mapper extensions; pcdb 1 sub-
tolerance -0.011 SAP; cohort-2 golden residuals tightening per
[[feedback-golden-residuals-near-zero]].

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 08:51:21 +00:00
Khalim Conn-Kowlessar
9896644c4c Slice S0380.163: Elmhurst-mirror HW PE/CO2 factor on dual-rate tariffs
SAP 10.2 Table 12 footnote (t) (PDF p.189): "PE factors for grid
electricity vary by month. The average figure given in this table is
therefore not used directly. Instead the monthly factors given in
Table 12e should be used in the SAP worksheet." Footnote (s) says the
same for CO2 / Table 12d. Read literally, monthly factors apply to
every electric end-use including dual-rate HW.

The BRE-approved Elmhurst rdSAP engine doesn't follow that reading
for HW. The 41-variant heating-systems corpus controlled-variable
fixture lodges worksheet (278) "Water heating (low-rate cost)" with
factor **1.5010 PE / 0.136 CO2** (Table 12 annual flat) across every
dual-rate tariff cert, while applying the monthly Table 12e/12d
cascade to lighting (1.5338 winter-weighted) and secondary heating
(1.5715) on the same certs. It's an engine implementation choice,
not a documented spec exception.

Per [[feedback-software-no-special-handling]] the calculator
contract is bit-faithful replication of the engine, not literal
compliance with the spec text. This slice flips cascade
`_hot_water_primary_factor` + `_hot_water_co2_factor_kg_per_kwh` to
accept a `tariff: Tariff` parameter:

  - STANDARD tariff       → Table 12e/12d monthly cascade weighted
                            by HW demand seasonality (unchanged from
                            S0380.71 / .72, matches cohort-1 ASHP
                            standard-tariff worksheet)
  - 7-hour / 10-hour /
    18-hour / 24-hour     → Table 12 annual flat (1.501 / 0.136)
                            matching the Elmhurst worksheet (278)
                            "Water heating (low-rate cost)" row

Per-line walk on electric 3 (18-hour tariff, electric immersion HW,
2384.116 kWh annual):

  worksheet (278) factor = 1.5010
  cascade pre-slice      = 1.5214   delta = +0.0204
  (1.5214 - 1.5010) × 2384.116 = +48.66 kWh/yr PE — EXACT match
  the corpus residual pin.

Same shape for CO2: worksheet 0.1360, cascade pre-slice 0.1410,
delta +0.0050 × 2384.116 = +11.95 kg/yr.

Closures across the 18-variant deferred lighting-PE cohort
(electric 1/2/3/5/6/7/8/9 + solid fuel 4/5/6/7/8/9/10/11 + ashp +
gshp):
  ΔCO2 +6.31 / +11.95 → ±0.0000 EXACT
  ΔPE  +25.51 / +48.66 → ±0.0000 EXACT
  ΔSAP_c / Δcost unchanged at ±0.0000 EXACT (already closed
  pre-slice by S0380.156..162).

All 25 cascade-OK variants in the heating-systems corpus now
SAP / cost / CO2 / PE EXACT vs worksheet on all 4 metrics, with
solid fuel 2 as the only remaining open residual (separate
S0380.154 summer-immersion-blend CO2/PE artifact — deferred).

Documented in
`domain/sap10_calculator/docs/SAP_CALCULATOR.md §8.1
"HW PE/CO2 factors on dual-rate tariffs use Table 12 annual"` —
the master doc now carries a new §8 "Elmhurst-mirrored spec
divergences" section for cases like this. Validation tally
refreshed from stale "930/930" to current "941/941".

No regressions on the 6 Elmhurst U985 fixtures (gas combi
STANDARD tariff — unaffected) or the cohort-1 ASHP certs
(STANDARD tariff — unaffected). The dual-rate gate fires only
on the 4 off-peak tariffs.

Verbatim spec quote retained for reference (SAP 10.2 Table 12
footnote (t), PDF p.189):
  "PE factors for grid electricity vary by month. The average
   figure given in this table is therefore not used directly.
   Instead the monthly factors given in Table 12e should be used
   in the SAP worksheet."

Tests: 907 pass (+1), 0 fail. Pyright net-zero (43 → 43).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 08:34:20 +00:00
Khalim Conn-Kowlessar
8d465d973f Slice S0380.162: SAP 10.2 Appendix N3.1 default pump gain for electric HPs
SAP 10.2 Appendix N3.1 (PDF p.105) "Circulation pump and fan":
"For electric heat pumps: The electricity used by the water
circulation pump or fan is included within the calculated annual
space and hot water heating efficiency and is not included in
worksheet (230c). **The default heat gain from Table 5a is included
via worksheet (70).**"

This rule applies the Table 5a row "Central heating pump in heated
space" GAIN (3 / 10 / 7 W per pump-age bucket) to electric heat
pumps even though the pump ELECTRICITY is hidden in the COP and
excluded from (230c). The "Not applicable for electric heat pumps
from database" clause in Table 5a footnote a) scopes only to the
PCDB-Table-362 cascade case (Appendix N1.2.1: "For heat pumps held
in the PCDB ... a single water circulation pump serving the heat
emitters is sufficient" — pump kWh AND gain embedded in COP).

S0380.160 over-stripped the gain by zeroing pump_w for every HP
category-4 main, conflating the PCDB-Table-362 case with the Table-4a
default cascade. This slice refines the HP gate in
`_any_main_system_has_central_heating_pump`:
  - Cat 4 HP WITH `main_heating_index_number` lodged (PCDB Table
    362) → continue (skip; pump in COP per N1.2.1);
  - Cat 4 HP with SAP code in `_TABLE_4A_WARM_AIR_SAP_CODES` (Cat 5
    warm-air HPs distribute via ducted air, no water circulation
    pump; warm-air fan handled separately by Table 5a "Warm air
    heating system fans" row, S0380.161) → continue;
  - Otherwise (Cat 4 HP, Table 4a default cascade, water-emitter)
    → apply Table 5a default per Appendix N3.1.

Per-line walk on ashp (SAP code 214 air-to-water HP, Cat 4, no PCDB,
"Post 2013" pump age):
  worksheet (70)[Jan] = 3.0000 W
  cascade pre-slice    = 0.0000 W      delta = -3.000 W
The -3 W winter gain shortfall over-stated cascade (84) Total gains
by -3 W in heating months → cascade SH demand +12.27 kWh/yr
(cascade 9302 vs worksheet 9290), pushing continuous SAP down 0.024
because the cost residual was driven by the +1.5 kWh × 12 month
shortfall flowing through the £0.0741 low-rate cost.

Closures:
  ashp:  ΔSAP -0.0240 → +0.0000 EXACT, Δcost +£0.55 → +£0.00 EXACT
  gshp:  ΔSAP -0.0178 → -0.0000 EXACT, Δcost +£0.41 → -£0.00 EXACT

ΔPE +36 → +25.51 (and ΔCO2 +7.33 → +6.31) — residuals narrow to the
Elmhurst-vs-spec HW PE annual-vs-monthly Table 12e/12d quirk only
(same pattern as the 16-variant lighting-PE deferred cohort,
scaled by HW kWh = 1138 vs 2384 → 25.51 vs 48.66). Cohort
Σ |ΔSAP_c| 0.07 → 0.03; all 25 cascade-OK variants now SAP+cost EXACT.

Cohort-1 (cert 0380 et al.) golden fixtures unaffected — those certs
lodge `main_heating_index_number` (PCDB Table 362) → HP gate skips
correctly → (70) = 0 preserved. Cert 000565 (HP main 1 + gas boiler
main 2) unaffected — wet-boiler branch fires for main 2.

Verbatim spec quote (SAP 10.2 Appendix N3.1, PDF p.105):
  "For electric heat pumps: The electricity used by the water
   circulation pump or fan is included within the calculated annual
   space and hot water heating efficiency and is not included in
   worksheet (230c). The default heat gain from Table 5a is
   included via worksheet (70)."

Tests: 906 pass (+1), 0 fail. Pyright net-zero (35 → 35).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 23:59:29 +00:00
Khalim Conn-Kowlessar
482ce88b55 Slice S0380.161: SAP 10.2 Table 5a warm-air fan gain (SFP × 0.04 × V)
SAP 10.2 Table 5a (PDF p.177) row "Warm air heating system fans
a) c)" computes the gain as SFP × 0.04 × V (W). Footnote c) sets
the default SFP to 1.5 W/(l/s) when no PCDB warm-air-unit record
is lodged; footnote a) applies the heating-season-only mask
(zero in summer months). Footnote c) further omits the gain when
the dwelling has balanced whole-house mechanical ventilation
(MVHR / MV) — same omission as the Table 4f kWh-side footnote e).

Pre-slice the cascade's `internal_gains_from_cert` only wired the
central-heating-pump row of Table 5a; the warm-air-fan gain helper
(`warm_air_heating_fan_w`) existed but was unwired. The kWh-side
parallel (Table 4f, 136.35 kWh/yr) was wired in S0380.158 — this
slice closes the symmetry on the gain side.

Per-line walk on electric 2 (SAP code 524 = Cat 5 ASHP with
warm-air distribution, V = 227.25 m³, no balanced MV):

  worksheet (70)[Jan] = 13.6350 W
  cascade (70)[Jan]   = 0.0000 W      delta = -13.635 W
  worksheet (98c)[Jan] = 1600.43 kWh
  cascade (98c)[Jan]  = 1608.12 kWh   delta = +7.69 kWh

13.635 W = 1.5 × 0.04 × 227.25 exactly. The -13.6 W winter gain
shortfall propagates through the §7 utilisation cascade and over-
states cascade SH demand by ~57 kWh/yr (cascade 9483 vs worksheet
9426), under-charging cost by ~£2.50 with opposite sign to the
S0380.156-.158 closures.

Fix: new `_any_main_system_has_warm_air_distribution(epc)` +
`_has_balanced_mechanical_ventilation(epc)` predicates in
`internal_gains.py`, mirroring `cert_to_inputs._TABLE_4A_WARM_AIR_SAP_CODES`
+ `_BALANCED_MV_KIND_NAMES` (kept here as siblings so the worksheet
layer stays free of rdsap deps). Orchestrator wires
`warm_air_heating_fan_w(sfp=1.5, dwelling_volume_m3)` into the
heating-season term of `pumps_fans_monthly_w` when warm-air
distribution is present and balanced MV is not.

Closures electric 2:
  ΔSAP_c -0.1087 → -0.0000 EXACT
  Δcost  +£2.50 → -£0.00 EXACT
  ΔCO2   +16.54 → +11.95 (joins lighting-PE deferred cohort)
  ΔPE    +97.69 → +48.66 (joins lighting-PE deferred cohort)

Electric 2 joins the 15-variant lighting-PE deferred cohort
(electric 1 + electric 3/5/6/7/8/9 + solid fuel 5/6/7/8 + solid
fuel 4/9/10/11 + electric 2) where SAP/cost are EXACT but PE/CO2
carry an Elmhurst-vs-spec MONTHLY-factor offset (cohort uses
Table 12 annual factors on the off-peak HW immersion line; spec
mandates Table 12d/12e monthly per the header).

Verbatim spec quote (SAP 10.2 Table 5a row "Warm air heating
system fans a) c)", PDF p.177):
  "Warm air heating system fans a) c)  SFP × 0.04 × V"
  Footnote c): "SFP is the specific fan power from the database
    record for the warm air unit if applicable; otherwise
    1.5 W/(l/s). These values of SFP include an in-use factor.
    If the heating system is a warm air unit and there is balanced
    whole house mechanical ventilation, the gains for the warm air
    system should not be included."
  Footnote a): "... Set to zero in summer months. ..."

Σ |ΔSAP_c| across 25-variant cohort: 0.18 → 0.07 (~60% reduction).
No regressions on the other 24 variants or any golden fixture —
gate keyed on Table 4a warm-air SAP code frozenset (only electric
2 in the corpus has a code in that set).

Tests: 905 pass (+1), 0 fail. Pyright net-zero (35 → 35).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 23:16:57 +00:00
Khalim Conn-Kowlessar
af34ad9846 Slice S0380.160: SAP 10.2 Table 5a wet-pump gate for central heating gain
SAP 10.2 Table 5a (PDF p.177) row "Central heating pump in heated
space" only applies to mains with a water-loop circulation pump.
Footnote a) names two exclusions verbatim ("Does not apply if a
heating system used solely for domestic hot water. ... Not applicable
for electric heat pumps from database."), and the row's name carries
the implicit third: dry mains with no central heating pump (electric
storage heaters, electric direct-acting, solid-fuel room heaters
without back-boilers) — the row simply doesn't list them.

Pre-slice `internal_gains_from_cert` gated only on Note a) (HP
exclusion), applying `central_heating_pump_w(date_category=...)` to
every non-HP main. The default UNKNOWN-date branch added 7 W of pump
gain to (70)m for every dry-system fixture in the controlled-variable
corpus, even though the worksheet (70)m = 0 every month.

Per-line walk on electric 3 (SAP code 401 "Manual charge control"):

  cascade (73)[Jan] = 640.21 W
  worksheet (73)[Jan] = 633.21 W      delta = +7.00 W
  cascade (70)[Jan] = 7.00 W
  worksheet (70)[Jan] = 0.00 W        Table 5a inapplicable

The +7 W winter-month gain lowered cascade SH demand by ~38 kWh/yr
(cascade 11050 vs worksheet 11088). At Table 32 18-hour low-rate
~7.4 p/kWh that's £2.50/yr under-charging — matching the cluster's
uniform Δcost = -£1.96..-£2.80 pattern. Continuous SAP rose ~+0.10
because cost dominates the ECF.

Fix: new `_any_main_system_has_central_heating_pump(epc)` predicate
in `internal_gains.py`, mirroring `cert_to_inputs._is_wet_boiler_main`
(S0380.149 — Table 4f kWh side). Wet if any non-HP main lodges:
  - sap_main_heating_code in {101-141, 151-161, 191-196} (gas/oil/
    solid-fuel/electric boilers per Table 4a/4b),
  - main_heating_index_number (PCDB Table 322 record),
  - main_heating_category in {1, 2} (RdSAP central heating), OR
  - heat_emitter_type in {1, 3} (radiators / fan-coil per Table 4d).

Dead `_all_main_systems_are_heat_pumps` helper removed (the new
predicate subsumes its role).

Cluster closures (10 variants):
  electric 3:    SAP +0.1215 → -0.0000, cost -£2.80 → -£0.00
  electric 5:    SAP +0.1081 → -0.0000, cost -£2.49 → -£0.00
  electric 6:    SAP +0.1081 → -0.0000, cost -£2.49 → -£0.00
  electric 7:    SAP +0.1017 → -0.0000, cost -£2.34 → -£0.00
  electric 8:    SAP +0.0941 → -0.0000, cost -£2.17 → -£0.00
  electric 9:    SAP +0.1199 → -0.0000, cost -£2.76 → -£0.00
  solid fuel 4:  SAP +0.0850 → -0.0000, cost -£1.96 → -£0.00
  solid fuel 9:  SAP +0.1072 → -0.0000, cost -£2.47 → -£0.00
  solid fuel 10: SAP +0.1134 → +0.0000, cost -£2.61 → -£0.00
  solid fuel 11: SAP +0.0912 → +0.0000, cost -£2.10 → +£0.00

Σ |ΔSAP_c| across 25-variant cohort: 1.24 → 0.18. All 10 cluster
variants now join the lighting-PE +48.66 / CO2 +11.95 deferred
cohort (Elmhurst-vs-spec monthly factor quirk, same shape as
electric 1 + solid fuel 5/6/7/8 from prior closures).

Verbatim spec quote (SAP 10.2 Table 5a row 1, PDF p.177):
  "Central heating pump in heated space, 2013 or later  3 a)"
  "Central heating pump in heated space, 2012 or earlier  10 a)"
  "Central heating pump in heated space, unknown date  7 a)"

The row name ("Central heating pump") gates by construction: dry
systems have no central heating pump and the row's three sub-rows
don't apply.

No regressions on the other 31 variants or any golden fixture; the
6 Elmhurst U985 fixtures lodge PCDB index → the new predicate
returns True → pump_w unchanged.

Tests: 904 pass (+1), 0 fail. Pyright net-zero (35 → 35).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 23:02:42 +00:00
Khalim Conn-Kowlessar
0261f446f0 docs: handover post S0380.156..159
Captures the per-line walk discipline used to close electric 2 + 5
across four slices (.156 Table 3 WHC=903 primary-loss, .157 Table 2b
note b) WHC=903 ×0.9, .158 Table 4f warm-air heating fans, .159
Table 4a Cat 7 R tariff-aware dispatch). Σ |ΔSAP_c| across the
25-variant heating-systems corpus dropped from 2.87 → 1.21 (58%
reduction). All variants now sit under 0.3 SAP.

Next-slice candidate: the 9-variant cluster at ±0.09..0.12 SAP
(electric 3/5/6/7/8/9 + sf 4/9/10/11) — uniform pattern suggesting
a shared shave-the-residual fix. Worth a per-line walk on one
cluster variant before accepting the prior "Elmhurst-vs-spec quirk"
framing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 22:30:59 +00:00
Khalim Conn-Kowlessar
fba45d1111 Slice S0380.159: SAP 10.2 Table 4a R tariff-aware dispatch for electric storage
SAP 10.2 Table 4a (PDF p.166) Cat 7 "Electric storage heaters"
splits the responsiveness R between two sub-tables:

  Off-peak tariff:
    Slimline storage heaters       ... R = 0.2  402
    Convector storage heaters      ... R = 0.2  403
    Slimline + Celect-type control ... R = 0.4  405
    Convector + Celect-type ctrl   ... R = 0.4  406
  24-hour heating tariff:
    Slimline storage heaters       ... R = 0.4  402
    Convector storage heaters      ... R = 0.4  403
    Slimline + Celect-type control ... R = 0.6  405
    Convector + Celect-type ctrl   ... R = 0.6  406

Per SAP 10.2 §12.4.3 (PDF p.36) the 18-hour tariff has electricity
at low rate for 18 hours per day with at most 6h of interruption /
2h max each — operationally equivalent to 24-hour for storage-heater
charging. The cascade therefore routes EIGHTEEN_HOUR + TWENTY_FOUR_
HOUR through the 24-hour Table 4a sub-row.

Pre-slice `_responsiveness` keyed on `sap_main_heating_code` only
and returned R=0.2 for code 402 regardless of tariff. The existing
docstring already flagged the gap:

    402: 0.20,  # Slimline storage heaters (24-hr tariff: 0.40)
    ... "promote to (sap_code, tariff) lookup when 24-hour fixture
    surfaces; until then the off-peak default applies (under-shoots
    R for the 24-hour case)."

Per-line walk on electric 5 (sap_main_heating_code=402 +
meter_type="18 Hour"): cascade T_living (87)[Jan] = 20.1213 vs
worksheet 19.6519, (92)[Jan] = 18.6996 vs worksheet 18.2063, (93)
[Jan] = 19.0996 vs worksheet 18.6063 (cascade +0.4933 K throughout
the cascade). Back-solve from worksheet T_living=19.6519 via the
Table 9b Tsc formula:

  Tsc(R=0.4) = 0.6 × (21-2) + 0.4 × (4.3 + 0.9933 × 705.4/210.23)
             = 11.4 + 0.4 × 7.6325 = 14.4528

  ΔT = 21 - 14.4528 = 6.5472
  u_sum = 0.5 × 6.5472 × (7² + 8²) / (24 × 11.43) = 1.3481
  T_living = 21 - 1.3481 = 19.6519 EXACT match.

Adds:
  - `_CONTINUOUS_CHARGING_TARIFFS: frozenset[Tariff]` = {EIGHTEEN_
    HOUR, TWENTY_FOUR_HOUR} — the tariffs treated as "24-hour
    heating" for Table 4a R selection.
  - `_RESPONSIVENESS_24_HOUR_OVERRIDE_BY_SAP_CODE: dict[int, float]`
    — the override table for codes 402/403/405/406 (404, 407, 409
    keep the same R in both sub-tables).
  - `tariff: Optional[Tariff]` parameter to `_responsiveness`, with
    the override consulted before the off-peak default.
  - Tariff threaded through both call sites of MIT cascade (rating
    + demand paths) via `tariff_from_meter_type`.

Closures electric 5:
  ΔSAP −1.1759 → +0.1081 (91% reduction)
  Δcost +£27.09 → −£2.49
  ΔCO2 +62.72 → +7.30 kg
  ΔPE +438.03 → +0.07 kWh (essentially EXACT)

Electric 5 now joins the same residual cluster as electric 3/6/7/8/
9 (+0.09..+0.12 SAP, −£2..−£3 cost, +£7 CO2) — the cluster that
the prior handovers suspected was a shared shave-the-residual gap.

No regressions on the other 24 cohort variants. Extended handover
suite: 903 pass / 0 fail (was 902 — +1 from the new AAA test).
Pyright net-zero (43 → 43).

Σ |ΔSAP_c| across the 25-variant cohort: 2.30 → 1.24 (~46%
reduction from this slice).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 22:25:51 +00:00
Khalim Conn-Kowlessar
8843df1b46 Slice S0380.158: SAP 10.2 Table 4f warm-air heating system fans
SAP 10.2 Table 4f (PDF p.174) row "Warm air heating system fans"
+ footnote e) — verbatim:

  Warm air heating system fans e)        SFP × 0.4 × V

  e) SFP is the specific fan power from the database record for the
     warm air unit if applicable; otherwise 1.5 W/(l/s). These values
     of SFP include the in-use factor.
     If the heating system is a warm air unit and there is balanced
     whole house mechanical ventilation, the electricity for warm
     air circulation should not be included in addition to the
     electricity for mechanical ventilation. However it is included
     for a warm air system and MEV or PIV from outside.
     V is the volume of the dwelling in m³.

Per Table 4a (PDF p.165-166), warm-air systems are:
  - Category 5: heat pumps with warm-air distribution (codes 521,
    523, 524 electric; 525, 526, 527 gas-fired)
  - Category 9: warm-air systems NOT heat pump (501-511, 520 gas-
    fired; 512-514 liquid-fired; 515 Electricaire electric)

Pre-slice the cascade's `_table_4f_additive_components` docstring
explicitly listed "(230b) Warm-air heating fans + (230c) for warm-
air pump" as "Not yet wired" — every Cat 5 / Cat 9 warm-air corpus
variant resolved `pumps_fans_kwh_per_yr` to 0. For electric 2 (code
524 Cat 5 air-source warm-air HP, no MV, V = 227.25 m³), the P960
worksheet block 11a (249) lodges 136.35 kWh × 13.67 p/kWh = £18.64
where the cascade computed 0.

New `_TABLE_4A_WARM_AIR_SAP_CODES` frozenset (22 codes) + leaf helper
`_table_4f_warm_air_heating_fans_kwh(main, dwelling_volume_m3,
has_balanced_mv)` wired at the orchestrator pumps_fans summation
alongside the existing circulation-pump and gas-flue-fan helpers.
Footnote-e balanced-MV omission reads `epc.sap_ventilation.
mechanical_ventilation_kind` via the new
`_has_balanced_mechanical_ventilation` predicate (returns True for
MVHR / MV; False for MEV / PIV / NATURAL).

Per-line walk evidence: cascade `pumps_fans_kwh_per_yr` = 0.0000 vs
worksheet (249) = 136.3500 = 1.5 × 0.4 × 227.25 exactly. Default SFP
from footnote e matches; PCDB warm-air-unit SFP lookup deferred
until a fixture exercises it.

Closures electric 2:
  pumps_fans_kwh_per_yr: 0 → 136.35 (EXACT match to worksheet)
  ΔSAP +0.7002 → −0.1087 (residual swung past worksheet — the +0.70
    pre-slice was an under-counted-fan offset; spec-correct fix lands
    just past zero, exposing a small upstream SH cascade gap likely
    in the Cat 5 warm-air HP Table 4a SH efficiency or Table 9c MIT
    cascade for warm-air mains — follow-up slice)
  Δcost −£16.14 → +£2.50
  ΔCO2 −2.37 → +16.54 kg
  ΔPE −108.58 → +97.69 kWh

No regressions on the other 24 cohort variants — the warm-air-code
gate fires only when `sap_main_heating_code` is in the new frozenset
and only electric 2 has a warm-air SAP code in the corpus. Extended
handover suite: 902 pass / 0 fail (was 901 — +1 from the new AAA
test). Pyright net-zero (43 → 43).

Σ |ΔSAP_c| across the 25-variant cohort: 2.87 → 2.30 (~20%
reduction from this slice).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 21:56:03 +00:00
Khalim Conn-Kowlessar
a2a4b6824a Slice S0380.157: SAP 10.2 Table 2b note b) WHC=903 electric-immersion guard
SAP 10.2 Table 2b note b) (PDF p.159) — verbatim:

  Multiply Temperature Factor by 0.9 if there is separate time
  control of domestic hot water (boiler systems, warm air systems
  and heat pump systems).

The parenthetical list restricts the rule to systems where the heat
generator (boiler / warm-air / HP) is the device heating the
cylinder. Electric immersion is NOT in that list because the
immersion isn't a heat-generator system feeding DHW — it sits inside
the cylinder. The ×0.9 multiplier reflects shorter cylinder-heating
periods when a boiler / HP / warm-air operates on a separate timer
for DHW vs SH; if the heat generator doesn't feed the cylinder at all
(because the immersion does), there's no such timing effect.

Pre-slice `_separately_timed_dhw` returned True for any Cat 4 HP
main BEFORE consulting WHC (line 3872 `if main.main_heating_category
== 4: return True`). For electric 2 (sap_main_heating_code=524 Cat 5
warm-air ASHP, main_heating_category=4 per Elmhurst mapper, WHC=903
electric immersion + cylinder + cylinder thermostat lodged), the
cat-4 branch fired before the existing `_is_electric_water` check
could route the cert to False. The cascade applied ×0.9 to the
Temperature Factor (53), pulling (55) from 1.2294 → 1.1064 → cascade
annual (56) = 403.87 vs worksheet (56) annual = 448.73.

Same WHC=903 principle as the prior slice S0380.156 (Table 3 zero-
loss list for electric immersion): when HW is independent of the
main heating, main-heating-specific DHW rules don't apply — even
when the main happens to be a HP / boiler / warm-air system.

Fix: new top-of-function `if epc.sap_heating.water_heating_code ==
_WHC_ELECTRIC_IMMERSION: return False` guard in
`_separately_timed_dhw`. Reuses the constant introduced in S0380.156.

Closures electric 2:
  Cylinder (56) storage loss annual 403.87 → 448.73 (matches
  worksheet 1.2294 × 365 = 448.73 EXACT within rounding)
  HW kWh demand 2339.24 → 2384.12 (matches worksheet (62)/(64) =
  2384.116 EXACT)
  ΔSAP +0.8118 → +0.7002
  Δcost −£18.71 → −£16.14
  ΔCO2 −7.21 → −2.37 kg
  ΔPE −161.68 → −108.58 kWh

The remaining +0.70 SAP residual is a separate upstream gap (likely
warm-air-HP SH cascade or Table 4a SH efficiency for code 524) —
follow-up slice.

No regressions on the other 24 cohort variants. Cohort-1 ASHP certs
(Cat 4 HP + WHC=901 = HW from HP + cylinder) keep ×0.9 as before
because their WHC=901 doesn't trigger the new guard. Extended
handover suite: 901 pass / 0 fail (was 900 — +1 from the new AAA
test). Pyright net-zero (43 → 43).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 20:56:52 +00:00
Khalim Conn-Kowlessar
02092c8041 Slice S0380.156: SAP 10.2 Table 3 WHC=903 electric-immersion zero-loss guard
SAP 10.2 Table 3 (PDF p.160) verbatim:

  Primary loss is set to zero for the following:
      Electric immersion heater
      Combi boiler ...
      CPSU ...
      Boiler and thermal store within a single casing
      Separate boiler and thermal store connected by no more than 1.5
      m of insulated pipework
      Direct-acting electric boiler
      Heat pump (...) with hot water vessel integral to package

The Elmhurst WHC=903 lodging signals exactly the first row: "HW from
a separate electric immersion heater" — the cylinder is heated by an
immersion element inside the tank, no primary pipework between any
heat generator and the cylinder. The rule is universal: regardless
of what main heating exists for space heating, electric immersion
means no primary circuit means no primary loss.

Pre-slice `_primary_loss_applies` only consulted `water_heating_code`
in the Table 4a wet-boiler branch (codes 151-161 / 191-196). The Cat
4 HP branch returned True unconditionally when no PCDB record was
lodged; the Cat 1/2 boiler branch returned True unconditionally; the
PCDB Table 322 + Table 4b non-PCDB branches likewise. For the
electric 2 corpus variant (sap_main_heating_code=524 Cat 5 warm-air
ASHP, main_heating_category=4 per Elmhurst mapper, no PCDB record,
WHC=903 + cylinder), the Cat-4 branch falsely returned True and the
cascade added ~510 kWh/yr primary loss to a system with no primary
circuit at all.

Per-line walk discipline applied: cascade `water_heating_from_cert`
output dump showed `primary_loss_monthly_kwh_annual = 509.98` while
worksheet (59)m = 0 every month → spec lookup found Table 3 verbatim
"Electric immersion heater" zero-loss line.

Adds `_WHC_ELECTRIC_IMMERSION: Final[int] = 903` constant + a
top-of-function `if water_heating_code == _WHC_ELECTRIC_IMMERSION:
return False` guard that fires before any of the system-type-keyed
branches.

Closures electric 2:
  HW kWh 2849.22 → 2339.24 (matches worksheet (62)/(64) = 2384.12
  within the residual ~45 kWh storage-loss gap)
  ΔSAP −0.4584 → +0.8118 (cascade swung past the worksheet by +1.27
  — the pre-slice 'near-correct' value was offsetting cascade bugs
  per [[feedback-software-no-special-handling]]; the +0.81 residual
  exposes a separate upstream gap to chase in a follow-up slice)
  Δcost +£10.56 → −£18.71
  ΔCO2 +47.89 → −7.21 kg
  ΔPE +443.13 → −161.68 kWh

No regressions on the other 24 cohort variants — only electric 2 has
the (Cat 4 HP, no PCDB, WHC=903) combination in the corpus.
Extended handover suite: 900 pass / 0 fail (was 899 — +1 from the
new AAA test). Pyright net-zero (43 → 43).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 19:28:25 +00:00
Khalim Conn-Kowlessar
4350c71bdd docs: handover post S0380.153..155
Session landed three spec-clean slices closing four major residuals:

- S0380.153 (Table 3 middle row for solid-fuel boilers): SF3 EXACT all
  4 metrics (+0.30 → -0.0000). Found the rule that solid-fuel boilers
  don't ship with dual programmers per §9.2.4.

- S0380.154 (§12.4.4 back-boiler summer-immersion): SF2 SAP+cost
  EXACT (+1.86 → -0.0000 SAP; -£42.84 → -£0.00 cost). Implemented HW
  fuel kWh split + monthly blend across cost / CO2 / PE / standing.

- S0380.155 (Table 4a HP water-column dispatch): gshp closed ±0.02
  SAP (+0.94 → -0.0178). HW kWh 841 → 1138 matches worksheet exactly.

Σ |ΔSAP_c| 14.5 (session start of S0380.150) → 2.7 = 81% reduction
across 6 slices, two sessions.

Handover doc captures:
- Per-line discipline (walk worksheet before forming hypothesis)
- Elmhurst-vs-spec divergences to defer (lighting-PE +48.66 cluster
  uses Table 12 annual factor; spec Table 12d mandates monthly)
- Ranked open fronts (electric 5 R=0.20 storage MIT, electric 2
  warm-air HP HW, deferred lighting-PE cluster)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 16:01:52 +00:00
KhalimCK
b650274108
Merge pull request #1140 from Hestia-Homes/feature/per-cert-mapper-validation
Feature/per cert mapper validation
2026-06-01 16:58:21 +01:00
Khalim Conn-Kowlessar
fb9b32ac3d Merge branch 'feature/per-cert-mapper-validation' of https://github.com/Hestia-Homes/Model into feature/per-cert-mapper-validation 2026-06-01 15:16:28 +00:00
Khalim Conn-Kowlessar
152db1aef4 Slice S0380.155: SAP 10.2 Table 4a — heat-pump water-efficiency column dispatch
SAP 10.2 Table 4a (PDF p.163-164) heat-pump rows split efficiency into
two columns — "space" and "water":

    Code  System                                            space  water
    211   Ground source HP with flow temp <= 35°C            230    170
    213   Water source HP with flow temp <= 35°C             230    170
    215   Gas-fired GSHP with flow temp <= 35°C              120     84
    216   Gas-fired WSHP with flow temp <= 35°C              120     84
    217   Gas-fired ASHP with flow temp <= 35°C              110     77
    521   Warm-air electric GSHP                             230    170
    523   Warm-air electric WSHP                             230    170
    525   Warm-air gas-fired GSHP                            120     84
    526   Warm-air gas-fired WSHP                            120     84
    527   Warm-air gas-fired ASHP                            110     77

The split reflects real physics: heat pumps lose efficiency raising
water to ~55°C DHW temperatures vs ~35°C space-heating flow. ASHP
"in other cases" (codes 214, 221, 223, 224) and the "other cases"
gas-fired rows (225-227) have space == water = 170 / 84 / 77 — no
distinct DHW column.

Pre-slice the cascade routed WHC ∈ {901, 902, 914} ("HW from main
heating") through `seasonal_efficiency(main_code)`, which only consults
the Space column. For SAP code 211 the cascade returned 2.30 (= space)
when the spec requires 1.70 (= water). HW fuel kWh undercounted by
26% on the heating-systems corpus gshp variant: cascade 841.47 kWh vs
worksheet 1138.46 kWh.

New `_TABLE_4A_HEAT_PUMP_WATER_EFFICIENCY` dict (10 codes where Space
≠ Water) consulted in `_water_efficiency_with_category_inherit` before
falling through to the existing `seasonal_efficiency` path. Codes
where Space == Water keep the legacy inheritance — no behaviour
change. Non-HP main heating (boilers, storage heaters) likewise
unchanged.

Closures (gshp variant — SAP code 211 + WHC=901 + cylinder):
  HW fuel kWh:  841.47 → 1138.45 (matches worksheet 1138.46)
  ΔSAP_c:       +0.9373 → -0.0178
  Δcost:        -£21.60 → +£0.41
  ΔCO2:         -34.98  → +7.06 kg/yr
  ΔPE:          -418.92 → +33.52 kWh/yr

No regressions on 40 other corpus variants — gshp is the only fixture
that lodges a heat-pump code with diverging Space/Water columns.

Cohort-1 ASHP closure (S0380.28 reciprocal interpolation) is unaffected
because that path runs through `heat_pump_record` PCDB Appendix N3
when a PCDB Table 362 record is lodged; this fix is the Table 4a
fallback for cases without a PCDB record.

Extended handover suite: 899 pass / 0 fail. Pyright net-zero (43 → 43).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 15:13:21 +00:00
KhalimCK
365abe5c0f
Merge pull request #1139 from Hestia-Homes/feature/assemble-new-backend
feat(ara): first_run backend rebuild — Ingestion → Baseline → Modelling on hexagonal + UnitOfWork
2026-06-01 16:10:49 +01:00
Khalim Conn-Kowlessar
305bffd284 refactor(ara): rename FirstRunPipeline → AraFirstRunPipeline (PR #1139 review)
Aligns the composition with its entry point (the `ara_first_run` lambda +
`AraFirstRunTriggerBody`): clearer what the file does.

- orchestration/first_run_pipeline.py → ara_first_run_pipeline.py
- FirstRunPipeline → AraFirstRunPipeline; FirstRunCommand → AraFirstRunCommand
- test files renamed to match

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 15:00:33 +00:00
Khalim Conn-Kowlessar
62e762e962 refactor(property): PropertyRow.id non-Optional (PR #1139 review)
`property` is an FE-owned table the backend only ever reads — every row read
carries an id — so the autoincrement-PK `Optional[int]` idiom doesn't apply
here. Make it `int` and drop the now-redundant None guard in get_many.

(Contrast: solar_table keeps Optional id — the backend DOES insert those, so
id is genuinely None pre-flush.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 14:58:11 +00:00
Khalim Conn-Kowlessar
3cad599fd1 refactor(property-baseline): units on co2 / PEUI columns (PR #1139 review)
Make the stored units explicit on the property_baseline_performance columns:
- `*_co2_emissions` → `*_co2_emissions_t_per_yr` (tonnes CO₂/yr, whole dwelling)
- `*_primary_energy_intensity` → `*_primary_energy_intensity_kwh_per_m2_yr`

Column names only; the domain `Performance` VO stays unit-suffix-free (units are
a storage concern, mapped in from_domain/to_domain). Migration doc updated.
Round-trip stays green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 14:57:00 +00:00
Khalim Conn-Kowlessar
c3691d9af2 refactor(property-baseline): rename baseline → property_baseline aggregate (PR #1139 review)
Wholesale rename of the Baseline aggregate to PropertyBaseline for clarity /
to disambiguate from baselines that appear elsewhere in Modelling. Scoped to
this aggregate only — the distinct Rebaselining term (rebaseline_reason,
StubRebaseliner, RebaselineNotImplemented) is deliberately untouched.

- domain/baseline → domain/property_baseline; BaselinePerformance →
  PropertyBaselinePerformance.
- repositories/baseline → repositories/property_baseline; BaselineRepository
  / BaselinePostgresRepository → PropertyBaseline*.
- orchestration/baseline_orchestrator.py → property_baseline_orchestrator.py;
  BaselineOrchestrator → PropertyBaselineOrchestrator. BaselineStage →
  PropertyBaselineStage.
- infrastructure/postgres: baseline_performance_table.py →
  property_baseline_performance_table.py; table `baseline_performance` →
  `property_baseline_performance`; Model renamed.
- UnitOfWork attribute `.baseline` → `.property_baseline`.
- Docs: ADR-0004 references + migration doc (renamed to
  property-baseline-performance-table.md) updated.

CONTEXT.md glossary term ("Baseline Performance") left as-is pending a
ubiquitous-language call (raised on the PR). 123 tests pass; pyright strict
clean (only the unrelated pre-existing moto import errors remain).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 14:54:59 +00:00
Khalim Conn-Kowlessar
5e941b9295 Slice S0380.154: SAP 10.2 §12.4.4 — back-boiler summer-immersion HW split
SAP 10.2 §12.4.4 (PDF p.36-37):

  "Independent boilers that provide domestic hot water usually do so
   throughout the year. With open fire back boilers or closed room
   heaters with boilers, an alternative system (electric immersion)
   may be provided for heating water in summer. In that case water
   heating is provided by the boiler for months October to May and by
   the alternative system for months June to September."

Scope is verbatim Table 4a codes 156 (Open fire with back boiler to
radiators) and 158 (Closed room heater with boiler to radiators). Range
cooker boilers (160, 161), pellet stoves with boilers (159), and
independent solid-fuel boilers (151, 153, 155) are NOT covered.

Pre-slice, the cascade treated the back-boiler cohort identically to
year-round solid-fuel mains: (59)m primary loss applied Jun-Sep, HW
fuel kWh was billed entirely at the boiler's solid-fuel rate, the HW
CO2 / PE factors used the boiler fuel's annual factor, and the off-peak
electric standing charge (£40 for 18-hour tariff) was not added because
the cert's lodged water-heating fuel code was anthracite.

Implementation (4 wired pieces):

1. `_section_12_4_4_summer_immersion_applies(epc, main)` — predicate
   gate keyed on back-boiler SAP code (156, 158) + WHC ∈ {901, 902, 914}
   "HW from main heating" + cylinder present.

2. `_primary_loss_override` zeroes (59)m for Jun-Sep when the predicate
   fires — matches the Elmhurst P960 worksheet which has (59) Jun-Sep =
   0 for SF2 (vs ~42 kWh/month for SF3 range cooker).

3. `_section_12_4_4_hw_blend(...)` — returns the 5-tuple
   (annual_hw_fuel_kwh, blended_cost_gbp_per_kwh, blended_co2_factor,
   blended_pe_factor, extra_standing_charge_gbp). The blend is kWh-
   weighted across:
   - Winter Oct-May: boiler fuel at the boiler's Table 32 unit price /
     Table 12 annual CO2 / Table 12 annual PE factor
   - Summer Jun-Sep: standard electricity (Table 12d/12e monthly
     factors weighted by summer (62)m demand) priced at the tariff's
     off-peak low rate per Table 13 note 2 (the 6.8 - 0.036V × N -
     0.105V dual-immersion formula clamps to zero high-rate for
     normal V/N combos on tariffs with ≥18 hrs low rate; SF2 has
     V=110, N≈2 → 100% low-rate)
   - The Table 32 off-peak electric standing charge that fires when
     hot water uses off-peak electricity per Table 12 note (a). For
     EIGHTEEN_HOUR tariff this is Table 32 code 38 = £40.

4. Orchestrator (`cert_to_inputs`) resolves the blend once and overrides
   `hot_water_kwh_per_yr`, `hot_water_fuel_cost_gbp_per_kwh`,
   `hot_water_co2_factor_kg_per_kwh`, `hot_water_primary_factor`, and
   `standing_charges_gbp` when the predicate fires. Other certs fall
   back to the existing single-fuel HW helpers (no behaviour change).

Worksheet evidence (heating-systems corpus property 001431 SF2 — code
158 + WHC=901 + cylinder thermostat + 18-hour tariff):
  - (62) Oct-May = 2205.80 kWh, Jun-Sep = 684.55 kWh
  - (217)m = 65 winter / 100 summer, (219) = 3393.5 anthr + 684.55 elec
    = 4078.06 fuel kWh
  - (247) HW cost = 4078.06 × 4.27 p/kWh blended = £174.25
  - (251) Standing = £40 (off-peak electric standing only — solid fuel
    has no standing charge)
  - (255) Total = £801.13

Closures (SF2):
  ΔSAP_c   +1.86 → -0.0000  (EXACT)
  Δcost   -£42.84 → -£0.00  (EXACT)
  ΔCO2  +346.87  → -93.10 kg/yr (residual: Elmhurst CO2 blend uses a
                                  different summer-month weighting that
                                  the SAP 10.2 Table 12d cascade does
                                  not reproduce — spec-correct per
                                  Table 12d header).
  ΔPE   -605.76  → -1027.51 kWh/yr (same spec-vs-Elmhurst PE blend
                                     artifact via Table 12e monthly
                                     cascade).

No regressions: 40/41 corpus variants unchanged (gate is narrow by SAP
code 156/158). Extended handover suite 898 pass / 0 fail. Pyright net-
zero (43 → 43).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 14:18:44 +00:00
Khalim Conn-Kowlessar
e4bf4e70e8 Slice S0380.153: SAP 10.2 Table 3 — not-separately-timed DHW for solid-fuel boilers
SAP 10.2 Table 3 (PDF p.160) provides three primary-loss rows keyed off
the DHW timing arrangement, the middle row giving winter h=5 / summer
h=3 for "Cylinder thermostat, water heating NOT separately timed".

Solid-fuel boiler systems (Table 4a codes 151-161 — independent boilers,
open-fire + back boilers, closed room heaters with boilers, range cooker
boilers, stoves with boilers) do not ship with dual programmers. Per
SAP 10.2 §9.2.4 (PDF p.27) these are "independent solid fuel boilers,
open fires with a back boiler and room heaters with a boiler" — the
appliance itself is the timer. DHW timing follows the burn schedule,
not a separate cylinder programmer, so the middle Table 3 row applies.

Pre-slice `_separately_timed_dhw` returned True for any cylinder +
non-electric HW fuel cert (the S0380.140 gate), routing solid-fuel
boilers through h=3 year-round (the third row, "Cylinder thermostat,
water heating separately timed"). That under-counted winter (59)m
by ~21 kWh/month × 8 winter months across the affected cohort, with
the under-counted water-heating gain propagating into MIT / SH / SAP.

New gate: `sap_main_heating_code in _TABLE_4A_SOLID_FUEL_BOILER_CODES`
(frozenset of {151, 153, 155, 156, 158, 159, 160, 161}) — added before
the existing cylinder-present fallback. The post-S0380.140 electric-
immersion / heat-pump / no-main branches are unchanged. Table 4b
liquid-fuel boilers (101-141) keep the True default — modern gas/oil
installations standardly include dual programmers and the worksheet
confirms `oil 1` / `oil pcdb 1..3` / `pcdb 1` are pinned exact at
h=3 year-round.

Worksheet evidence (heating-systems corpus property 001431):
  - solid fuel 3 (SAP code 160 range cooker boiler + WHC=901
    cylinder thermostat): worksheet (59)m winter = 64.58 (h=5, p=0)
    and summer = 41.92 / 43.31 (h=3, p=0). Cascade closes ΔSAP +0.30
    → −0.0000, Δcost −£6.84 → −0.00, ΔPE −214 → −0.00 (4-metric exact).
  - solid fuel 2 (SAP code 158 closed room heater + back boiler):
    same Table 3 fix narrows ΔSAP +2.06 → +1.86. Remaining ~1.86 SAP
    is the SAP 10.2 §12.4.4 immersion-in-summer rule for back-boilers
    (codes 156, 158) — the worksheet has summer (59)m = 0 because the
    Elmhurst P960 lodges `Summer Immersion: Yes` + the spec routes
    Jun-Sep HW through an electric immersion at η=100%. That's a
    bigger lift (monthly HW efficiency + fuel-split plumbing) and is
    a follow-up slice.

Other corpus variants: no impact (verified via cohort sweep). The
gate is narrow by SAP code so only the 2 affected variants move.

Extended handover suite: 897 pass / 0 fail (+1 from new AAA test).
Pyright net-zero (43 → 43, transient +1 fixed via `EpcPropertyData`
import on the new test's `_cylinder_epc_for` return annotation).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 13:27:12 +00:00
Khalim Conn-Kowlessar
3a44ca89fb docs: handover post S0380.150..152
Three slices closed:
- S0380.150 18-hour tariff for pumps+lighting (§12 + App F2)
- S0380.151 RdSAP 10 §4.1 Table 5 extract-fans default
- S0380.152 Table 3 primary loss for solid-fuel back-boilers

Cluster A closed; Cluster B partial (SF3 done, SF2 partial); Cluster
C open. Σ|ΔSAP| 14.5 → 6.4 across the 25 cascade-OK cohort variants.

Mid-session pivot documented: my Cluster B hypothesis was wrong
(Table 9c step 12), the actual gap was Table 3 primary loss for
solid-fuel boilers. Discipline added: dump per-line worksheet data
before forming a spec hypothesis.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 13:03:55 +00:00
Khalim Conn-Kowlessar
d4f6ff0f2f Slice S0380.152: SAP 10.2 Table 3 — primary loss for solid-fuel back-boilers
SAP 10.2 Table 3 (PDF p.160) "Primary circuit loss" verbatim:

  "Primary circuit loss applies when hot water is heated by a heat
   generator (e.g. boiler) connected to a hot water storage vessel
   via insulated or uninsulated pipes (the primary pipework)."

The spec rule does NOT restrict to Table 4b gas/oil boilers — any
boiler connected to a cylinder via primary pipework incurs the loss.
The cert's `water_heating_code` is the discriminator:

  - WHC=901/902/914 (HW from main heating system) + wet boiler +
    cylinder → primary loss applies (back-boiler / wet boiler heats
    cylinder via primary loop).
  - WHC=903 (HW from a separate electric immersion / secondary) → no
    primary loss even when the main is a wet boiler.

Pre-slice `_primary_loss_applies` only covered Table 4b gas/oil boiler
codes (101-141). Table 4a solid-fuel boiler codes 151-161 (manual /
auto / range-cooker boilers, closed room heater + back-boiler, open
fire + back-boiler, wood pellet + back-boiler) fell through and
primary loss silently went to zero — under-counting §5 (72) water-
heating internal gain by ~74 W cohort-wide for every WHC=901 solid-
fuel back-boiler variant.

Worksheet evidence on the 001431 corpus (all age G, same cylinder):
  - solid fuel 2 (code 158, WHC=901): ws (59) ≈ 505 kWh/yr   → apply
  - solid fuel 3 (code 160, WHC=901): ws (59) ≈ 643 kWh/yr   → apply
  - solid fuel 5 (code 153, WHC=903): ws (59) = 0            → skip
  - solid fuel 4..11 (633/636 non-boilers, WHC=903): skip

The fix:
  - `_primary_loss_applies(...)` gains a `water_heating_code: Optional[int]`
    parameter (default None for back-compat with synthetic tests).
  - New branch after the Table 4b fallback: `_is_wet_boiler_main(main)`
    + `water_heating_code in _WATER_INHERIT_FROM_MAIN_CODES` → True.
  - Call site `_primary_loss_override` passes
    `epc.sap_heating.water_heating_code`.

Heating-systems corpus impact:
  - solid fuel 3 (code 160, WHC=901): +1.31 → +0.30 SAP
                                       PE -918.6 → -214.3 kWh/yr
  - solid fuel 2 (code 158, WHC=901): +2.77 → +2.06 SAP
                                       PE -1241.7 → -754.1 kWh/yr
  - All other variants: unchanged

SF2 doesn't fully close because the worksheet's (59) is winter-only
(0 in summer) but the cascade applies the year-round Table 3 formula
via `_separately_timed_dhw=True` (cylinder + non-electric HW fuel).
Remaining residual is a follow-up — likely a
`_separately_timed_dhw=False` rule for solid-fuel back-boilers (HW
timing tied to the room fire, not separately programmed).

Pyright net-zero (43 → 43). Extended handover suite: 895 → 896 pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 12:59:08 +00:00
Khalim Conn-Kowlessar
fb173cdf3f Slice S0380.151: RdSAP 10 §4.1 Table 5 — extract-fans age-band default
RdSAP 10 Specification §4.1 Table 5 "Ventilation parameters" (PDF p.28)
verbatim — "Extract fans" entry:

  • Number of extract fans if known
  • If number is unknown:
      Not park home:
        Age bands A to E      all cases             → 0
        Age bands F to G      all cases             → 1
        Age bands H to M      up to 2 hab. rooms    → 1
                              3 to 5 hab. rooms     → 2
                              6 to 8 hab. rooms     → 3
                              more than 8 hab. rooms → 4
      Park home:
        Age band F            all cases             → 0
        Age bands G onwards   all cases             → 2

The Elmhurst Summary §12.0 renders "No. of intermittent extract fans: 0"
as the form for *unknown*; every other §2 chimney/flue line item follows
"number if known, or 0 if not present" and the cascade trusts the lodged
value verbatim. Only extract fans have a non-zero age-band default.

Pre-slice the cascade read the lodged 0 verbatim → cohort-wide -0.044
ACH ventilation deficit (= -2.6 W/K HLC, = -1.2% SH demand, = ~-0.3 SAP
per variant). All 25 cascade-OK corpus variants are age G + 4 habitable
rooms + not park home → Table 5 default = 1 fan.

New helper `_rdsap_extract_fans_default(age_band, habitable_rooms, *,
is_park_home)` + wiring in `ventilation_from_cert` applies
`max(lodged, table_5_default)` so the spec minimum fires when lodging
is below it.

Heating-systems corpus impact (25 cascade-OK variants):

  oil 1, oil pcdb 1/2/3            +0.27..+0.29 → EXACT (<1e-4)
  electric 1, solid fuel 5/6/7/8   +0.28..+0.43 → EXACT
  pcdb 1, ashp                     +0.41 / +0.18 → ±0.02
  electric 3/6/7/8/9, sf 4/9/10/11 +0.39..+0.60 → +0.08..+0.12
  electric 5                       -0.74 → -1.18  (Cluster B over-shoot)
  electric 2                       -0.24 → -0.46  (Cluster C HW gap)
  gshp                             +1.09 → +0.94  (Cluster C HW gap)
  solid fuel 2/3                   +3.08 / +1.76  → +2.77 / +1.31

Cluster A (cohort-wide HLC deficit) is closed. The four remaining open
fronts (Clusters B + C) are now visible without offsetting bugs:
  - Cluster B (Table 9c step 12 R sign): electric 5, solid fuel 2/3
  - Cluster C (HW kWh cascade): gshp + electric 2 (Appendix N3)
                                solid fuel 2/3 (Table 4b HW efficiency)

Golden-fixture re-pins:
  cert 0240 (age J, TFA 118): PE +2.18 → +5.80, CO2 +0.13 → +0.32
  cert 0390-2954 (age F, TFA 360): PE -28.27 → -27.97, CO2 -2.74 → -2.71

Pyright net-zero (44 → 44). Extended handover suite: 893 → 895 pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 11:26:53 +00:00
Khalim Conn-Kowlessar
a658f73613 Slice S0380.150: SAP 10.2 §12 / Appendix F2 — 18-hour high-rate for pumps + lighting
SAP 10.2 §12 (PDF p.45 lines 2280-2283):

  "The 18-hour tariff is only for use with electric CPSUs with
   sufficient energy storage to provide space (and possibly water)
   heating requirements for 2 hours. Electricity at the low-rate price
   is available for 18 hours per day, with interruptions totalling 6
   hours per day, with the proviso that no interruption will exceed 2
   hours. The low-rate price applies to space and water heating, while
   electricity for all other purposes is at the high-rate price."

SAP 10.2 Appendix F2 (PDF p.63 lines 3809-3812):

  "F2 Electric CPSUs using 18-hour electricity tariff. The 18-hour
   low rate applies to all space heating and water heating provided
   by the CPSU. The CPSU must have sufficient energy stored to provide
   heating during a 2-hour shut-off period. The 18-hour high rate
   applies to all other electricity uses."

Table 12a Grid 2 omits 18-hour / 24-hour from its 7-hour / 10-hour
table; pre-slice the cascade's `_other_fuel_cost_gbp_per_kwh` fell
through Grid 2's `NotImplementedError` to
`prices.standard_electricity_p_per_kwh` (Table 32 code 30 = 13.19
p/kWh). Per §12 + Appendix F2 the 18-hour rule is explicit fraction =
1.0 at the high rate — pumps, fans, and lighting bill at the 18-hour
high rate (Table 32 code 38 = 13.67 p/kWh).

All 41 heating-systems corpus variants lodge `meter_type='18 Hour'`,
so this gap was cohort-wide. Pre-slice the cascade undercounted
pumps + lighting cost by (13.67 − 13.19) × kWh on every variant:

  oil 1            Δcost -£9.31 → -£6.69   (closed £2.62, pumps 265 +
                                            lighting 282 × £0.0048)
  oil pcdb 1/2     Δcost -£8.32 → -£6.29   (closed £2.03)
  oil pcdb 3       Δcost -£8.91 → -£6.29   (closed £2.62)
  pcdb 1           Δcost -£11.10 → -£9.07  (closed £2.03)
  ashp             Δcost -£5.57 → -£4.22   (closed £1.35, lighting only)
  electric 1..9    Δcost shift ~ -£1.35..+£1.35  (lighting only;
                                                  storage / room-heater
                                                  certs carry pumps_fans
                                                  = 0)
  solid fuel 4..11 Δcost ~ -£1.55 (lighting only)
  gshp             Δcost -£26.48 → -£25.12 (closed £1.35)

Pyright net-zero (43 → 43). Extended handover suite: 892 → 893 pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 09:34:09 +00:00
Khalim Conn-Kowlessar
f20d96369f docs: handover post S0380.146..149
Captures the four slices that closed the oil-cohort Table 4f gap:
.146 primary loss for Table 4b regular boilers, .147 Eq D1 for
non-PCDB Table 4b, .148 liquid fuel boiler aux 100 kWh, .149
per-pump-age circulation + wet-boiler gate.

Documents the cohort-wide ~-£10/yr cost residual that S0380.149's
spec correctness exposed — the new next-slice front. Highlights the
user directive [[feedback-software-no-special-handling]] that
surfaced during S0380.147 and continued to apply through .149.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 09:18:38 +00:00
Khalim Conn-Kowlessar
35ea664db8 Slice S0380.149: Table 4f — circulation pump dispatch by pump age + wet-boiler gate
SAP 10.2 Table 4f (PDF p.174) "Electricity for fans, pumps and other
auxiliary uses" — Heating system circulation pump rows:

  Circulation pump, 2013 or later                 41 kWh/yr
  Circulation pump, 2012 or earlier              165 kWh/yr
  Circulation pump, unknown date                 115 kWh/yr

Pre-slice the cascade hardcoded `_PUMPS_FANS_KWH_BY_MAIN_CATEGORY[2]
= 160 kWh/yr` (115 Unknown CH + 45 gas flue fan) for category=2 gas
boilers and fell through to `_DEFAULT_PUMPS_FANS_KWH_PER_YR = 130`
for any other category. Both shortcuts ignored the per-cert
`central_heating_pump_age` lodging AND incorrectly applied
circulation pump electricity to dry electric storage / direct-acting
/ room heater systems (no primary water loop).

Implementation:

  - Mapper: `_elmhurst_pump_age_int` now recognises both "Pre 2013"
    and "2012 or earlier" string forms as the SAP10 enum 1 (Pre 2013).
    Pre-slice "2012 or earlier" silently returned 2 (2013 or later)
    on the entire oil corpus, mis-applying the 41 kWh post-2013
    circulation pump to certs that lodge "2012 or earlier" via
    Elmhurst Summary §14 "Heat pump age".
  - New `_is_wet_boiler_main(main)` gate: identifies wet-boiler
    systems by Table 4a/4b code range (101-141 gas/oil, 151-161
    solid fuel, 191-196 electric boilers), PCDB Table 322 record,
    or category ∈ {1, 2} fallback. Heat pumps (cat 4) return False
    per Table 4f note "Not applicable for electric heat pumps from
    database". Electric storage / direct / room heater codes
    (401-499, 601-699) return False — they have no primary loop.
  - New `_table_4f_circulation_pump_kwh(main)` dispatches on
    `central_heating_pump_age`:
        None / 0 → 115 kWh (Unknown date)
        1        → 165 kWh (Pre 2013 / 2012 or earlier)
        2        →  41 kWh (2013 or later)
  - New `_table_4f_main_1_gas_boiler_flue_fan_kwh(main)` extracts
    the gas-flue-fan 45 kWh logic from the old category dispatch.
    Gated on `_is_wet_boiler_main` + gas fuel + fan_flue_present.
  - Remove `_PUMPS_FANS_KWH_BY_MAIN_CATEGORY` and
    `_DEFAULT_PUMPS_FANS_KWH_PER_YR` constants (the new helpers
    replace both).

Worksheet evidence for the wet-boiler gate:

  electric 1 (code 191 electric boiler):   ws (230c) = 41 kWh ✓
  electric 5 (code 402 electric storage):  ws (231)  =  0 kWh ✗
  solid fuel 2 (code 158 anthracite):      ws (230c) = 41 kWh ✓
  solid fuel 9 (code 636 wood stove):      ws (231)  =  0 kWh ✗
  oil 1 (code 127 condensing oil):         ws (230c) = 165 kWh ✓
  oil pcdb 3 (PCDB 18573):                 ws (230c) = 41 kWh ✓

Cascade impact across heating-systems corpus (vs S0380.148 state):

  | Variant        | SAP Δ        | Cause |
  |----------------|--------------|-------|
  | oil 1          | +0.60→+0.40  | 165 + 100 = 265 ≡ worksheet exact |
  | oil pcdb 1/2   | -0.15→+0.36  | 41 + 100 = 141 ≡ ws exact |
  | oil pcdb 3     | +0.59→+0.39  | same |
  | pcdb 1         | -0.03→+0.50  | 41 + 100 = 141 ≡ ws (was over) |
  | electric 1     | -0.06→+0.45  | 41 (wet electric boiler) |
  | electric 3-9   | -0.1..-1.4→  | 0 (dry storage/UFH) |
  |                | +0.5..+0.6   | was 130 default; now 0 |
  | solid fuel 2-8 | various      | 41 (boilers) — partial closures |
  | solid fuel 9-11| -0.2→+0.5    | 0 (room heaters) — was 130 |

Re-pins reflect spec-correct application. Per
[[feedback-software-no-special-handling]]: pre-slice near-zero pins
were masking pre-existing offsetting cascade gaps; spec correctness
unmasks them.

Golden fixtures impact:

  - cert 0240 (dual oil combi, pump_age=0 Unknown): PE +2.52→+2.18
  - cert 0390 (Firebird PCDF oil, pump_age=0): PE -28.08→-28.27
  - cert 6035 (gas combi, pump_age=2 post-2013): PE +47.29→+46.42

Cert 6035 closer to zero (post-2013 41 kWh < pre-slice 115 unknown).
Cert 0240/0390 small shifts from removing the gas-cat-2 hardcoded
160 path for oil mains.

Tests:
  - test_sap_table_4f_circulation_pump_dispatches_per_central_heating_
    pump_age — asserts oil 1 inputs.pumps_fans_kwh_per_yr == 265
    (165 Pre 2013 + 100 liquid fuel) ± 1.0.
  - test_sap_table_4f_liquid_fuel_boiler_flue_fan_and_fuel_pump_adds_
    100_kwh (S0380.148) still passes.

Extended handover suite: 892 pass, 0 fail. Pyright net-improved
(removed unused `main_category` variable, file 33→32 errors).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 09:14:11 +00:00
Khalim Conn-Kowlessar
1b1f45b679 Slice S0380.148: Table 4f — liquid fuel boiler flue fan and fuel pump (100 kWh/yr)
SAP 10.2 Table 4f (PDF p.174) "Electricity for fans, pumps and other
auxiliary uses" row:

  Liquid fuel boiler — flue fan and fuel pump   100 kWh/yr  c) d)

Note c): "Applies to all liquid fuel boilers that provide main heating,
but not if boiler provides hot water only. Where there are two main
heating systems include two figures from this table."

Pre-slice the cascade's `_table_4f_additive_components` only wired:
  - (230a) MEV / MVHR
  - (230e) Main 2 gas-boiler flue fan (45 kWh)
  - (230g) Solar HW pump

The liquid-fuel sibling row was missing — oil 1 worksheet (230d) and
oil pcdb 3 worksheet (230d) both lodge 100 kWh/yr "oil boiler pump"
that the cascade was silently skipping.

Implementation:

  - Add `_LIQUID_FUEL_CODES = frozenset({4, 71, 73, 75, 76})` and new
    `is_liquid_fuel_code(fuel_code)` helper in
    `domain/sap10_calculator/tables/table_32.py`. Mirror of
    `is_electric_fuel_code` — routes through `_to_table_32_code`
    normalisation so Elmhurst-derived Table 32 codes (e.g. code 23
    = bulk wood pellets, solid) don't collide with API enum codes
    (where 23 = B30D community).
  - Extend `_table_4f_additive_components` to add 100 kWh for Main 1
    when `is_liquid_fuel_code(main.main_fuel_type)` returns True
    (`isinstance(int)` guard for the `Union[int, str]` field). Mirror
    the same gate for Main 2 per Note c) "Where there are two main
    heating systems include two figures".
  - LPG is GAS (Table 4b/4f convention, Ecodesign classification) —
    `_LIQUID_FUEL_CODES` deliberately excludes 2/3/5/9 LPG codes.

Cascade impact across heating-systems corpus:

  | Variant   | SAP Δ       | Cost Δ      | PE Δ        |
  |-----------|-------------|-------------|-------------|
  | oil 1     | +1.18→+0.60 | -£27→-£14   | -276→-124   |
  | oil pcdb 1| +0.42→-0.15 |  -£10→+£3.4 |  -84→+67    |
  | oil pcdb 2| +0.42→-0.15 |  -£10→+£3.4 |  -84→+67    |
  | oil pcdb 3| +1.16→+0.59 | -£27→-£14   | -271→-120   |
  | pcdb 1    | +0.57→-0.03 | -£13→+£0.6  | -109→+42    |

Cohort closures: pcdb 1 EXACT (-0.03), oil pcdb 1/2 closed to -0.15.

Golden fixtures impact:

  - cert 0240 (dual-main oil combi 130): SAP integer 73→72 (resid
    +0→-1), PE +1.02→+2.52, CO2 +0.11→+0.14. Dual-main certs add
    2 × 100 = 200 kWh aux per Note c). Cert's published SAP 73
    suggests the dual-main Q_space split (main_heating_fraction)
    may also need wiring — slice candidate.
  - cert 0390 (Firebird PCDF 9005 oil combi): PE -28.50→-28.08
    (CLOSER to zero), CO2 -2.75→-2.73 (CLOSER to zero), SAP +7
    unchanged.

Test:
  test_sap_table_4f_liquid_fuel_boiler_flue_fan_and_fuel_pump_adds_
  100_kwh — asserts oil pcdb 3 inputs.pumps_fans_kwh_per_yr ≥ 230
  (130 base + 100 liquid fuel boiler aux).

Extended handover suite: 891 pass, 0 fail. Pyright net-zero (44=44).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 08:53:23 +00:00
Khalim Conn-Kowlessar
de5ae2a27e docs: handover post S0380.146..147
Captures the two slices that closed oil 1 from +2.66 → +1.18 SAP via
Table 3 primary-loss extension (.146) + Appendix D §D2.1 (2) Equation
D1 wiring for non-PCDB Table 4b boilers (.147). Highlights the user
directive that surfaced this session ("BRE/Elmhurst software follows
spec exactly; no special non-spec handling") and the resulting pin
shifts on cert 0240 + 6035 (combi-no-cylinder golden fixtures
re-pinned per spec correctness).

Ranks next-slice candidates: oil 1 Table 4f auxiliary energy (~+0.4
SAP closure remaining), electric 5 -1.43 regressed by .145, solid
fuel 2/3 anthracite outliers, community heating + electric storage
unblocking.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 08:26:04 +00:00
Khalim Conn-Kowlessar
7dceeff24b Slice S0380.147: Appendix D Eq D1 — Table 4b non-PCDB boilers (winter/summer monthly cascade)
SAP 10.2 Appendix D §D2.1 (2) Equation (D1) (PDF p.57):

  If the boiler provides both space and water heating, and the summer
  seasonal efficiency is lower than the winter seasonal efficiency,
  the efficiency is a combination of winter and summer seasonal
  efficiencies according to the relative proportion of heat needed
  from the boiler for space and water heating in the month concerned:

              Q_space + Q_water
  η_water,m = ───────────────────────────────
              Q_space/η_winter + Q_water/η_summer

  where Q_space (kWh/month) is the quantity calculated at (98c)m
  multiplied by (204) or by (205);
        Q_water (kWh/month) is the quantity calculated at (64)m;
        η_winter and η_summer are the winter and summer seasonal
        efficiencies (from Table 4b).

Pre-slice the cascade only wired Eq D1 for PCDB-tested boilers (the
`pcdb_record` branch in `_apply_water_efficiency`). For non-PCDB
Table 4b boilers (`sap_main_heating_code` 101-141) where the cert
lodges no `main_heating_index_number`, the cascade fell through to
the scalar `water_efficiency_pct` divisor — which resolved via WHC
901 inherit to Table 4b WINTER eff (wrong direction; spec wants the
monthly Eq D1 blend).

This slice:

  - Adds `domain/sap10_calculator/tables/table_4b.py` with the full
    41-row Table 4b (winter, summer) pair dict for codes 101-141
    verbatim from SAP 10.2 PDF p.168 (Table 4b).
  - Refactors `_apply_water_efficiency` parameter from
    `pcdb_record: Optional[GasOilBoilerRecord]` to
    `eq_d1_winter_summer_pct: Optional[tuple[float, float]]` —
    decouples the Eq D1 input from the PCDB record so a Table 4b
    fallback can populate it without faking a PCDB record.
  - Resolves Eq D1 inputs at the call site with priority order:
        1. PCDB Table 105 winter/summer (existing path)
        2. SAP 10.2 Table 4b (PDF p.168) winter/summer when PCDB
           absent + WHC=901 (`_WHC_FROM_MAIN_HEATING`, the spec form
           of "boiler provides both space and water heating").
    §9.4.11 -5pp interlock applies symmetrically to both columns of
    whichever (winter, summer) tuple is resolved.

Oil 1 cert worksheet (217)m verified Jan 81.83 / Apr 81.42 / May
79.94 / Jun-Sep 72.00 / Dec 81.86 — exact back-solve to Eq D1 with
Table 4b code 127 (winter 84, summer 72). Annual HW fuel (219) =
Σ (64)m × 100 / (217)m = 3638.99 kWh/yr ≡ cascade post-slice.

Cascade impact:

  Heating-systems corpus (worksheet-pinned, oil 1 only on pin grid):
    oil 1  SAP +1.76 → +1.18  (Δ -0.59)
           cost -£40.60 → -£27.12  (Δ +£13.48)
           CO2  -129.22 → -55.36   (Δ +73.86 kg/yr)
           PE   -590.02 → -275.52  (Δ +314.50 kWh/yr)
    Remaining oil 1 residual is Table 4f auxiliary energy (cascade
    pumps_fans 130 kWh vs worksheet 265 kWh — missing the oil-boiler
    pump 100 kWh + CH pump 130 vs ws 165). Follow-up slice.

  Golden fixtures (cert-pinned, integer-rounded PE):
    cert 0240 (dual oil combi 130, no cylinder): PE +0.05 → +1.02
    cert 6035 (gas combi 104, no cylinder):      PE +46.10 → +47.29
    Both shifts reflect spec-correct Eq D1 now firing for non-PCDB
    combi-no-cylinder configs. The pre-slice near-zero pin on cert
    0240 was masking offsetting cascade gaps (likely Table 4f
    auxiliary energy and/or dual-main Q_space split per (98c)m ×
    (204) which the cascade currently treats as full demand).

Following [[reference-unmapped-sap-code]] discipline, the new Table
4b dict is the canonical spec-source — `domain.sap10_ml.sap_
efficiencies._SPACE_EFF_BY_CODE` still carries the winter column for
the ML feature cascade and is left in place per the sap10_ml
deprecation plan (separate migration).

Test:
  test_sap_appendix_d_eq_d1_water_efficiency_monthly_for_non_pcdb_
  table_4b_boiler_with_cylinder — asserts cert 1431 oil 1 HW fuel
  annual = 3638.99 ± 1.0 kWh/yr (matches worksheet (219)).

Extended handover suite: 890 pass, 0 fail. Pyright net-zero (44=44).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 08:22:46 +00:00
Khalim Conn-Kowlessar
bd193e06fc Slice S0380.146: Table 3 primary loss — Table 4b non-PCDB regular boilers with cylinder
SAP 10.2 Table 3 (PDF p.160) "Primary circuit loss":

  "Primary circuit loss applies when hot water is heated by a heat
   generator (e.g. boiler) connected to a hot water storage vessel via
   insulated or uninsulated pipes (the primary pipework). Primary loss
   is set to zero for the following:
       Electric immersion heater
       Combi boiler ...
       CPSU ..."

A Table 4b regular (non-combi, non-CPSU) gas or liquid-fuel boiler
feeding a cylinder is in neither zero-loss list, so primary loss must
apply. Pre-slice the Elmhurst-path fallback in `_primary_loss_applies`
only covered PCDB Table 322 records (S0380.142) — when the cert lodges
a Table 4b code (e.g. oil 1 sap_main_heating_code 127 "Condensing oil
boiler") with no PCDB index and no `main_heating_category` lodgement,
primary loss silently fell through to zero.

This slice extends the Elmhurst-path fallback in `_primary_loss_applies`
to fire when `sap_main_heating_code` is in the Table 4b code range
(101-141) and NOT in the combi/CPSU sub-row exclusion set per Table 3:

  Combi codes:  103, 104, 107, 108, 112, 113, 118, 128, 129, 130
  CPSU codes:   120, 121, 122, 123

Oil 1 worksheet (59)m daily rate = 1.3972 kWh/day uniform = 14 ×
[0.0245 × 3 + 0.0263] (uninsulated pipework, has cylinder thermostat +
separately timed DHW → h=3 winter & summer per Table 3 split). Annual
sum = 365 × 1.3972 ≈ 510 kWh/yr — matches the worksheet's (59) annual.

Cascade impact on heating-systems corpus:
  - oil 1 SAP residual +2.66 → +1.76 (Δ -0.90)
         cost  -£61.24 → -£40.60 (Δ +£20.64)
         CO2   -242.27 → -129.22 (Δ +113.05 kg/yr)
         PE  -1050.49 → -590.02   (Δ +460.47 kWh/yr)

Only the oil 1 variant moves — every other cascade-OK variant either
already routes primary loss via the PCDB Table 322 branch (oil pcdb 1/
2/3, pcdb 1) or via the boiler-category {1,2} branch. The other oil
codes 124/125/126/131/132 + range-cooker codes 133-141 are gated for
free by the same dispatch when their certs surface in future cohorts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 22:20:50 +00:00
Khalim Conn-Kowlessar
1636cfbc83 docs: handover post S0380.141..145
Five slices closing pcdb 1 (+6.95→+0.57 via §9.4.11 + §4 cylinder
gates + RdSAP10 Table 29) and the electric storage cluster (e3/e6/e7
+2.5/+1.3 SAP → <0.21 each via Table 4e (92)m→(93)m). Cumulative
|ΔSAP| 18.0 → 12.2 (-32%). Open fronts ranked + spec-source index.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 21:55:53 +00:00
Khalim Conn-Kowlessar
b1478cff63 Slice S0380.145: Table 4e temperature adjustment — apply (92)m → (93)m offset per Table 9c step 8
SAP 10.2 Table 4e (PDF p.170-173) "Heating system controls":

  3. The 'Temperature adjustment' modifies the mean internal
     temperature and is added to worksheet (92)m.

SAP 10.2 Table 9c step 8 (PDF p.184): "Apply adjustment to the mean
internal temperature from Table 4e, where appropriate".

Pre-slice the cascade hardcoded `control_temperature_adjustment_c
=0.0` at all three call sites of `mean_internal_temperature_monthly`
and `space_heating_section_with_results`. The §8 heat loss calc
therefore drove off (92)m unchanged → §8 SH demand under-counted on
every cert whose `main_heating_control` lodges a non-zero adjustment.

Table 4e adjustments by code (full p.170-173 coverage):

  Group 0 — No heating system:
    2699: +0.3
  Group 1 — Boilers with radiators/UFH (+ micro-CHP):
    2101, 2102: +0.6   (no thermo / programmer-only)
    2103..2113: 0
  Group 2 — Heat pumps:
    2201, 2202: +0.3
    2203..2210: 0
  Group 3 — Heat networks:
    2301, 2302: +0.3
    2303..2314: 0
  Group 4 — Electric storage:
    2401 (Manual charge):                  +0.7
    2402 (Automatic charge):               +0.4
    2403 (Celect):                         +0.4
    2404 (HHR controls):                    0
  Group 5 — Warm air:
    2501, 2502: +0.3
    2503..2506: 0
  Group 6 — Room heaters:
    2601: +0.3
    2602..2605: 0
  Group 7 — Other systems:
    2701, 2702: +0.3
    2703..2706: 0

New `_control_temperature_adjustment_c(main)` helper consults
`_CONTROL_TEMPERATURE_ADJUSTMENT_BY_CODE` (52 entries, full Table 4e
coverage). Strict-raises `UnmappedSapCode` on present-but-unmapped
codes per [[reference-unmapped-sap-code]] so spec-coverage gaps
surface at test time. The helper is wired to all three call sites
of the MIT/SH orchestrators in cert_to_inputs.

Corpus impact — closes the +2.5 SAP cluster substantially:

  Variant | control |  pre  →  post  | delta
  ------- | ------- | -------------- | -----
  e3 (401)|  2401   | +2.55 → -0.09  | -2.46  (massive close)
  e6 (404)|  2402   | +1.33 → -0.17  | -1.50
  e7 (408)|  2402   | +1.29 → -0.20  | -1.49
  e2 (524)|  2502   | +0.47 → -0.18  | -0.65
  e5 (402)|  2402   | +0.07 → -1.43  | -1.50  (regressed —
                                              previously net-zero
                                              from offsetting bugs)

Cumulative |ΔSAP| across these 5: 5.71 → 2.07 (-3.64 pts closed).
electric 3 / 6 / 7 / 8 / 9 now all within 0.20 SAP of worksheet.
Golden fixtures unchanged (API certs in those tests don't lodge
non-zero-adjustment control codes; suite stays 888 pass).

Extended handover suite: 888 pass, 0 fail (was 887 + 1 new AAA test).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 21:50:10 +00:00
Khalim Conn-Kowlessar
ec6661cbb6 Slice S0380.144: Table 11 — per-Table-4a-code secondary fraction dispatch for electric storage heaters + remove code 408 from §A.2.2 forced-secondary set
SAP 10.2 Table 11 (PDF p.188) "Fraction of heat supplied by
secondary heating systems" — the "Electric storage heaters (not
integrated)" row splits by Table 4a sub-type:

  - not fan-assisted:                                       0.15
  - fan-assisted:                                           0.10
  - high heat retention (as defined in 9.2.8):              0.10

Plus separate rows:
  Integrated storage/direct-acting electric systems:        0.10
  Electric room heaters:                                    0.20
  Other electric systems (e.g. underfloor):                 0.10

Cross-referenced with SAP 10.2 Table 4a (PDF p.166) Electric
storage codes:

  401: Old (large volume) storage heaters     — not fan-assisted
  402: Slimline storage heaters                — not fan-assisted
  403: Convector storage heaters               — not fan-assisted
  404: Fan storage heaters                     — fan-assisted
  405: Slimline + Celect                       — not fan-assisted
  406: Convector + Celect                      — not fan-assisted
  407: Fan + Celect                            — fan-assisted
  408: Integrated storage + direct-acting      — "Integrated"
  409: High heat retention                     — HHR
  421: Underfloor heating                      — "Other electric"

Pre-slice the cascade defaulted `_secondary_fraction` to 0.10 for
every forced electric-storage code (Elmhurst mapper leaves
`main_heating_category=None`, dispatch falls through to the
`_SECONDARY_HEATING_FRACTION_DEFAULT` 0.10), missing the 0.15
not-fan-assisted sub-row on codes 401/402/403/405/406.

Two compounding spec-citable fixes:

(a) New `_SECONDARY_FRACTION_BY_ELECTRIC_STORAGE_CODE` dispatch dict
    consulted before the category-based lookup in
    `_secondary_fraction`. Routes each Table 4a 4xx code to its
    Table 11 sub-row fraction.

(b) Code 408 removed from `_FORCE_SECONDARY_FOR_MAIN_CODES`.
    SAP 10.2 §A.2.2 (PDF p.~189) verbatim: "This applies to main
    heating codes 401 to 407, 409 and 421" — 408 is explicitly
    NOT in the spec's forced list. The integrated storage+direct-
    acting heater's direct-acting element acts as the secondary
    already, so the calculation doesn't add another.

Corpus impact (electric variants — Elmhurst mapper path):

- electric 3 (SAP 401): sec_frac 0.10 → 0.15; CO2 -117.84 →
  -108.88; PE -1121.97 → -1093.18. SAP / cost residual unchanged
  because the off-peak meter routes the cost calc through the
  `_ZERO_FUEL_COST_FOR_OFF_PEAK` sentinel + legacy scalar-field
  math which bills main and secondary at the same off-peak low
  rate (7.41 p/kWh) — main-vs-secondary split is cost-neutral.
- electric 5 (SAP 402): sec_frac 0.10 → 0.15; CO2 -11.08 → -2.48;
  PE -161.03 → -133.36. Same cost-invariance.
- electric 7 (SAP 408): forced-secondary removed → cascade secondary
  fuel kWh 891 → 0 (matches worksheet); CO2 -37.86 → -53.57;
  PE -498.47 → -549.37. SAP residual unchanged (same off-peak
  cost-invariance).
- electric 4/6/8/9: no change (categories 404/409/421 keep their
  existing 0.10 dispatch).

The remaining +2.55 SAP residual on electric 3 (+1.29 on electric 7)
is now confirmed to be driven by space-heating DEMAND undercount
(cascade SH demand 10083 kWh vs worksheet 11088 kWh for electric 3;
8914 vs 9529 for electric 7), not by sec_frac dispatch. That's a
separate slice — likely §9 MIT calc or §8 gains/HLC for storage-
heater R values, follow-up after this slice.

Extended handover suite: 887 pass, 0 fail (was 886 + 1 new AAA test).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 21:27:46 +00:00
Khalim Conn-Kowlessar
53ceb63624 docs: handover post S0380.141..143 (pcdb 1 closure via §9.4.11 + §4 cylinder gates + RdSAP 10 Table 29 inaccessible-cylinder insulation defaults)
Three slices on top of `8ee877e4` closed cert pcdb 1 from SAP +6.95
to +0.57 (-92% magnitude) via spec-citable fixes in three distinct
cascade areas.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 21:06:11 +00:00
Khalim Conn-Kowlessar
eda6f449e4 Slice S0380.143: RdSAP 10 §10.11 Table 29 — derive cylinder insulation defaults from construction age band when §15.1 lodges "No Access"
RdSAP 10 Specification §10.11 Table 29 page 56 — "Heating and hot
water parameters" → row "Hot water cylinder insulation if not
accessible":

  Age band of main property A to F: 12 mm loose jacket
  Age band of main property G, H:   25 mm foam
  Age band of main property I to M: 38 mm foam

Pre-slice the Elmhurst mapper passed through cylinder_insulation_type
and cylinder_insulation_thickness_mm as None whenever §15.1 lodged
"Cylinder Size: No Access" (the inaccessible-cylinder lodging form)
because the Summary doesn't carry the measured insulation label /
thickness on inaccessible cylinders. The cascade's §4 (56)m water
storage loss override at `_cylinder_storage_loss_override` then
returned None (gates on `insulation_type == _CYLINDER_INSULATION_
TYPE_FACTORY` + thickness lodged), so the worksheet's (56)m sum was
dropped entirely from (62)m.

Cert pcdb 1 (corpus 001431, Potterton KOA PCDB 716 + 110 L cylinder
+ §15.1 "No Access" + age G 1983-1990) exposes the gap: worksheet
(56)m monthly ≈ 59.06 kWh ((51) factor 0.024 from Note 1 formula
L = 0.005 + 0.55 / (t + 4) at t = 25 mm) × (52) volume factor 1.0294
× (53) Table 2b temperature factor 0.702 — annual sum ≈ 695 kWh,
missing from the pre-slice cascade entirely.

New helper
`_resolve_elmhurst_inaccessible_cylinder_insulation(age_band)` in
`datatypes/epc/domain/mapper.py` returns the
`(insulation_type_code, thickness_mm)` tuple for age G/H (factory
foam, 25 mm) and I/J/K/L/M (factory foam, 38 mm). Age bands A-F
(loose jacket, 12 mm) raise `UnmappedElmhurstLabel` — no current
Elmhurst corpus member is age A-F with §15.1 = "No Access", and the
loose-jacket SAP10 cylinder_insulation_type enum value is not yet
plumbed into the calculator's `cylinder_storage_loss_factor_table_2`
dispatch (only factory=1 is exercised). The strict-raise mirrors the
[[reference-unmapped-sap-code]] pattern so a future fixture forces
the loose-jacket extension explicitly.

`_map_elmhurst_sap_heating` calls the resolver before constructing
SapHeating; the accessible-cylinder path stays unchanged
(measured label + thickness from §15.1).

Corpus impact:

- pcdb 1 (only "No Access" cylinder variant in the corpus):
  SAP +2.86 → +0.57; cost -£63.22 → -£12.55; CO2 -328.74 → -51.19;
  PE -1257.97 → -109.46. The remaining residual is a ~1.3% cascade-
  side undercount on space-heating demand (cascade SH 7900 kWh vs
  worksheet (98c) 8004 kWh) plus minor pumps/fans rate noise — well
  within the spec-cascade floor.

Combined with S0380.141 (§9.4.11 -5pp interlock on SH + Eq D1) and
S0380.142 (§4 lines 7700/7702 cylinder-presence gates), the
pre-slice pcdb 1 residual SAP +6.95 closes to +0.57 (-92% magnitude),
cost -£157.61 to -£12.55, PE -3135.30 to -109.46.

Extended handover suite: 886 pass, 0 fail.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 21:03:10 +00:00
Khalim Conn-Kowlessar
7f9074fca9 Slice S0380.142: §4 (61)m/(59)m cascade — cylinder presence gates combi=0 + primary loss applies for PCDB Table 322 boilers
SAP 10.2 §4 line 7702 (PDF p.137):

  Combi loss for each month from Table 3a, 3b or 3c (enter '0' if
  not a combi boiler)

SAP 10.2 Table 3 (PDF p.160) zero-loss list for primary circuit loss:

  Electric immersion heater
  Combi boiler (including when it is part of a combined heat pump and
  boiler package and provides all the hot water)
  CPSU (including electric CPSU)
  Boiler and thermal store within a single casing
  Separate boiler and thermal store connected by no more than 1.5 m
  of insulated pipework
  Direct-acting electric boiler
  Heat pump (...) with hot water vessel integral to package

Combi boilers are defined by Table 3's zero-loss list entry: they
provide instantaneous DHW with no storage vessel. A cert that lodges
a hot-water cylinder therefore has a non-combi heat generator —
the cylinder bypasses any instantaneous-DHW capability and the
boiler acts as a regular boiler for the DHW circuit.

Two compounding gaps for PCDB Table 322 (gas/oil boiler) records
with a lodged cylinder:

(a) (61)m combi loss: pre-slice the cascade routed every PCDB record
    through `pcdb_combi_loss_override` regardless of cylinder
    presence. For PCDB regular boilers (subsidiary_type=0, store_
    type=0, separate_dhw_tests=0) this dispatched to Table 3a row 1
    "Instantaneous without keep-hot" — 600 kWh/yr. Cert pcdb 1
    (Potterton KOA PCDB 716 + 110 L cylinder) exposed this: worksheet
    (61)m = 0 ; cascade was lodging 600 kWh/yr keep-hot loss on a
    regular oil boiler.

(b) (59)m primary loss: `_primary_loss_applies` gated on
    `main_heating_category in {1, 2}`. The Elmhurst path leaves
    `main_heating_category=None`, so the gate returned False even
    when the cert lodged a PCDB Table 322 (gas/oil boiler) record +
    a cylinder. Worksheet (59)m sum ~1177 kWh ; cascade was zero.

Fix:

- `_water_heating_worksheet_and_gains` now zeroes combi_loss_override
  whenever `epc.has_hot_water_cylinder` is True (top-level gate
  preceding the `pcdb_combi_loss_override` dispatch). Preserves the
  existing non-cylinder fallback for HP / no-PCDB / community-heat
  certs that lack a main_heating_category lodgement.

- `_primary_loss_applies` extends the Elmhurst-path fallback: when
  `main_heating_index_number` resolves to a PCDB Table 322 record,
  return True (the cert is implicitly a boiler — Table 3 row 1 covers
  any "heat generator (e.g. boiler) connected to a hot water storage
  vessel via insulated or uninsulated pipes").

Corpus impact:

- pcdb 1 (Potterton KOA + cylinder, the only PCDB Table 322 + cylinder
  combination in the corpus): SAP +3.40 → +2.86; cost -£75.68 →
  -£63.22; CO2 -397.02 → -328.74; PE -1601.74 → -1257.97.

- Golden cert 0390-2954-3640-2196-4175 (Firebird oil combi PCDF 9005
  + cylinder): PE -26.37 → -28.50; CO2 -2.55 → -2.75. Combi-loss
  removal (-600 kWh/yr) exceeded the primary-loss gain (~5-10 kWh
  given the cert's insulated pipework + thermostat lodging), so the
  net (62) shifted down. Direction is more spec-correct: the spec
  treats a combi feeding a cylinder as a regular boiler for DHW,
  matching the (61)m=0 + (59)m>0 worksheet behaviour.

Extended handover suite: 885 pass, 0 fail.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 20:53:19 +00:00
Khalim Conn-Kowlessar
6636f1c333 Slice S0380.141: §9.4.11 boiler interlock — extend −5pp adjustment to both space-heating efficiency and the PCDB Equation D1 water cascade
SAP 10.2 §9.4.11 (PDF p.30) "Boiler interlock":

  For the purposes of the SAP, an interlocked system is one in which
  both the space and stored water heating are interlocked. If either
  is not, the 5% seasonal efficiency reduction is applied to both
  space and water heating; if both are interlocked no reductions are
  made.

Table 4c (PDF p.169-170) lodges -5 for both Space and DHW columns on
the "No boiler interlock — regular boiler" row. Pre-slice the cascade
applied the -5pp adjustment ONLY to the `water_eff` scalar fallback
(`cert_to_inputs.py:4354`) and missed:

  (a) the SH efficiency path (cascade kept the raw PCDB winter eff for
      space heating);
  (b) the PCDB Equation D1 monthly cascade (Eq D1 received raw
      winter/summer values without the -5pp adjustment).

RdSAP §3 (PDF p.57) defines boiler interlock as "Assumed present if
there is a room thermostat and (for stored hot water systems heated
by the boiler) a cylinder thermostat. Otherwise not interlocked."
Cert pcdb 1 (Potterton KOA PCDB 716 + 110 L cylinder + Cylinder Stat:
No) reproduces the pattern: worksheet (210) = 60% = PCDB winter
65 - 5; worksheet (217)m monthly Eq D1 pivots on (winter 60,
summer 48) not (65, 53).

The SH path is further gated on `pcdb_main is not None` because
§9.4.11 only applies to "gas and liquid fuel boilers" — cert 000565
(ASHP Main 1) keeps its raw SH eff. The combi-fed-cylinder DHW path
(cert 000565 WHC 914 to PCDB combi Main 2) continues to receive its
existing -5pp via the `water_pcdb_main` gate (unchanged).

Corpus impact: pcdb 1 SAP residual +6.95 → +3.40; cost -£157.61 →
-£75.68; CO2 -845.81 → -397.02; PE -3135.30 → -1601.74. No other
variant has PCDB main + cylinder + no thermostat, so the other 24
corpus pins are unchanged.

Extended handover suite: 884 pass, 0 fail (was 883 + 1 new AAA test
pinning the §9.4.11 SH eff path).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 20:33:01 +00:00
Khalim Conn-Kowlessar
8ee877e44c docs: handover update — +2.5 SAP cluster is heterogeneous, not a shared cascade gap
Probed all three variants (electric 3, oil 1, solid fuel 2) in this
thread. Each has a different driver despite the matching magnitude:
- electric 3: §9 useful-demand calc for ctrl=3 storage heaters
- oil 1: HW efficiency for Table 4b oil boiler (cascade 86% vs ws ~65%)
- solid fuel 2: HW kWh lodged in different line ref (re-probe needed)

Tested combined-R hypothesis (effective_R = (1-frac)·R_main + frac·R_sec
per SAP 10.2 §9b) — the cascade currently DOES NOT pass secondary_fraction
to mean_internal_temperature_monthly, so effective_R = R_main. Monkey-
patching to inject combined R REGRESSES electric 3 (+2.55 → +3.17)
because raising R lowers cascade demand — opposite of needed direction.

Recommends taking the three variants as separate per-variant slices.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 19:20:43 +00:00
Khalim Conn-Kowlessar
c389645bfa docs: handover post S0380.138..140 (off-peak tariff cascade + §4 cylinder storage loss)
Three-slice handover covering:
- S0380.138: per-tariff Table 32 low-rate dispatch
- S0380.139: _is_off_peak_meter canonical normalization
- S0380.140: §4 (56)m cylinder storage loss (extractor + cascade)

Ranks next-slice candidates (top: +2.5 SAP cluster across electric 3,
oil 1, solid fuel 2 — likely shared Table 9 MIT bug).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 19:10:16 +00:00
Khalim Conn-Kowlessar
068088bc2f Slice S0380.140: §4 cylinder storage loss — extractor picks up §16 thermostat lodging + Table 2b note b restricts ×0.9 to boiler/warm-air/HP systems
Two compounding bugs were over-counting the SAP 10.2 §4 (56)m cylinder
storage loss by ~76 kWh/yr across all 17 cylinder-with-immersion
corpus variants (cascade HW kWh 2460.40 vs worksheet 2384.12):

(1) **Extractor gap.** Elmhurst Summary §15.1 "Hot Water Cylinder"
    block lodges `Cylinder Size` / `Insulation Thickness` but NOT
    `Cylinder Thermostat`. The thermostat is lodged separately in
    §16 "Recommendations" as `Cylinder thermostat (Already installed)`.
    The extractor only searched §15.1, so `cylinder_thermostat`
    resolved to None for every variant on property 001431. The
    cascade then defaulted `has_cylinder_thermostat=False`, applying
    SAP 10.2 Table 2b's ×1.3 "no thermostat" multiplier.

(2) **Cascade spec gap.** `_separately_timed_dhw` returned True for
    any cylinder-lodged cert regardless of HW fuel. Per SAP 10.2
    Table 2b note b) (PDF p.159):

    > "Multiply Temperature Factor by 0.9 if there is separate time
    >  control of domestic hot water (boiler systems, warm air systems
    >  and heat pump systems)"

    Electric immersion is NOT in the bracketed list — the ×0.9
    reduction is restricted to boiler / warm-air / HP systems. Pre-
    slice the cascade over-applied ×0.9 on electric-immersion certs.

Combined, the cascade computed TF = 0.60 × 1.3 × 0.9 = 0.702 vs the
worksheet's TF = 0.60 (base — thermostat present, immersion exempt).
After both fixes the cascade HW kWh matches the worksheet's (64) at
1e-3 precision (2384.116 vs 2384.12).

Corpus impact (16 cylinder-with-immersion variants on 18-hour meter):

| variant      | SAP_c shift | Cost shift |
|--------------|------------:|-----------:|
| electric 1   | -0.20 →   -0.06 |  -£3.34 |
| electric 2   | -1.27 →   +0.47 |  -£4.44 |
| electric 3   | +2.42 →   +2.55 |  -£2.91 |
| electric 5   | -0.06 →   +0.07 |  -£3.06 |
| electric 6   | +1.19 →   +1.33 |  -£3.20 |
| electric 7   | +1.14 →   +1.29 |  -£3.35 |
| electric 8   | -0.41 →   -0.26 |  -£3.50 |
| electric 9   | -0.24 →   -0.12 |  -£2.91 |
| solid fuel 4-11 | -0.45..-0.09 → -0.29..+0.10 | -£3 to -£4 |

The HW kWh line closes cleanly; some SAP residuals sign-flip slightly
because the cascade's now-correct HW kWh exposes the SH+Sec demand
mismatch for storage heaters (electric 3/6/7 — open driver is the
Table 11 `main_heating_category=None` default for codes 401/402,
queued for a mapper-side slice).

Tests:
- new AAA test `test_separately_timed_dhw_excludes_electric_immersion_per_table_2b_note_b`
- 16 corpus pins re-tightened (8 electric + 8 solid fuel)

Extended handover suite: 883 pass (was 882; +1 new test), 0 fail.
Pyright net-zero on touched files (43 → 43 errors, all pre-existing).

Per [[feedback-spec-citation-in-commits]] +
[[feedback-spec-floor-skepticism]] (the "HW +76 kWh uniform overcount"
across 17 variants traced to TWO spec-citable defaults the cascade
was getting wrong, not a precision floor).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 19:03:58 +00:00
Khalim Conn-Kowlessar
c4db37db19 Slice S0380.139: route _is_off_peak_meter through tariff_from_meter_type canonical dispatch (bare '18 Hour' lodging)
Pre-slice `_is_off_peak_meter` carried its own string-dispatch that
only recognised the RdSAP 10 long form `"off-peak 18 hour"`. The bare
`"18 Hour"` lodging (Elmhurst Summary §14.2 surface form, lodged by
41/41 corpus variants) fell into the catch-all `return False` branch.
That mis-classified every 18-hour cert as non-off-peak for the
secondary / PV cost paths and billed electric secondary heating at
standard 13.19 p/kWh (Table 32 code 30) instead of the 18-hour low
rate 7.41 p/kWh (Table 32 code 40).

The fix routes `_is_off_peak_meter` through `tariff_from_meter_type`
so every lodging form already recognised there (int 1/4/5, `"18 Hour"`,
`"off-peak 18 hour"`, `"Dual"`, `"Dual (24 hour)"`, numeric strings)
is consistently classified. Single (code 2) stays standard; Unknown
(code 3) retains the heuristic "electric end-uses on Unknown meters
typically come from E7-eligible dwellings whose tariff the assessor
couldn't pin down — apply off-peak". Per
[[feedback-zero-error-strict]] the now-dead `_RDSAP_DEFINITELY_OFF_PEAK`
frozenset is deleted (canonical dispatch covers the same codes).

Spec citation per [[feedback-spec-citation-in-commits]]:

> RdSAP 10 §17 page 85 row 10-2 (Electricity meter): "Dual / single /
>  10-hour / 18-hour / 24-hour / unknown"
> RdSAP 10 §12 page 62: "if the meter is dual 18-hour/24-hour it is
>  18-hour/24-hour tariff"

Corpus impact (6 storage-heater / underfloor variants on forced
secondary):

| variant | SAP code | old ΔSAP | new ΔSAP |
|---|---:|---:|---:|
| electric 3 | 401 | -0.10 | +2.42 |
| electric 5 | 402 | -2.48 | -0.06 |
| electric 6 | 404 | -1.14 | +1.19 |
| electric 7 | 408 | -1.08 | +1.14 |
| electric 8 | 409 | -2.54 | -0.41 |
| electric 9 | 421 | -2.76 | -0.24 |

Total absolute SAP residual across the cluster: 10.10 → 5.46.

The 3 sign-flipped variants (electric 3/6/7) surface a separate
cascade bug: `_secondary_heating_fraction_for_category` defaults to
0.10 when the mapper leaves `main_heating_category=None` for electric
storage, but the worksheet for codes 401/402 uses 0.15 = Table 11
Cat 7. Mapper-side fix queued.

Tests:
- new AAA test `test_is_off_peak_meter_recognises_bare_18_hour_lodging`
  covers 7 lodging forms (bare, lowercase, long-form, Single, standard,
  Unknown+electric, Unknown+non-electric)
- 6 corpus pins re-tightened (electric 3/5/6/7/8/9)

Extended handover suite: 882 pass (was 881; +1 new test), 0 fail.
Pyright net-zero on touched files (43 → 43 errors, all pre-existing).

Per [[reference-unmapped-sap-code]] strict-dispatch routing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 18:39:43 +00:00
Khalim Conn-Kowlessar
a830e85565 Slice S0380.138: route every off-peak callsite through the per-tariff Table 32 low-rate (electric +5..+9 SAP cluster + spillover)
Pre-slice every off-peak callsite in `cert_to_inputs.py` —
`_space_heating_fuel_cost_gbp_per_kwh`, `_hot_water_fuel_cost_gbp_per_kwh`,
`_secondary_fuel_cost_gbp_per_kwh`, `_pv_dwelling_import_price_gbp_per_kwh` —
hardcoded `prices.e7_low_rate_p_per_kwh = 5.50` p/kWh (Table 32 code 31,
the 7-hour low rate) regardless of the cert's actual tariff. Every
18-hour cert was thereby under-charged 1.91 p/kWh × off-peak kWh on
its space-heating, hot-water, and secondary-heating cost rows.

Per RdSAP 10 §19 Table 32 (p.95):

> "Electricity ... 7-hour tariff (low rate / off-peak) — code 31 5.50 p/kWh
>  ... 10-hour tariff (low rate) — code 33 7.50 p/kWh
>  ... 18-hour tariff (low rate) — code 40 7.41 p/kWh
>  ... 24-hour tariff — code 35 6.61 p/kWh"

The fix routes through a new `_off_peak_low_rate_gbp_per_kwh(tariff)`
helper that reads the existing per-tariff Table 32 lookup
(`_TARIFF_HIGH_LOW_RATES_P_PER_KWH`). A companion
`_off_peak_low_rate_gbp_per_kwh_via_meter_heuristic(meter_type)` covers
the secondary / PV paths that detect off-peak via the
`_is_off_peak_meter` heuristic (RdSAP meter code 3 = Unknown is treated
as off-peak for electric end-uses), falling back to the SEVEN_HOUR rate
when the meter resolves to STANDARD — codifying the heuristic that the
literal 5.50 constant used to embed.

Per [[feedback-zero-error-strict]] the now-dead
`PriceTable.e7_low_rate_p_per_kwh` field is deleted (no fallback can
silently re-introduce the 5.50 hardcode); the field's docstring +
RDSAP_10_TABLE_32_PRICES instantiation update to point at the new
helpers.

Corpus closure (all 18-hour cohort):

- 8 electric variants — SAP +5.85..+9.64 → -0.10..-2.76; cost
  -£135..-£222 → +£2..+£64
- ashp +5.67 → +0.24 SAP (-£131 → -£5.57)
- gshp +5.16 → +1.15 SAP (-£119 → -£26)
- solid fuel 4..11 — SAP +1.59..+2.04 → ±0.45 (cost ±£10)

Golden 0240 PV path also closes (was raising UnmappedSapCode on
Unknown-meter probe — surfaced an unreachable PV literal that the
meter-heuristic helper now resolves).

Tests:
- new AAA test `test_space_heating_off_peak_fallback_uses_actual_tariff_low_rate_not_e7`
  exercising the EIGHTEEN_HOUR fallback at the helper level
- 19 corpus pins re-tightened (8 electric + ashp + gshp + 8 solid-fuel
  + golden 0240's implicit pin)

Extended handover suite: 881 pass (was 880; +1 new test), 0 fail.
Pyright net-zero on touched files (43 → 43 errors, all pre-existing).

Per [[feedback-spec-citation-in-commits]] +
[[feedback-worksheet-not-api-reference]] +
[[reference-unmapped-sap-code]].

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 18:22:54 +00:00
Khalim Conn-Kowlessar
3be8b8877b docs: handover + next-agent prompt post S0380.131..137
Captures seven slices: heating-oil price flip (S0380.131),
MissingMainFuelType strict-raise (S0380.132), Elmhurst EES → fuel
dispatch (S0380.133), PE pin block-mismatch fix (S0380.134), Table 4a
R-dispatch solid fuel (S0380.135), dual-fuel cost-cascade fix
(S0380.136), Table 4a R-dispatch electric (S0380.137).

Suite: 880 pass / 0 fail at HEAD 3542186f.

Next slice candidate: the +5..+9 SAP cluster across all 7 cascade-OK
electric corpus variants — uniform −£135..−£222 cost under-count
suggests one shared Table 12a tariff-handling gap.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 17:12:10 +00:00
Khalim Conn-Kowlessar
3542186f18 Slice S0380.137: extend Table 4a R-dispatch to electric storage / direct-acting / underfloor / ceiling (cluster)
Continuation of S0380.135's Table 4a per-heating-system responsiveness
dispatch (`_RESPONSIVENESS_BY_SAP_CODE` in cert_to_inputs.py). The
solid-fuel coverage closed 10 corpus variants; this slice extends the
dispatch to the electric heating SAP code ranges from SAP 10.2 Table
4a (PDF p.170):

  401  Old (large volume) storage heaters             R=0.00
  402  Slimline storage heaters                       R=0.20
  403  Convector storage heaters                      R=0.20
  404  Fan storage heaters                            R=0.40
  405  Slimline storage heaters + Celect-type ctrl    R=0.40
  407  Fan storage heaters + Celect-type ctrl         R=0.60
  408  Integrated storage+direct-acting heater        R=0.60
  409  High heat retention storage heaters (§9.2.8)   R=0.80
  421  In concrete slab (off-peak only)               R=0.00
  422  Integrated (storage+direct-acting)             R=0.25
  423  Integrated with low off-peak                   R=0.50
  424  In screed above insulation                     R=0.75
  425  In timber floor / immediately below covering   R=1.00
  515  Electricaire system                            R=0.75
  691  Panel, convector or radiant heaters            R=1.00
  694  Water- or oil-filled radiators                 R=1.00
  701  Electric ceiling heating                       R=0.75

A few electric storage codes (402, 403, 405, 407) carry a *different*
R value in the 24-hour tariff section of Table 4a vs the off-peak
section (e.g. Slimline 402 = R=0.20 off-peak / R=0.40 24-hour). This
dict captures the off-peak value as the default because the 24-hour
tariff is rare in the corpus (no variant lodges it). If a 24-hour-
tariff cert surfaces with one of these codes the dispatch needs to be
promoted to a (sap_code, tariff) lookup; until then the off-peak
default applies.

Heating-systems corpus impact — 6 electric corpus variants re-pinned:

  variant       SAP  R    ΔSAP   was       ΔPE      was
  electric 3    401  0.00 +9.43  +14.70   -1059   -3189
  electric 5    402  0.20 +6.76  +10.97     -96   -1798
  electric 6    404  0.40 +7.82  +10.97    -494   -1770
  electric 7    408  0.60 +7.58   +9.68    -428   -1277
  electric 8    409  0.80 +5.84   +6.89    +200    -224
  electric 9    421  0.00 +6.77  +12.03    +154   -1976

3/6 PE residuals close to ±200 kWh (electric 5/8/9). The remaining
+5..+9 SAP residuals across all electric variants suggest a separate
shared cascade gap (likely Table 12a high/low-rate fraction or pumps/
fans electric handling — fuel cost is consistently under-counted by
~£100-£220 across the cluster). Queued for follow-up.

electric 1 (SAP 191 Direct acting electric boiler) and electric 2
(SAP 524 Air source heat pump) unchanged — both have spec R=1.0
already (matched the Table 4d emitter fallback).

Extended handover suite: 880 pass / 0 fail (+1 new AAA test
covering the 17 electric R-dispatch entries).

Pyright net-zero on touched files (43 → 43).

No golden fixture impact — no golden cert lodges a covered electric
SAP code via the cascade path that would shift residuals.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 17:03:46 +00:00