Extend ESDL's with relevant key performance indicators.
Project description
KPI Calculator
A Python package for calculating Key Performance Indicators (KPIs) for heat network designs from ESDL files.
Part of the 'Nieuwe Warmte Nu Design Toolkit' project.
Quick Start
from kpicalculator import calculate_kpis
# Automatic: Loads time series from InfluxDB references in ESDL
results = calculate_kpis(esdl_file="path/to/model.esdl")
print(f"Total CAPEX: {results['costs']['capex']['All']} EUR")
Installation
pip install git+https://github.com/Project-OMOTES/kpi-calculator.git@feature/database-connectivity # From development branch
pip install kpi-calculator # Coming soon
Features
KPI Categories:
- Cost: CAPEX, OPEX, NPV, LCOE
- Energy: Consumption, production, efficiency
- Emissions: Total CO2, emissions per MWh
Data Sources:
- ESDL files with embedded cost data
- InfluxDB time series (automatic)
- XML time series files (testing)
- Pandas DataFrames (simulator integration)
Architecture:
- Modular adapters, calculators, and managers
- Full type safety with Pydantic v2
- Secure InfluxDB integration (setup guide)
- Comprehensive test coverage (83%+)
Usage
Basic Usage
from kpicalculator import calculate_kpis
# Production: Automatically loads time series from InfluxDB profiles in ESDL
results = calculate_kpis(esdl_file="model.esdl")
# With optional parameters
results = calculate_kpis(
esdl_file="model.esdl",
system_lifetime=30 # Default: 30 years
)
# Testing: Override with XML file when database is unavailable
results = calculate_kpis(
esdl_file="model.esdl",
time_series="timeseries.xml" # For testing only
)
Data Source Options
Cost Data (priority order):
- ESDL
costInformationelements (production default) - CSV files (testing override only)
Time Series Data (priority order):
- Pandas DataFrames (in-memory, simulator integration)
- InfluxDB profiles (automatic from ESDL InfluxDBProfile references)
- XML files (testing override when database unavailable)
- None (asset-level calculations only)
Note: In production, time series are automatically loaded from InfluxDB when your ESDL file contains InfluxDBProfile references. You only need to specify time_series parameter for testing with XML files.
Database Setup: See Secure Database Setup for configuring InfluxDB credentials using environment variables or secure configuration files.
Simulator Integration
Pass time series data directly as pandas DataFrames:
import pandas as pd
# Create time series data indexed by datetime
datetime_index = pd.date_range("2024-01-01", periods=24, freq="H")
timeseries_data = {
"asset_id_1": pd.DataFrame({
"mass_flow": [2.5, 2.6, 2.4, ...],
"temperature": [353.15, 353.20, ...],
"heat_supplied": [100000, 102000, ...],
}, index=datetime_index),
"asset_id_2": pd.DataFrame({
"heat_demand": [80000, 81000, ...],
}, index=datetime_index),
}
results = calculate_kpis(
esdl_file="model.esdl",
timeseries_dataframes=timeseries_data,
system_lifetime=30
)
Requirements for timeseries_dataframes:
- Keys: Asset IDs matching ESDL file
- Values: DataFrames with datetime index and property columns
- Properties: Any of
mass_flow,pressure,temperature,volume_flow,heat_supplied,heat_demand,velocity,pressure_loss,heat_loss
Integration example: The simulator-worker converts its port-level tuple-column format to asset-level DataFrames before calling calculate_kpis(). See integration guide.
See test: test_timeseries_dataframes_integration
Testing with CSV Override
# Override ESDL costs for testing
results = calculate_kpis(
esdl_file="model.esdl",
pipes_cost="test_pipes.csv",
assets_cost="test_assets.csv"
)
Advanced: Batch Processing
from kpicalculator import KpiManager
# Batch process multiple scenarios
manager = KpiManager("unit_conversion.csv")
scenarios = [
{"file": "scenario_1.esdl", "lifetime": 25},
{"file": "scenario_2.esdl", "lifetime": 30},
{"file": "scenario_3.esdl", "lifetime": 35}
]
for scenario in scenarios:
manager.load_from_esdl(scenario["file"])
results = manager.calculate_all_kpis(system_lifetime=scenario["lifetime"])
# Compare results across scenarios
Results Structure
{
"costs": {
"capex": {"All": 1000000, "HeatProducer": 500000, ...},
"opex": {"All": 50000, ...},
"npv": 850000,
"lcoe": 45.5
},
"energy": {
"consumption": 1e9,
"production": 950000,
"efficiency": 0.95
},
"emissions": {
"total": 1200,
"per_mwh": 1.26
}
}
Supported ESDL Features
Cost Units:
- EUR, EUR/m, EUR/kW, EUR/MW, EUR/kWh, EUR/MWh, EUR/yr, %
- Automatic unit conversion (e.g., EUR/m × pipe length = total investment)
Time Series:
- InfluxDBProfile references (production)
- XML files (testing)
- Pandas DataFrames (simulator integration)
Asset Types:
- Producers, consumers, pipes, storage, conversion, pumps
Dependencies
Runtime:
- pandas ≥2.0.0
- numpy ~2.1.0
- pyesdl ~25.5.1
- pydantic ≥2.0.0
- influxdb ≥5.3.2
- xmltodict 0.14.2
- coloredlogs ~15.0.1
Development Status
Implemented:
- ESDL adapter with cost extraction
- Cost, energy, and emission calculators
- InfluxDB integration
- Security layer with input validation
- CI/CD pipeline with UV
Planned:
- MESIDO adapter
- OMOTES Simulator adapter
- Advanced caching
See Roadmap for details.
Contributing
This project is part of the OMOTES (Optimization and Modeling for Thermal Energy Systems) initiative.
Releases
Releases are automatically published to PyPI when a GitHub Release is created:
- Ensure all changes are merged to
main - Create and push a version tag:
git tag -a v1.2.3 -m "Release 1.2.3" && git push origin v1.2.3 - Create a GitHub Release from the tag
- The CI workflow will automatically build, verify, and publish to PyPI
The workflow includes security scanning, build verification, and generates cryptographic attestations for supply chain security.
License
GNU General Public License v3.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kpi_calculator-0.1.1.tar.gz.
File metadata
- Download URL: kpi_calculator-0.1.1.tar.gz
- Upload date:
- Size: 63.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c7ea3a91fdce3082cd29d7daa63dce7605ddd45d27a6d8066b54fae432c27fa
|
|
| MD5 |
b963ec540d7dffd87964e00de9d4a0f7
|
|
| BLAKE2b-256 |
3f2aefb07646dc11993a6281c15ec0c90cf8e1c32f76fee432bb1eea8e7cb6d8
|
Provenance
The following attestation bundles were made for kpi_calculator-0.1.1.tar.gz:
Publisher:
ci.yml on Project-OMOTES/kpi-calculator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kpi_calculator-0.1.1.tar.gz -
Subject digest:
5c7ea3a91fdce3082cd29d7daa63dce7605ddd45d27a6d8066b54fae432c27fa - Sigstore transparency entry: 808901212
- Sigstore integration time:
-
Permalink:
Project-OMOTES/kpi-calculator@2c155d4e433a0dea1be463b0fd4ca274016d2256 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Project-OMOTES
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@2c155d4e433a0dea1be463b0fd4ca274016d2256 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kpi_calculator-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kpi_calculator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 74.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fd469d654ae9aefa21fdb2265053451d584689ae2b8016130461c00ff16359b
|
|
| MD5 |
127771d7d021ba671d8fed91f00e2cc8
|
|
| BLAKE2b-256 |
34106551800071c5cb418e8488de9e549cf665d042faed0941809689e40e6769
|
Provenance
The following attestation bundles were made for kpi_calculator-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on Project-OMOTES/kpi-calculator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kpi_calculator-0.1.1-py3-none-any.whl -
Subject digest:
1fd469d654ae9aefa21fdb2265053451d584689ae2b8016130461c00ff16359b - Sigstore transparency entry: 808901213
- Sigstore integration time:
-
Permalink:
Project-OMOTES/kpi-calculator@2c155d4e433a0dea1be463b0fd4ca274016d2256 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Project-OMOTES
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@2c155d4e433a0dea1be463b0fd4ca274016d2256 -
Trigger Event:
release
-
Statement type: