mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Slice 2. `harness.plan_table.format_plan_table(plan)` renders a Plan as a plain-text table — one package summary line (baseline SAP/band -> post SAP/band, CO2 saved, cost of works + contingency, bill saved) and one line per Plan Measure (signed SAP points, cost, delivered kWh + £ savings). Pure presentation: reads the Plan, computes nothing. The DB-less First Run test now prints it (visible under `pytest -s`) so the modelled package can be eyeballed and debugged by hand. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
"""The sense-check table the DB-less harness prints for a Plan."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from domain.modelling.plan import Plan, PlanMeasure
|
|
from domain.modelling.recommendation import Cost
|
|
from domain.modelling.scoring.package_scorer import Score
|
|
from domain.modelling.scoring.scoring import MeasureImpact
|
|
from harness.plan_table import format_plan_table
|
|
|
|
|
|
def _plan() -> Plan:
|
|
baseline = Score(
|
|
sap_continuous=57.4, co2_kg_per_yr=3000.0, primary_energy_kwh_per_yr=300.0
|
|
)
|
|
post = Score(
|
|
sap_continuous=61.2, co2_kg_per_yr=2100.0, primary_energy_kwh_per_yr=240.0
|
|
)
|
|
measures = (
|
|
PlanMeasure(
|
|
measure_type="cavity_wall_insulation",
|
|
description="Cavity wall insulation",
|
|
cost=Cost(total=500.0, contingency_rate=0.1),
|
|
impact=MeasureImpact(
|
|
sap_points=3.1,
|
|
co2_savings_kg_per_yr=600.0,
|
|
energy_savings_kwh_per_yr=1200.0,
|
|
),
|
|
kwh_savings=900.0,
|
|
energy_cost_savings=120.0,
|
|
),
|
|
PlanMeasure(
|
|
measure_type="mechanical_ventilation",
|
|
description="Mechanical extract ventilation",
|
|
cost=Cost(total=900.0, contingency_rate=0.26),
|
|
impact=MeasureImpact(
|
|
sap_points=-1.3,
|
|
co2_savings_kg_per_yr=-50.0,
|
|
energy_savings_kwh_per_yr=-200.0,
|
|
),
|
|
kwh_savings=-150.0,
|
|
energy_cost_savings=-30.0,
|
|
),
|
|
)
|
|
return Plan(measures=measures, baseline=baseline, post_retrofit=post)
|
|
|
|
|
|
def test_table_shows_package_transition_and_each_measure() -> None:
|
|
# Arrange
|
|
plan: Plan = _plan()
|
|
|
|
# Act
|
|
table: str = format_plan_table(plan)
|
|
|
|
# Assert — the package SAP transition (both bands resolve to D), and each
|
|
# measure's signed SAP contribution against its type.
|
|
assert "57.4" in table
|
|
assert "61.2" in table
|
|
assert "(D)" in table
|
|
assert "cavity_wall_insulation" in table
|
|
assert "+3.1" in table
|
|
assert "mechanical_ventilation" in table
|
|
assert "-1.3" in table
|
|
# The package cost of works (500 + 900) appears.
|
|
assert "1,400" in table
|