Legacy register fuel descriptions resolve to modern main_fuel codes 🟩

Strip the pre-RdSAP-17 deprecation rider and alias the SAP-prefixed
forms before the code-table lookup. Raises the historic fuel resolution
rate from ~22% of pairs to ~92% of dump rows.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-06 10:03:50 +00:00
parent c79cd777e5
commit 1a11d0b900

View file

@ -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)