Pure-function module + 13 unit tests for the photovoltaic onsite/export
split. No cascade wiring yet — Slices S0380.45..47 will wire β into the
PE / CO2 / cost cascades respectively (which currently all over-credit
the exported PV portion at the IMPORT factor).
Module: `domain/sap10_calculator/worksheet/photovoltaic.py`
- `PhotovoltaicSplit` frozen dataclass — monthly β + (E_PV,dw,m,
E_PV,ex,m) with annual-sum properties matching worksheet line
refs (233a) and (233b).
- `pv_beta_coefficients(Cbat)` — three coefficients keyed on battery
capacity (kWh), capped at 15 per §3c:
CPV1 = 1.610 - 0.0973 × Cbat
CPV2 = 0.415 - 0.00776 × Cbat
CPV3 = 0.511 + 0.0866 × Cbat
- `pv_split_monthly(epv, dpv, battery_kwh)` — per §3d-4:
R_PV,m = E_PV,m / D_PV,m
β_m = min(exp(-CPV1 × (R_PV,m × CPV2)^CPV3), D_PV,m / E_PV,m)
E_PV,dw,m = E_PV,m × β_m; E_PV,ex,m = E_PV,m × (1 - β_m)
Edge cases (not in spec but implied by physics):
- E_PV,m = 0 → β = 0; both onsite and exported = 0
- D_PV,m = 0 → cap forces β = 0; all PV exports
Unit-test coverage (13 tests, AAA convention, `abs(diff) <= tol`):
- β coefficient constants at Cbat=0, 5 (ASHP cohort), 15 (cap)
- Cbat>15 clamps to 15; Cbat<0 clamps to 0 (defensive)
- Hand-computed β worked example (no battery): β≈0.4864 at E_PV=100,
D_PV=200 — pinned at 1e-7 against precomputed value AND at 1e-9
against the live formula recomputation (load-bearing math pin)
- Edge cases: E_PV=0 → no split; D_PV=0 → full export
- Battery monotonicity: β increases with Cbat for fixed (E_PV, D_PV)
- Energy conservation: E_PV,dw + E_PV,ex = E_PV per month + annually
- Tuple length validation (raises on != 12 months)
- Return shape pinned to `PhotovoltaicSplit` dataclass contract
Test suite: 750 → 763 pass + 0 fail. Pyright net-zero on new files.
Spec citation: SAP 10.2 specification Appendix M1 §3-4 (p.93-94).
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