Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
- xxx


# [0.1.20.3] - 2026-07-15

## Added
- ESDL profile reading and writing for different types: influxdb and postgres, and inline (in ESDL file).

## Changed
- Write_result_db_profiles has been replaced by esdl_profiles_output_type (determines the ESDL output profile type)
- Names used for keys in "database_connections" specified
- Using pyesdl for database credential management

## Fixed
- xxx


# [0.1.20.2] - 2026-07-15

## Added
Expand Down Expand Up @@ -392,4 +406,3 @@
## Fixed
- Error exit when stage 1, priority 1 was not successful


17 changes: 9 additions & 8 deletions examples/PoCTutorial/src/run_grow_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from mesido.esdl.esdl_mixin import DBAccessType
from mesido.esdl.esdl_mixin import DBAccessType, ESDLOutputProfilesType
from mesido.esdl.esdl_parser import ESDLFileParser
from mesido.workflows import EndScenarioSizingStaged, run_end_scenario_sizing

Expand All @@ -13,16 +13,17 @@ class EndScenarioSizingStagedHighs(EndScenarioSizingStaged):
import time

kwargs = {
"write_result_db_profiles": True,
# '"esdl_output_profiles_type"=None' (default) means no profiles to DB
"esdl_output_profiles_type": ESDLOutputProfilesType.INFLUXDB,
"database_connections": [
{
"access_type": DBAccessType.WRITE, # DBAccessType.READ or DBAccessType.READ_WRITE
"influxdb_host": "localhost",
"influxdb_port": 8086,
"influxdb_username": None,
"influxdb_password": None,
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"host": "localhost",
"port": 8086,
"username": None,
"password": None,
"ssl": False,
"verify_ssl": False,
},
],
}
Expand Down
12 changes: 6 additions & 6 deletions examples/municipality/src/run_municipality.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"database_connections": [
{
"access_type": DBAccessType.READ, # DBAccessType.WRITE or DBAccessType.READ_WRITE
"influxdb_host": "required_user_input",
"influxdb_port": 1234,
"influxdb_username": "required_user_input",
"influxdb_password": "required_user_input",
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"host": "required_user_input",
"port": 1234,
"username": "required_user_input",
"password": "required_user_input",
"ssl": False,
"verify_ssl": False,
},
],
}
Expand Down
33 changes: 17 additions & 16 deletions manual_run/testing_bugs/src/run_grow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mesido.esdl.esdl_parser import ESDLFileParser
from mesido.workflows import EndScenarioSizingStaged, run_end_scenario_sizing
from mesido.esdl.esdl_mixin import DBAccessType
from mesido.esdl.esdl_mixin import DBAccessType, ESDLOutputProfilesType

if __name__ == "__main__":
import time
Expand All @@ -11,27 +11,28 @@
base_folder = Path(__file__).resolve().parent.parent

kwargs = {
"use_esdl_ranged_constraint": True, # default value in the code is set to False
"esdl_output_profiles_type": ESDLOutputProfilesType.INFLUXDB,
# None (default) or ESDLOutputProfilesType.POSTGRESQL or
# ESDLOutputProfilesType.TIME_SERIES_PROFILE or ESDLOutputProfilesType.DATE_TIME_PROFILE
"database_connections": [
{
"access_type": DBAccessType.READ, # or DBAccessType.WRITE or DBAccessType.READ_WRITE
"influxdb_host": "required_user_input",
"influxdb_port": 1234,
"influxdb_username": "required_user_input",
"influxdb_password": "required_user_input",
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"host": "required_user_input",
"port": 1234,
"username": "required_user_input",
"password": "required_user_input",
"ssl": False,
"verify_ssl": False,
},
{
"access_type": DBAccessType.WRITE, # or DBAccessType.WRITE or DBAccessType.READ_WRITE
"influxdb_host": "localhost",
"influxdb_port": 8086,
"influxdb_username": None,
"influxdb_password": None,
"influxdb_ssl": False,
"influxdb_verify_ssl": False,
"access_type": DBAccessType.READ_WRITE,
"host": "localhost",
"port": 8086,
"username": "root",
"password": "9012",
"ssl": False,
"verify_ssl": False,
},

],
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# < 81.0.0 needed for pandapipes (still to be removed)
# < 82.0.0 needed for pkg_resources (used in rtctools)
"setuptools <= 80.9.0",
"pyesdl == 26.6.1",
"pyesdl[profiles] == 26.7",
"pandas >= 1.3.1, < 2.0",
"casadi-gil-comp == 3.6.7",
"StrEnum == 0.4.15",
Expand Down
12 changes: 6 additions & 6 deletions src/mesido/asset_sizing_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mesido.esdl.asset_to_component_base import AssetStateEnum
from mesido.esdl.common import Asset
from mesido.esdl.esdl_additional_vars_mixin import get_asset_contraints
from mesido.esdl.profile_parser import InfluxDBProfileReader
from mesido.esdl.profile_parser import ESDLProfileReader
from mesido.head_loss_class import HeadLossOption
from mesido.network_common import NetworkSettings
from mesido.pipe_class import CableClass, GasPipeClass, PipeClass
Expand Down Expand Up @@ -817,7 +817,7 @@ def _get_ub_profile_constraint(asset_name: str, profile_name: str, ub: float) ->
if (
qty_asset_profile_constraints > 0
and hasattr(asset_profile_constraints[0], "maximum")
and InfluxDBProfileReader._get_profile_quantity_and_unit(
and ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.WATT
Expand Down Expand Up @@ -1785,7 +1785,7 @@ def __producer_constraints(
if (
qty_asset_profile_constraints > 0
and hasattr(asset_profile_constraints[0], "maximum")
and InfluxDBProfileReader._get_profile_quantity_and_unit(
and ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.WATT
Expand Down Expand Up @@ -1828,16 +1828,16 @@ def __producer_constraints(
# profile is specified without units (xlm/csv)
qty_asset_profile_constraints == 0
or (
InfluxDBProfileReader._get_profile_quantity_and_unit(
ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).physicalQuantity
== esdl.PhysicalQuantityEnum.COEFFICIENT
and (
InfluxDBProfileReader._get_profile_quantity_and_unit(
ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.PERCENT
or InfluxDBProfileReader._get_profile_quantity_and_unit(
or ESDLProfileReader._get_profile_quantity_and_unit(
asset_profile_constraints[0].maximum
).unit
== esdl.UnitEnum.NONE
Expand Down
63 changes: 42 additions & 21 deletions src/mesido/esdl/esdl_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Any, Dict, List, Optional, Tuple

import esdl.esdl_handler
from esdl.profiles.credentials import Credentials

from mesido.component_type_mixin import (
ModelicaComponentTypeMixin,
Expand All @@ -21,7 +22,7 @@
from mesido.esdl.esdl_model_base import _ESDLModelBase
from mesido.esdl.esdl_parser import ESDLStringParser
from mesido.esdl.esdl_qth_model import ESDLQTHModel
from mesido.esdl.profile_parser import BaseProfileReader, InfluxDBProfileReader
from mesido.esdl.profile_parser import BaseProfileReader, ESDLProfileReader
from mesido.physics_mixin import PhysicsMixin
from mesido.pipe_class import GasPipeClass, PipeClass
from mesido.pycml.pycml_mixin import PyCMLMixin
Expand Down Expand Up @@ -57,6 +58,17 @@ class DBAccessType(StrEnum):
READ_WRITE = "read_write"


class ESDLOutputProfilesType(StrEnum):
"""
Enumeration for ESDL output profiles type
"""

INFLUXDB = "influxdb"
POSTGRESQL = "postgresql"
TIME_SERIES_PROFILE = "time_series_profile"
DATE_TIME_PROFILE = "date_time_profile"


class _ESDLInputException(Exception):
pass

Expand Down Expand Up @@ -132,7 +144,7 @@ def __init__(self, *args, **kwargs) -> None:
DBAccessType.WRITE: [],
}

profile_reader_class = kwargs.get("profile_reader", InfluxDBProfileReader)
profile_reader_class = kwargs.get("profile_reader", ESDLProfileReader)
input_file_name = kwargs.get("input_timeseries_file", None)
input_folder = kwargs.get("input_folder")
input_file_path = None
Expand All @@ -141,37 +153,43 @@ def __init__(self, *args, **kwargs) -> None:
database_connection_info = kwargs.get("database_connections", {})
read_only_dbase_credentials: Dict[str, Tuple[str, str]] = {} # for profile reader
for dbconnection in database_connection_info:
database_host_port = "{}:{}".format(
dbconnection["host"],
dbconnection["port"],
)
if dbconnection["access_type"] != DBAccessType.WRITE:
database_host_port = "{}:{}".format(
dbconnection["influxdb_host"],
dbconnection["influxdb_port"],
)
read_only_dbase_credentials[database_host_port] = (
dbconnection["influxdb_username"],
dbconnection["influxdb_password"],
dbconnection["username"],
dbconnection["password"],
)
if dbconnection["access_type"] != DBAccessType.READ_WRITE:
self._database_credentials[dbconnection["access_type"]].append(
{
"influxdb_host": dbconnection["influxdb_host"],
"influxdb_port": dbconnection["influxdb_port"],
"influxdb_username": dbconnection["influxdb_username"],
"influxdb_password": dbconnection["influxdb_password"],
"influxdb_ssl": dbconnection["influxdb_ssl"],
"influxdb_verify_ssl": dbconnection["influxdb_verify_ssl"],
"host": dbconnection["host"],
"port": dbconnection["port"],
"username": dbconnection["username"],
"password": dbconnection["password"],
"ssl": dbconnection["ssl"] if "ssl" in dbconnection else False,
"verify_ssl": (
dbconnection["verify_ssl"] if "verify_ssl" in dbconnection else False
),
}
)
elif dbconnection["access_type"] == DBAccessType.READ_WRITE:
both_read_and_write = [DBAccessType.READ, DBAccessType.WRITE]
for rw in both_read_and_write:
self._database_credentials[rw].append(
{
"influxdb_host": dbconnection["influxdb_host"],
"influxdb_port": dbconnection["influxdb_port"],
"influxdb_username": dbconnection["influxdb_username"],
"influxdb_password": dbconnection["influxdb_password"],
"influxdb_ssl": dbconnection["influxdb_ssl"],
"influxdb_verify_ssl": dbconnection["influxdb_verify_ssl"],
"host": dbconnection["host"],
"port": dbconnection["port"],
"username": dbconnection["username"],
"password": dbconnection["password"],
"ssl": dbconnection["ssl"] if "ssl" in dbconnection else False,
"verify_ssl": (
dbconnection["verify_ssl"]
if "verify_ssl" in dbconnection
else False
),
}
)
else:
Expand All @@ -181,14 +199,17 @@ def __init__(self, *args, **kwargs) -> None:
)
sys.exit(1)

Credentials.add_credential(
database_host_port, dbconnection["username"], dbconnection["password"]
)

if input_file_name is not None:
input_file_path = Path(input_folder) / input_file_name

if read_only_dbase_credentials: # read from database
self.__profile_reader: BaseProfileReader = profile_reader_class(
energy_system=self.__energy_system_handler.energy_system,
file_path=input_file_path,
database_credentials=read_only_dbase_credentials,
use_esdl_ranged_contraint=self._ESDLMixin__use_esdl_ranged_constraint,
)
else: # read from a file, no database credentials needed
Expand Down
Loading
Loading