The CO2 cascade in calculator.py had no PV credit at all
(environmental_section_from_cert had a stale `pv_credit = 0.0` with
the comment "no PV in any Elmhurst fixture", but that helper isn't
called by `calculate_sap_from_inputs` anyway). The full ASHP+PV
cluster therefore over-counted CO2 by +0.16..+0.28 t/yr — the entire
PV CO2 offset was missing.
Wiring (calculator.py):
- New fields: `pv_dwelling_co2_factor_kg_per_kwh: Optional[float]`,
`pv_exported_co2_factor_kg_per_kwh: Optional[float]`.
- CO2 cascade now subtracts:
pv_co2_credit = E_PV,dw × dwelling_CO2_factor
+ E_PV,ex × exported_CO2_factor
when the split + factors are set. None preserves the legacy
zero-credit behaviour for synthetic CalculatorInputs constructions.
Wiring (cert_to_inputs.py):
- New constant: `_PV_EXPORT_FUEL_CODE_TABLE_12 = 60` (SAP 10.2
Table 12 code 60, "electricity sold to grid, PV") — the EXPORT
factor key per Appendix M1 §6/§7/§8.
- The dwelling CO2 factor is the effective monthly Table 12d Σ
weighted by E_PV,dw,m at code 30 (Standard electricity); the
exported CO2 factor is the same Σ weighted by E_PV,ex,m at
code 60 ("Electricity sold to grid, PV"). Both reuse the
existing `_effective_monthly_co2_factor` helper.
Test impact (CO2 residual cluster, re-pinned in this slice):
Pre-Slice 46 → Post-Slice 46:
- 0330 (no PV): -0.034 → -0.034 (unchanged ✓)
- 0350 (PV + 5 kWh battery): +0.171 → -0.084
- 0380 (PV + 5 kWh battery): +0.279 → -0.054
- 2130 (PV + gas combi): +0.299 → -0.046
- 2225 (PV + 5 kWh battery): +0.263 → -0.071
- 2636 (PV + 5 kWh battery): +0.219 → -0.058
- 3800 (PV + 5 kWh battery): +0.261 → -0.014
- 9285 (PV + 5 kWh battery): +0.157 → -0.098
- 9418 (PV + 5 kWh battery): +0.232 → -0.046
- 9501 (PV, no battery): +0.202 → -0.047
Cluster magnitude dropped 3-5× — over-count flipped to slight
under-count (-0.01..-0.10 vs +0.16..+0.28). The remaining negative
residual is largely the same E_PV-magnitude bug from Slice 45 (PV
is over-credited because the cascade thinks E_PV ≈ 3× the worksheet
value for the 5-kWh-battery cohort). Slice 47 (cost cascade) + Slice
S0380.48 (E_PV magnitude audit) will close the cluster further.
Chain tests still <1e-4 — CO2 cascade isn't gated by the chain
tests' SAP-rating-vs-worksheet assertions.
Test suite: 763 pass + 0 fail. Pyright net-zero per touched file
(calculator.py 0/0; cert_to_inputs.py 34/34; test_golden_fixtures.py 1/1).
Spec citations:
- SAP 10.2 specification Appendix M1 §7 (p.94) — PV CO2 credit split.
- SAP 10.2 Table 12d (p.194) code 60 — monthly CO2 factor for
"electricity sold to grid, PV" (already in `tables/table_12.py`).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
||
|---|---|---|
| .devcontainer | ||
| .github/workflows | ||
| .idea | ||
| .vscode | ||
| applications | ||
| asset_list | ||
| backend | ||
| backlog | ||
| datatypes | ||
| deployment/terraform | ||
| docs/adr | ||
| domain | ||
| epr_data_exports | ||
| etl | ||
| infrastructure | ||
| model_data/requirements | ||
| orchestration | ||
| recommendations | ||
| repositories | ||
| scripts | ||
| sfr/principal_pitch | ||
| survey_report | ||
| tests | ||
| utilities | ||
| utils | ||
| .coveragerc | ||
| .dockerignore | ||
| .gitignore | ||
| __init__.py | ||
| ara_backend_design.md | ||
| BaseUtility.py | ||
| CLAUDE.md | ||
| conftest.py | ||
| CONTEXT.md | ||
| devcontainer.sh | ||
| Dockerfile.test | ||
| Dockerfile.test.dockerignore | ||
| Makefile | ||
| MEMORY.md | ||
| package-lock.json | ||
| package.json | ||
| pyproject.toml | ||
| pyrightconfig.json | ||
| pytest.ini | ||
| README.md | ||
| run_lambda_local.sh | ||
| serverless.yml | ||
| test.requirements.txt | ||
| tox.ini | ||
| UBIQUITOUS_LANGUAGE.md | ||
Model Repository
This repository contains the code pertaining to the development of the data science and machine learning products being utilised by Hestia.
The different folders in this repository relate to services that can be used independently, or can be imported and used as part of a larger application
Getting Started
Prerequisites
Dev Container Setup
This repo uses a Docker Compose-based dev container. The model-backend service joins a shared-dev Docker network so it can communicate with other local services (e.g. a frontend container) running on your machine.
VS Code users: The initializeCommand in devcontainer.json creates the shared-dev network automatically before the container starts. No manual step required — just open the repo and select Reopen in Container.
Non-VS Code / CI workflows: Run the following once before starting the container:
make dev-setup
This is idempotent and safe to re-run if the network already exists.
Folders
backend/
This folder contains the code for the fastapi backend service, which provides an interface to much of the functionality in this repository, for the frontend
model_data/
This folder contains related to the reading and preparation of assessment model data, including pulling out epc attributes
Testing
All tests can be run, against the configuration in pytest.ini running
pytest
This will run the complete panel of tests and report on coverage in the locations specified by the pytest.ini file.
To run tests in a specific service, e.g. inside of model_data, simply run
pytest --cov-config=model_data/.coveragerc --cov=model_data
This will produce the test results and coverage reports