Skip to content

Commit 479bb90

Browse files
authored
Improve naming for per-phase component metric streams (#987)
Closes #880
2 parents 69aad56 + f78e8c7 commit 479bb90

File tree

11 files changed

+43
-33
lines changed

11 files changed

+43
-33
lines changed

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
+ `ev_charger_pool` -> `new_ev_charger_pool`
1212
+ `pv_pool` -> `new_pv_pool`
1313

14+
- The following component metric streams have been renamed to clarify that they stream per-phase values:
15+
+ `frequenz.sdk.microgrid.`
16+
* `voltage` -> `voltage_per_phase`
17+
* `grid.current` -> `grid.current_per_phase`
18+
* `ev_charger_pool.current` -> `ev_charger_pool.current_per_phase`
19+
1420
## New Features
1521

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(
5555
self._ev_charger_ids = self._get_ev_charger_ids()
5656
self._evc_states = EvcStates()
5757
self._voltage_cache: LatestValueCache[Sample3Phase[Voltage]] = LatestValueCache(
58-
microgrid.voltage().new_receiver(),
58+
microgrid.voltage_per_phase().new_receiver(),
5959
unique_id=f"{type(self).__name__}«{hex(id(self))}»:voltage_cache",
6060
)
6161
self._config = EVDistributionConfig(component_ids=self._ev_charger_ids)

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
new_ev_charger_pool,
235235
new_pv_pool,
236236
producer,
237-
voltage,
237+
voltage_per_phase,
238238
)
239239

240240

@@ -263,5 +263,5 @@ async def initialize(server_url: str, resampler_config: ResamplerConfig) -> None
263263
"new_ev_charger_pool",
264264
"new_pv_pool",
265265
"producer",
266-
"voltage",
266+
"voltage_per_phase",
267267
]

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def frequency(self) -> GridFrequency:
139139

140140
return self._frequency_instance
141141

142-
def voltage(self) -> VoltageStreamer:
143-
"""Return the 3-phase voltage measuring point."""
142+
def voltage_per_phase(self) -> VoltageStreamer:
143+
"""Return the per-phase voltage measuring point."""
144144
if not self._voltage_instance:
145145
self._voltage_instance = VoltageStreamer(
146146
self._resampling_request_sender(),
@@ -506,9 +506,9 @@ def frequency() -> GridFrequency:
506506
return _get().frequency()
507507

508508

509-
def voltage() -> VoltageStreamer:
510-
"""Return the 3-phase voltage measuring point."""
511-
return _get().voltage()
509+
def voltage_per_phase() -> VoltageStreamer:
510+
"""Return the per-phase voltage measuring point."""
511+
return _get().voltage_per_phase()
512512

513513

514514
def logical_meter() -> LogicalMeter:

src/frequenz/sdk/timeseries/_voltage_streamer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class VoltageStreamer:
4444
)
4545
4646
# Get a receiver for the phase-to-neutral voltage.
47-
voltage_recv = microgrid.voltage().new_receiver()
47+
voltage_recv = microgrid.voltage_per_phase().new_receiver()
4848
4949
async for voltage_sample in voltage_recv:
5050
print(voltage_sample)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class EVChargerPool:
3333
3434
Provides:
3535
- Aggregate [`power`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.power]
36-
and 3-phase
37-
[`current`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.current]
36+
and
37+
[`current_per_phase`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.current_per_phase]
3838
measurements of the EV Chargers in the pool.
3939
"""
4040

@@ -147,7 +147,7 @@ def component_ids(self) -> abc.Set[int]:
147147
return self._pool_ref_store.component_ids
148148

149149
@property
150-
def current(self) -> FormulaEngine3Phase[Current]:
150+
def current_per_phase(self) -> FormulaEngine3Phase[Current]:
151151
"""Fetch the total current for the EV Chargers in the pool.
152152
153153
This formula produces values that are in the Passive Sign Convention (PSC).

src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ class FormulaEngine3Phase(
443443
[`FormulaEngine`][frequenz.sdk.timeseries.formula_engine.FormulaEngine], except that
444444
they stream [3-phase samples][frequenz.sdk.timeseries.Sample3Phase]. All the
445445
current formulas (like
446-
[`Grid.current`][frequenz.sdk.timeseries.grid.Grid.current],
447-
[`EVChargerPool.current`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.current],
448-
etc.) are implemented as 3-phase formulas.
446+
[`Grid.current_per_phase`][frequenz.sdk.timeseries.grid.Grid.current_per_phase],
447+
[`EVChargerPool.current_per_phase`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.current_per_phase],
448+
etc.) are implemented as per-phase formulas.
449449
450450
### Streaming Interface
451451
@@ -461,7 +461,7 @@ class FormulaEngine3Phase(
461461
462462
ev_charger_pool = microgrid.new_ev_charger_pool(priority=5)
463463
464-
async for sample in ev_charger_pool.current.new_receiver():
464+
async for sample in ev_charger_pool.current_per_phase.new_receiver():
465465
print(f"Current: {sample}")
466466
```
467467
@@ -478,7 +478,9 @@ class FormulaEngine3Phase(
478478
grid = microgrid.grid()
479479
480480
# Calculate grid consumption current that's not used by the EV chargers
481-
other_current = (grid.current - ev_charger_pool.current).build("other_current")
481+
other_current = (grid.current_per_phase - ev_charger_pool.current_per_phase).build(
482+
"other_current"
483+
)
482484
483485
async for sample in other_current.new_receiver():
484486
print(f"Other current: {sample}")

src/frequenz/sdk/timeseries/grid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def power(self) -> FormulaEngine[Power]:
9999
return engine
100100

101101
@property
102-
def _power_3_phase(self) -> FormulaEngine3Phase[Power]:
103-
"""Fetch the grid 3-phase power for the microgrid.
102+
def _power_per_phase(self) -> FormulaEngine3Phase[Power]:
103+
"""Fetch the per-phase grid power for the microgrid.
104104
105105
This formula produces values that are in the Passive Sign Convention (PSC).
106106
@@ -117,8 +117,8 @@ def _power_3_phase(self) -> FormulaEngine3Phase[Power]:
117117
return engine
118118

119119
@property
120-
def current(self) -> FormulaEngine3Phase[Current]:
121-
"""Fetch the grid current for the microgrid.
120+
def current_per_phase(self) -> FormulaEngine3Phase[Current]:
121+
"""Fetch the per-phase grid current for the microgrid.
122122
123123
This formula produces values that are in the Passive Sign Convention (PSC).
124124

tests/microgrid/test_grid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ async def test_grid_power_3_phase_side_meter(mocker: MockerFixture) -> None:
200200
assert grid, "Grid is not initialized"
201201
stack.push_async_callback(grid.stop)
202202

203-
grid_power_3_phase_recv = (
204-
grid._power_3_phase.new_receiver() # pylint: disable=protected-access
203+
grid_power_per_phase_recv = (
204+
grid._power_per_phase.new_receiver() # pylint: disable=protected-access
205205
)
206206

207207
for count in range(10):
@@ -216,7 +216,7 @@ async def test_grid_power_3_phase_side_meter(mocker: MockerFixture) -> None:
216216
[watts_phases, watts_phases]
217217
)
218218

219-
val = await grid_power_3_phase_recv.receive()
219+
val = await grid_power_per_phase_recv.receive()
220220
assert val is not None
221221
assert val.value_p1 and val.value_p2 and val.value_p3
222222
assert val.value_p1.as_watts() == watts_phases[0]
@@ -234,8 +234,8 @@ async def test_grid_power_3_phase_none_values(mocker: MockerFixture) -> None:
234234
assert grid, "Grid is not initialized"
235235
stack.push_async_callback(grid.stop)
236236

237-
grid_power_3_phase_recv = (
238-
grid._power_3_phase.new_receiver() # pylint: disable=protected-access
237+
grid_power_per_phase_recv = (
238+
grid._power_per_phase.new_receiver() # pylint: disable=protected-access
239239
)
240240

241241
for count in range(10):
@@ -250,7 +250,7 @@ async def test_grid_power_3_phase_none_values(mocker: MockerFixture) -> None:
250250
[watts_phases, [None, None, None], [None, 219.8, 220.2]]
251251
)
252252

253-
val = await grid_power_3_phase_recv.receive()
253+
val = await grid_power_per_phase_recv.receive()
254254
assert val is not None
255255
assert val.value_p1 and val.value_p2 and val.value_p3
256256
assert val.value_p1.as_watts() == watts_phases[0]

tests/timeseries/_formula_engine/test_formula_composition.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,12 @@ async def test_3_phase_formulas(self, mocker: MockerFixture) -> None:
428428
grid = microgrid.grid()
429429
stack.push_async_callback(grid.stop)
430430

431-
grid_current_recv = grid.current.new_receiver()
432-
ev_current_recv = ev_pool.current.new_receiver()
431+
grid_current_recv = grid.current_per_phase.new_receiver()
432+
ev_current_recv = ev_pool.current_per_phase.new_receiver()
433433

434-
engine = (grid.current - ev_pool.current).build("net_current")
434+
engine = (grid.current_per_phase - ev_pool.current_per_phase).build(
435+
"net_current"
436+
)
435437
stack.push_async_callback(engine._stop) # pylint: disable=protected-access
436438
net_current_recv = engine.new_receiver()
437439

0 commit comments

Comments
 (0)