Band a continuous SAP score on its published rating 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-21 10:07:55 +00:00
parent 08abd3131b
commit 07a71ad504

View file

@ -1,3 +1,4 @@
from decimal import ROUND_HALF_UP, Decimal
from enum import Enum
@ -34,7 +35,14 @@ class Epc(Enum):
@classmethod
def from_sap_continuous(cls, score: float) -> "Epc":
raise NotImplementedError
"""The band an un-rounded SAP rating is *published* in.
A dwelling is banded on the integer published on its EPC, which rounds
half up (SAP 10.2 §13) so this is `from_sap_score` over that rounding
rather than over Python's half-to-even `round`, which would drop an
exact x.5 at a band floor into the band below."""
published: int = int(Decimal(score).quantize(Decimal("1"), rounding=ROUND_HALF_UP))
return cls.from_sap_score(published)
def sap_lower_bound(self) -> int:
"""The minimum SAP rating in this band — the inverse of