From 782c6869693178b664f6973907ed3a34f9a85ee8 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Wed, 24 Jun 2026 11:20:32 +0000 Subject: [PATCH] Map fuel code 39 (electricity, any tariff) to standard electricity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit modelling_e2e properties with main fuel 39 failed at the price boundary (UnpricedFuelCode since #44fff767; previously mis-rated as non-electric → the ~14-SAP over-rating flagged in earlier review). Code 39 is SAP Table 12 "electricity, any tariff" (epc_codes.csv main_fuel 39 = "electricity, unspecified tariff"; spec footnote (j): defines an electric system, cost/CO2/PE = standard electricity). It was absent from API_FUEL_TO_TABLE_32, so to_table_32_code(39) was None → is_electric_fuel_code(39) False and pricing raised. Fix: map API_FUEL_TO_TABLE_32[39] = 30 (standard electricity) — the canonical place Khalim's fuel work added codes. One line makes classification, pricing, CO2/PE and the billing carrier all agree (39 → 30 → ELECTRICITY). Tests: to_table_32_code(39)==30, is_electric_fuel_code(39) True, price == standard electricity, and the billing carrier resolves to ELECTRICITY. 0 corpus impact (no lodged corpus cert uses 39); accuracy + mapper-corpus gates green. Co-Authored-By: Claude Opus 4.8 (1M context) --- domain/sap10_calculator/tables/table_32.py | 6 ++++++ tests/domain/billing/test_sap_fuel.py | 1 + tests/domain/sap10_calculator/test_table_32.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/domain/sap10_calculator/tables/table_32.py b/domain/sap10_calculator/tables/table_32.py index da22b5ce..6eee48df 100644 --- a/domain/sap10_calculator/tables/table_32.py +++ b/domain/sap10_calculator/tables/table_32.py @@ -107,6 +107,12 @@ API_FUEL_TO_TABLE_32: Final[dict[int, int]] = { 10: 30, 11: 42, 12: 43, 13: 44, 14: 11, 15: 12, 16: 22, 17: 9, 18: 75, 19: 76, 20: 51, 21: 52, 22: 53, 23: 55, 24: 54, 25: 41, 26: 1, 27: 2, 28: 4, 29: 30, 30: 42, 31: 43, 32: 44, 33: 11, + # SAP Table 12 code 39 = "electricity, any tariff" (epc_codes.csv main_fuel + # 39 = "electricity, unspecified tariff"; spec footnote (j): defines an + # electric system, cost/CO2/PE = standard electricity). Resolve to standard + # electricity (30) so it classifies as electric and prices at the standard + # rate — otherwise it now raises UnpricedFuelCode (was: mis-rated non-electric). + 39: 30, } # Gov-API `main_fuel_type` enum codes whose value COLLIDES with a diff --git a/tests/domain/billing/test_sap_fuel.py b/tests/domain/billing/test_sap_fuel.py index 98bc5c23..dda833a5 100644 --- a/tests/domain/billing/test_sap_fuel.py +++ b/tests/domain/billing/test_sap_fuel.py @@ -43,6 +43,7 @@ def test_table_32_codes_map_to_their_billing_fuel(code: int, fuel: Fuel) -> None (0, Fuel.ELECTRICITY), # API "electricity" -> Table 32 code 30 (25, Fuel.HEAT_NETWORK), # API community heat -> Table 32 code 41 (14, Fuel.COAL), # API house coal -> Table 32 code 11 + (39, Fuel.ELECTRICITY), # "electricity, any tariff" -> Table 32 code 30 ], ) def test_raw_api_fuel_codes_normalize_before_mapping(api_code: int, fuel: Fuel) -> None: diff --git a/tests/domain/sap10_calculator/test_table_32.py b/tests/domain/sap10_calculator/test_table_32.py index 59e2c93c..e8fb4ab2 100644 --- a/tests/domain/sap10_calculator/test_table_32.py +++ b/tests/domain/sap10_calculator/test_table_32.py @@ -339,3 +339,19 @@ def test_additional_standing_charges_zero_for_oil_only() -> None: # Assert assert standing == 0.0 + + +def test_electricity_any_tariff_code_39_resolves_to_standard_electricity() -> None: + # SAP Table 12 code 39 = "electricity, any tariff" (epc_codes.csv main_fuel 39 + # = "electricity, unspecified tariff"; spec footnote (j): defines an electric + # system, cost = standard tariff). It must classify as electric and price at + # the standard-electricity rate — without the mapping it raises UnpricedFuelCode + # and is_electric_fuel_code(39) is False (mis-rated as non-electric). + from domain.sap10_calculator.tables.table_32 import ( + is_electric_fuel_code, + to_table_32_code, + ) + + assert to_table_32_code(39) == 30 + assert is_electric_fuel_code(39) is True + assert unit_price_p_per_kwh(39) == unit_price_p_per_kwh(30)