Skip to content

Commit d574ae3

Browse files
committed
Add a _get_bounds method in PowerDistributingActor
This method will replace the `_get_{upper,lower}_bound` methods in subsequent commits. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent d7c524d commit d574ae3

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/frequenz/sdk/actor/power_distributing/power_distributing.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ...power import DistributionAlgorithm, DistributionResult, InvBatPair
4040
from ._battery_pool_status import BatteryPoolStatus, BatteryStatus
4141
from .request import Request
42-
from .result import Error, OutOfBound, PartialFailure, Result, Success
42+
from .result import Error, OutOfBound, PartialFailure, PowerBounds, Result, Success
4343

4444
_logger = logging.getLogger(__name__)
4545

@@ -226,6 +226,51 @@ def __init__(
226226
bat_id: None for bat_id, _ in self._bat_inv_map.items()
227227
}
228228

229+
def _get_bounds(self, batteries: abc.Set[int], include_broken: bool) -> PowerBounds:
230+
"""Get power bounds for given batteries.
231+
232+
Args:
233+
batteries: List of batteries
234+
include_broken: whether all batteries in the batteries set in the
235+
request must be used regardless the status.
236+
237+
Returns:
238+
Power bounds for given batteries.
239+
"""
240+
pairs_data: List[InvBatPair] = self._get_components_data(
241+
batteries, include_broken
242+
)
243+
return PowerBounds(
244+
inclusion_lower=sum(
245+
max(
246+
battery.power_inclusion_lower_bound,
247+
inverter.active_power_inclusion_lower_bound,
248+
)
249+
for battery, inverter in pairs_data
250+
),
251+
inclusion_upper=sum(
252+
min(
253+
battery.power_inclusion_upper_bound,
254+
inverter.active_power_inclusion_upper_bound,
255+
)
256+
for battery, inverter in pairs_data
257+
),
258+
exclusion_lower=sum(
259+
min(
260+
battery.power_exclusion_lower_bound,
261+
inverter.active_power_exclusion_lower_bound,
262+
)
263+
for battery, inverter in pairs_data
264+
),
265+
exclusion_upper=sum(
266+
max(
267+
battery.power_exclusion_upper_bound,
268+
inverter.active_power_exclusion_upper_bound,
269+
)
270+
for battery, inverter in pairs_data
271+
),
272+
)
273+
229274
def _get_upper_bound(self, batteries: abc.Set[int], include_broken: bool) -> float:
230275
"""Get total upper bound of power to be set for given batteries.
231276

src/frequenz/sdk/actor/power_distributing/result.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ class Error(Result):
7777
"""The error message explaining why error happened."""
7878

7979

80+
@dataclasses.dataclass
81+
class PowerBounds:
82+
"""Inclusion and exclusion power bounds for requested batteries."""
83+
84+
inclusion_lower: float
85+
exclusion_lower: float
86+
exclusion_upper: float
87+
inclusion_upper: float
88+
89+
8090
@dataclasses.dataclass
8191
class OutOfBound(Result):
8292
"""Result returned when the power was not set because it was out of bounds.

0 commit comments

Comments
 (0)