Skip to content

Commit 096b8b4

Browse files
authored
Improve consistency between *Pools (#894)
Also does some cleanup on the PowerDistributor tests.
2 parents b6f4f5f + ddcf616 commit 096b8b4

File tree

12 files changed

+157
-128
lines changed

12 files changed

+157
-128
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
- The minimum required `frequenz-channels` version is now [`v1.0.0-rc1`](https://github.com/frequenz-floss/frequenz-channels-python/releases/tag/v1.0.0-rc.1).
1212

13+
- The set of battery IDs managed by a battery pool are now available through `BatteryPool.component_ids`, and no longer through `BatteryPool.battery_ids`. This is done to have a consistent interface with other `*Pool`s.
14+
15+
- The `maxsize` parameter in calls to `BatteryPool.{soc/capacity/temperature}.new_receiver()` methods have now been renamed to `limit`, to be consistent with the channels repository.
16+
1317
## New Features
1418

1519
<!-- Here goes the main new features and examples or instructions on how to use them -->

benchmarks/timeseries/benchmark_ringbuffer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ def main() -> None:
174174
"Time to fill 29 days with data:\n\t"
175175
+ f"Array: {array_times['fill']} seconds\n\t"
176176
+ f"List: {list_times['fill']} seconds\n\t"
177-
+ f"Diff: {array_times['fill'] - list_times['fill']}"
177+
+ f"Diff: {array_times['fill'] - list_times['fill']}"
178178
)
179179

180180
print(
181181
"Day-Slices into 29 days with data:\n\t"
182182
+ f"Array: {array_times['test']/num_runs} seconds\n\t"
183183
+ f"List: {list_times['test']/num_runs} seconds\n\t"
184-
+ f"Diff: {array_times['test']/num_runs - list_times['test']/num_runs}"
184+
+ f"Diff: {array_times['test']/num_runs - list_times['test']/num_runs}"
185185
)
186186

187187
print(f" {''.join(['='] * (num_runs + 1))}")
@@ -195,15 +195,15 @@ def main() -> None:
195195
"Avg of windows of 29 days and running average & mean on every day:\n\t"
196196
+ f"Array: {slicing_array_times['avg']/num_runs} seconds\n\t"
197197
+ f"List: {slicing_list_times['avg']/num_runs} seconds\n\t"
198-
+ f"Diff: {slicing_array_times['avg']/num_runs - slicing_list_times['avg']/num_runs}"
198+
+ f"Diff: {slicing_array_times['avg']/num_runs - slicing_list_times['avg']/num_runs}"
199199
)
200200

201201
print(
202202
"Median of windows of 29 days and running average & mean on every day:\n\t"
203203
+ f"Array: {slicing_array_times['median']/num_runs} seconds\n\t"
204204
+ f"List: {slicing_list_times['median']/num_runs} seconds\n\t"
205205
+ "Diff: "
206-
+ f"{slicing_array_times['median']/num_runs - slicing_list_times['median']/num_runs}"
206+
+ f"{slicing_array_times['median']/num_runs - slicing_list_times['median']/num_runs}"
207207
)
208208

209209

examples/battery_pool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ async def main() -> None:
3030

3131
battery_pool = microgrid.battery_pool()
3232
receivers = [
33-
battery_pool.soc.new_receiver(maxsize=1),
34-
battery_pool.capacity.new_receiver(maxsize=1),
33+
battery_pool.soc.new_receiver(limit=1),
34+
battery_pool.capacity.new_receiver(limit=1),
3535
# pylint: disable=protected-access
36-
battery_pool._system_power_bounds.new_receiver(maxsize=1),
36+
battery_pool._system_power_bounds.new_receiver(limit=1),
3737
# pylint: enable=protected-access
3838
]
3939

src/frequenz/sdk/_internal/_channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class ReceiverFetcher(typing.Generic[T_co], typing.Protocol):
1616
"""An interface that just exposes a `new_receiver` method."""
1717

1818
@abc.abstractmethod
19-
def new_receiver(self, *, maxsize: int = 50) -> Receiver[T_co]:
19+
def new_receiver(self, *, limit: int = 50) -> Receiver[T_co]:
2020
"""Get a receiver from the channel.
2121
2222
Args:
23-
maxsize: The maximum size of the receiver.
23+
limit: The maximum size of the receiver.
2424
2525
Returns:
2626
A receiver instance.

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def producer(self) -> Producer:
154154

155155
def ev_charger_pool(
156156
self,
157-
ev_charger_ids: set[int] | None = None,
157+
ev_charger_ids: abc.Set[int] | None = None,
158158
) -> EVChargerPool:
159159
"""Return the corresponding EVChargerPool instance for the given ids.
160160
@@ -350,7 +350,7 @@ def producer() -> Producer:
350350
return _get().producer()
351351

352352

353-
def ev_charger_pool(ev_charger_ids: set[int] | None = None) -> EVChargerPool:
353+
def ev_charger_pool(ev_charger_ids: abc.Set[int] | None = None) -> EVChargerPool:
354354
"""Return the corresponding EVChargerPool instance for the given ids.
355355
356356
If an EVChargerPool instance for the given ids doesn't exist, a new one is

src/frequenz/sdk/timeseries/battery_pool/_battery_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ async def propose_discharge(
230230
)
231231

232232
@property
233-
def battery_ids(self) -> abc.Set[int]:
233+
def component_ids(self) -> abc.Set[int]:
234234
"""Return ids of the batteries in the pool.
235235
236236
Returns:

src/frequenz/sdk/timeseries/battery_pool/_methods.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def update_working_batteries(self, new_working_batteries: set[int]) -> None:
4040
"""
4141

4242
@abstractmethod
43-
def new_receiver(self, maxsize: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
43+
def new_receiver(self, limit: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
4444
"""Return new receiver for the aggregated metric results.
4545
4646
Args:
47-
maxsize: Buffer size of the receiver
47+
limit: Buffer size of the receiver
4848
4949
Returns:
5050
Receiver for the metric results.
@@ -119,18 +119,18 @@ def name(cls) -> str:
119119
"""
120120
return "SendOnUpdate"
121121

122-
def new_receiver(self, maxsize: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
122+
def new_receiver(self, limit: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
123123
"""Return new receiver for the aggregated metric results.
124124
125125
Args:
126-
maxsize: Buffer size of the receiver
126+
limit: Buffer size of the receiver
127127
128128
Returns:
129129
Receiver for the metric results.
130130
"""
131-
if maxsize is None:
131+
if limit is None:
132132
return self._result_channel.new_receiver()
133-
return self._result_channel.new_receiver(limit=maxsize)
133+
return self._result_channel.new_receiver(limit=limit)
134134

135135
def update_working_batteries(self, new_working_batteries: set[int]) -> None:
136136
"""Update set of the working batteries.

src/frequenz/sdk/timeseries/ev_charger_pool/_ev_charger_pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(
7777
self,
7878
channel_registry: ChannelRegistry,
7979
resampler_subscription_sender: Sender[ComponentMetricRequest],
80-
component_ids: set[int] | None = None,
80+
component_ids: abc.Set[int] | None = None,
8181
repeat_interval: timedelta = timedelta(seconds=3.0),
8282
) -> None:
8383
"""Create an `EVChargerPool` instance.
@@ -103,7 +103,7 @@ def __init__(
103103
self._resampler_subscription_sender: Sender[ComponentMetricRequest] = (
104104
resampler_subscription_sender
105105
)
106-
self._component_ids: set[int] = set()
106+
self._component_ids: abc.Set[int] = set()
107107
if component_ids is not None:
108108
self._component_ids = component_ids
109109
else:

src/frequenz/sdk/timeseries/ev_charger_pool/_state_tracker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import asyncio
9+
from collections import abc
910
from enum import Enum
1011

1112
from frequenz.channels import Merger, Receiver, merge
@@ -78,7 +79,7 @@ def is_ev_connected(self) -> bool:
7879
class StateTracker:
7980
"""A class for keeping track of the states of all EV Chargers in a pool."""
8081

81-
def __init__(self, component_ids: set[int]) -> None:
82+
def __init__(self, component_ids: abc.Set[int]) -> None:
8283
"""Create a `_StateTracker` instance.
8384
8485
Args:

0 commit comments

Comments
 (0)