diff --git a/datatypes/epc/domain/epc.py b/datatypes/epc/domain/epc.py index 18d72b310..e1b6d95aa 100644 --- a/datatypes/epc/domain/epc.py +++ b/datatypes/epc/domain/epc.py @@ -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