A Python simulation engine for modeling solar PV and battery energy storage systems (BESS) for project finance applications in Vietnam.
"Physics First, Finance Second."
Energy balance (kWh) is validated before applying tariffs ($). All calculations are auditable and reproducible.
RE-storage-model/
├── AGENTS.md # Project constitution & coding standards
├── implementation_spec.md # Technical architecture blueprint
├── model_architecture.md # Excel model domain logic (reference)
├── pyproject.toml # Project config & dependencies
├── src/
│ └── re_storage/
│ ├── core/ # Domain types & exceptions
│ ├── inputs/ # Input loading & Pydantic validation
│ ├── physics/ # Solar generation, battery dispatch, energy balance
│ ├── settlement/ # DPPA/CfD revenue, grid charges & savings
│ ├── aggregation/ # Hourly → Monthly → Annual → Lifetime
│ ├── financial/ # Cash flow waterfall, debt sizing, IRR/NPV
│ └── validation/ # Cross-cutting validation checks
├── tests/
│ ├── unit/ # Unit tests by module
│ ├── integration/ # End-to-end pipeline tests
│ ├── regression/ # Excel comparison tests
│ └── data/ # Test fixtures
├── scripts/ # One-off analysis & investigation scripts
├── docs/ # Working documents & reports
├── data/ # Input data files (Excel models)
└── notebooks/ # Exploration & debugging notebooks
# Create virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # Linux/macOS
# Install in development mode
pip install -e ".[dev]"pytest # Run all tests
pytest tests/unit/ # Unit tests only
pytest -v --tb=short # Verbose with short tracebacksmypy --strict src/
ruff check src/ tests/
black --check src/ tests/| Layer | Technology |
|---|---|
| Language | Python 3.11+ |
| Core Computation | pandas + numpy |
| Configuration | pydantic |
| Testing | pytest + hypothesis |
| Type Checking | mypy --strict |
| Formatting | black + isort + ruff |
MIT
This repository now includes a Firebase-hosted web interface under web/:
web/functions- Python Cloud Functions endpoints (/api/run-excel,/api/run-json,/api/compare-scenarios,/api/run-sensitivity)web/frontend- Vite + React + TypeScript SPA
Before deploying functions, vendor the Python package into web/functions so Firebase uploads the model code alongside the handlers:
python scripts/prepare_firebase_functions.pyfirebase deploy runs this automatically via the functions.predeploy hook in firebase.json.
Backend (functions framework):
cd web/functions
python -m venv .venv
.venv\Scripts\activate
python ..\..\scripts\prepare_firebase_functions.py
pip install -r requirements.txt
functions-framework --target runExcel --port 8081Frontend:
cd web/frontend
npm install
npm run devThe frontend dev server proxies /api/* to http://localhost:8080 by default; update
web/frontend/vite.config.ts if you run function targets on different ports.
python scripts/prepare_firebase_functions.py
web\functions\.venv\Scripts\python -m pytest tests/unit/test_web_handlers.py -v
cd web/frontend && npm run build
firebase deploy --only functions,hosting- Replace the placeholder project ID in
.firebasercwith a real Firebase project before the first deploy. - The current Firebase config sets Python functions to
timeoutSeconds: 300andavailableMemoryMb: 1024to support the model runtime.