Sell no works to a dwelling already at the goal band 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-21 10:04:48 +00:00
parent 31ad9448d2
commit 8548b8304b

View file

@ -0,0 +1,42 @@
"""The Optimiser judges "already at the goal band" on the *published* rating.
A dwelling is in a band by the rating published on its EPC the continuous SAP
rounded half up. The Optimiser works in continuous SAP, so a goal of "reach band
X" has to be met at the point the published rating enters band X (the integer
floor less half a point), not at the integer floor itself. Comparing a
continuous score against the integer floor makes a dwelling that already
publishes in the band read as a fraction short, and the Optimiser buys the
cheapest measure to close a gap that does not exist (#1652 / #1654 — 630 homes
in portfolio 796 published at SAP 69 / band C, each sold ~1 marginal SAP point
of works toward a band they had already reached).
End-to-end through ``run_modelling`` (no database) with the real calculator,
against Elmhurst certs that sit in the boundary window.
"""
from __future__ import annotations
from datatypes.epc.domain.epc_property_data import EpcPropertyData
from domain.modelling.plan import Plan
from harness.console import run_modelling
from tests.domain.modelling._elmhurst_recommendation import (
parse_recommendation_summary,
)
def _dwelling(fixture: str) -> EpcPropertyData:
return parse_recommendation_summary(fixture)
def test_dwelling_published_at_the_goal_band_is_sold_no_works() -> None:
# Arrange — cert 001431 with a flat roof scores a continuous 54.575, which
# publishes as SAP 55: exactly the band D floor, so the dwelling already IS
# band D. Against an integer floor of 55 it reads as 0.425 short.
already_band_d = _dwelling("flat_roof_001431_before.pdf")
# Act — ask for the band it is already in.
plan: Plan = run_modelling(already_band_d, goal_band="D", print_table=False)
# Assert — nothing to buy: the goal is already met.
assert plan.measures == ()
assert plan.cost_of_works == 0.0