Skip to content

Commit f80ac6e

Browse files
nhoeningFlix6x
andcommitted
Fix/don't break on multi asset flex model with one asset (#1795)
* improve error messages w.r.t. to asset ID Signed-off-by: Nicolas Höning <nicolas@seita.nl> * fix: flex model deserialization when multi-sensor flex model is not a list anymore Signed-off-by: Nicolas Höning <nicolas@seita.nl> * add changelog entry Signed-off-by: Nicolas Höning <nicolas@seita.nl> * remove some long-deprecated code Signed-off-by: Nicolas Höning <nicolas@seita.nl> * fix: only convert back to single-asset case in case sensor is not part of the flex-model Signed-off-by: F.N. Claessen <felix@seita.nl> * revert: part of db8d0b1 Signed-off-by: F.N. Claessen <felix@seita.nl> * docs: add extra inline explanations of code-blocks Signed-off-by: F.N. Claessen <felix@seita.nl> --------- Signed-off-by: Nicolas Höning <nicolas@seita.nl> Signed-off-by: F.N. Claessen <felix@seita.nl> Co-authored-by: F.N. Claessen <felix@seita.nl> (cherry picked from commit 978066a)
1 parent a6cf636 commit f80ac6e

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

documentation/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bugfixes
1111
-----------
1212
* Support different but still compatible units in time series segments of variable quantities [see `PR #1792 <https://www.github.com/FlexMeasures/flexmeasures/pull/1792>`_]
1313
* Fix account and `/assets/owned_by` pages rendering, giving them asset icons [see `PR #1772 <https://github.com/FlexMeasures/flexmeasures/pull/1772>`_]
14+
* Fix bug when sending one sensor in flex-model when triggering schedule on asset [see `PR #1795 <https://github.com/FlexMeasures/flexmeasures/pull/1795>`_]
1415
* Allow consultants to view client users [see `PR #1755 <https://www.github.com/FlexMeasures/flexmeasures/pull/1755>`_]
1516
* Fix bug where removed flex-model fields don't show up under the dropdown for new fields, except after a page refresh [see `PR #1775 <https://www.github.com/FlexMeasures/flexmeasures/pull/1775>`_]
1617
* Fix bug in displaying user audit log (incl. expanding its API schema) [see `PR #1779 <https://github.com/FlexMeasures/flexmeasures/pull/1779>`_]

flexmeasures/data/models/planning/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ def collect_flex_config(self):
178178
"""Merge the flex-config from the db (from the asset and its ancestors) with the initialization flex-config.
179179
180180
Note that self.flex_context overrides db_flex_context (from the asset and its ancestors).
181-
# todo: also fetch db_flex_model once that exists
182181
"""
183182
if self.asset is not None:
184183
asset = self.asset
@@ -193,11 +192,13 @@ def collect_flex_config(self):
193192
asset_ids = []
194193
flex_model = self.flex_model.copy()
195194
if not isinstance(self.flex_model, list):
195+
# To enable the matching of the passed flex_model with db_flex_models, we need to find out the asset ID
196196
if "asset" not in flex_model:
197197
if self.asset is not None:
198198
flex_model["asset"] = asset.id
199199
else:
200200
flex_model["asset"] = self.sensor.generic_asset.id
201+
# Listify the flex-model for the next code block, which actually does the merging with the db_flex_model
201202
flex_model = [flex_model]
202203

203204
for flex_model_d in flex_model:
@@ -214,9 +215,12 @@ def collect_flex_config(self):
214215
v for k, v in db_flex_model.items() if k not in asset_ids
215216
]
216217
combined_flex_model = amended_db_flex_model + amended_flex_model
217-
if len(combined_flex_model) == 1:
218+
# For the single-asset case, revert the flex-model listification
219+
if len(combined_flex_model) == 1 and "sensor" not in combined_flex_model[0]:
220+
# Single-asset case
218221
self.flex_model = combined_flex_model[0]
219222
else:
223+
# Multi-asset case
220224
self.flex_model = combined_flex_model
221225

222226
def deserialize_config(self):

flexmeasures/data/models/planning/storage.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
integrate_time_series,
3939
)
4040
from flexmeasures.utils.time_utils import get_max_planning_horizon
41-
from flexmeasures.utils.coding_utils import deprecated
4241
from flexmeasures.utils.time_utils import determine_minimum_resampling_resolution
4342
from flexmeasures.utils.unit_utils import ur, convert_units
4443

@@ -1119,15 +1118,17 @@ def _get_device_power_capacity(
11191118
site_power_capacity = site_power_capacity.get("sensor", None)
11201119
if site_power_capacity is None:
11211120
raise ValueError(
1122-
"site-power-capacity attribute is a dict, but has no sensor key."
1121+
f"site-power-capacity attribute on asset {asset.id} is a dict, but has no sensor key."
11231122
)
11241123

11251124
power_capacities.append(
11261125
self._ensure_variable_quantity(site_power_capacity, "MW")
11271126
)
11281127
continue
11291128

1130-
raise ValueError("Power capacity is not defined in the flex-model.")
1129+
raise ValueError(
1130+
f"Power capacity on asset {asset.id} is not defined in the flex-model."
1131+
)
11311132
return power_capacities
11321133

11331134
def _ensure_variable_quantity(
@@ -1807,24 +1808,3 @@ def prepend_series(series: pd.Series, value) -> pd.Series:
18071808
# sort index to keep the time ordering
18081809
series = series.sort_index()
18091810
return series.shift(1)
1810-
1811-
1812-
#####################
1813-
# TO BE DEPRECATED #
1814-
####################
1815-
@deprecated(build_device_soc_values, "0.14")
1816-
def build_device_soc_targets(
1817-
targets: list[dict[str, datetime | float]] | pd.Series,
1818-
soc_at_start: float,
1819-
start_of_schedule: datetime,
1820-
end_of_schedule: datetime,
1821-
resolution: timedelta,
1822-
) -> pd.Series:
1823-
return build_device_soc_values(
1824-
targets, soc_at_start, start_of_schedule, end_of_schedule, resolution
1825-
)
1826-
1827-
1828-
StorageScheduler.compute_schedule = deprecated(StorageScheduler.compute, "0.14")(
1829-
StorageScheduler.compute_schedule
1830-
)

0 commit comments

Comments
 (0)