diff --git a/domain/epc_prediction/historic_conditioning.py b/domain/epc_prediction/historic_conditioning.py index a0c884e0b..82fb082b4 100644 --- a/domain/epc_prediction/historic_conditioning.py +++ b/domain/epc_prediction/historic_conditioning.py @@ -84,6 +84,19 @@ _FUEL_CODES: dict[str, int] = { _NOT_COMMUNITY_SUFFIX = " (not community)" +# Pre-RdSAP-17 lodgements carry a deprecation rider after the fuel name; the +# fuel named is the same physical fuel. Dominant in the pre-2012 dump (a +# 65-shard scan: 636/663 otherwise-unresolved values were these variants). +_LEGACY_SUFFIX = " - this is for backwards compatibility only and should not be used" + +# SAP-style lodgements prefix the category; map the known forms to the base +# description the code table keys on. +_LEGACY_ALIASES: dict[str, str] = { + "Gas: mains gas": "mains gas", + "Electricity: electricity, unspecified tariff": "electricity", + "dual fuel - mineral + wood": "dual fuel (mineral and wood)", +} + @dataclass(frozen=True) class HistoricConditioning: @@ -105,6 +118,8 @@ def _wall_construction(description: str) -> Optional[int]: def _main_fuel(description: str) -> Optional[int]: base = description.strip().removesuffix(_NOT_COMMUNITY_SUFFIX) + base = base.removesuffix(_LEGACY_SUFFIX) + base = _LEGACY_ALIASES.get(base, base) return _FUEL_CODES.get(base)