Skip to content

Commit c942e5f

Browse files
committed
Remove all remaining references to FormulaEngines
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent bf4894f commit c942e5f

File tree

15 files changed

+148
-151
lines changed

15 files changed

+148
-151
lines changed

docs/user-guide/formula-engine.md renamed to docs/user-guide/formulas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Formula Engine
1+
# Formulas
22

3-
::: frequenz.sdk.timeseries.formula_engine
3+
::: frequenz.sdk.timeseries.formulas
44
options:
55
members: None
66
show_bases: false

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
## Streaming component data
154154
155155
All pools have a `power` property, which is a
156-
[`FormulaEngine`][frequenz.sdk.timeseries.formula_engine.FormulaEngine] that can
156+
[`Formula`][frequenz.sdk.timeseries.formulas.Formula] that can
157157
158158
- provide a stream of resampled power values, which correspond to the sum of the
159159
power measured from all the components in the pool together.

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"""An external interface for the BatteryPool.
55
66
Allows for actors interested in operating on the same set of batteries to share
7-
underlying formula engine and metric calculator instances, but without having to specify
8-
their individual priorities with each request.
7+
underlying formula and metric calculator instances, but without having to
8+
specify their individual priorities with each request.
99
"""
1010

1111
import asyncio
@@ -196,23 +196,22 @@ def power(self) -> Formula[Power]:
196196
197197
This formula produces values that are in the Passive Sign Convention (PSC).
198198
199-
If a formula engine to calculate this metric is not already running, it will be
199+
If a formula to calculate this metric is not already running, it will be
200200
started.
201201
202-
A receiver from the formula engine can be obtained by calling the `new_receiver`
202+
A receiver from the formula can be obtained by calling the `new_receiver`
203203
method.
204204
205205
Returns:
206-
A FormulaEngine that will calculate and stream the total power of all
206+
A Formula that will calculate and stream the total power of all
207207
batteries in the pool.
208208
"""
209-
engine = self._pool_ref_store._formula_pool.from_power_formula(
209+
return self._pool_ref_store._formula_pool.from_power_formula(
210210
"battery_pool_power",
211211
connection_manager.get().component_graph.battery_formula(
212212
self._pool_ref_store._batteries
213213
),
214214
)
215-
return engine
216215

217216
@property
218217
def soc(self) -> ReceiverFetcher[Sample[Percentage]]:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BatteryPoolReferenceStore: # pylint: disable=too-many-instance-attributes
2929
"""A class for maintaining the shared state/tasks for a set of pool of batteries.
3030
3131
This includes ownership of
32-
- the formula engine pool and metric calculators.
32+
- the formula pool and metric calculators.
3333
- the tasks for updating the battery status for the metric calculators.
3434
3535
These are independent of the priority of the actors and can be shared between

src/frequenz/sdk/timeseries/consumer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Consumer:
5353
"""
5454

5555
_formula_pool: FormulaPool
56-
"""The formula engine pool to generate consumer metrics."""
56+
"""The formula pool to generate consumer metrics."""
5757

5858
def __init__(
5959
self,
@@ -79,20 +79,20 @@ def power(self) -> Formula[Power]:
7979
8080
This formula produces values that are in the Passive Sign Convention (PSC).
8181
82-
It will start the formula engine to calculate consumer power if it is
82+
It will start the formula to calculate consumer power if it is
8383
not already running.
8484
85-
A receiver from the formula engine can be created using the
85+
A receiver from the formula can be created using the
8686
`new_receiver` method.
8787
8888
Returns:
89-
A FormulaEngine that will calculate and stream consumer power.
89+
A Formula that will calculate and stream consumer power.
9090
"""
9191
return self._formula_pool.from_power_formula(
9292
"consumer_power",
9393
connection_manager.get().component_graph.consumer_formula(),
9494
)
9595

9696
async def stop(self) -> None:
97-
"""Stop all formula engines."""
97+
"""Stop all formulas."""
9898
await self._formula_pool.stop()

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ def current_per_phase(self) -> Formula3Phase[Current]:
119119
120120
This formula produces values that are in the Passive Sign Convention (PSC).
121121
122-
If a formula engine to calculate EV Charger current is not already running, it
122+
If a formula to calculate EV Charger current is not already running, it
123123
will be started.
124124
125-
A receiver from the formula engine can be created using the `new_receiver`
125+
A receiver from the formula can be created using the `new_receiver`
126126
method.
127127
128128
Returns:
129-
A FormulaEngine that will calculate and stream the total current of all EV
129+
A Formula that will calculate and stream the total current of all EV
130130
Chargers.
131131
"""
132132
return self._pool_ref_store.formula_pool.from_current_3_phase_formula(
@@ -142,14 +142,14 @@ def power(self) -> Formula[Power]:
142142
143143
This formula produces values that are in the Passive Sign Convention (PSC).
144144
145-
If a formula engine to calculate EV Charger power is not already running, it
145+
If a formula to calculate EV Charger power is not already running, it
146146
will be started.
147147
148-
A receiver from the formula engine can be created using the `new_receiver`
148+
A receiver from the formula can be created using the `new_receiver`
149149
method.
150150
151151
Returns:
152-
A FormulaEngine that will calculate and stream the total power of all EV
152+
A Formula that will calculate and stream the total power of all EV
153153
Chargers.
154154
"""
155155
return self._pool_ref_store.formula_pool.from_power_formula(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EVChargerPoolReferenceStore:
2525
"""A class for maintaining the shared state/tasks for a set of pool of EV chargers.
2626
2727
This includes ownership of
28-
- the formula engine pool and metric calculators.
28+
- the formula pool and metric calculators.
2929
- the tasks for calculating system bounds for the EV chargers.
3030
3131
These are independent of the priority of the actors and can be shared between

src/frequenz/sdk/timeseries/formulas/_formula_pool.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
"""The component ID for non-existent components in the components graph.
2929
3030
The non-existing component ID is commonly used in scenarios where a formula
31-
engine requires a component ID but there are no available components in the
32-
graph to associate with it. Thus, the non-existing component ID is subscribed
33-
instead so that the formula engine can send `None` or `0` values at the same
34-
frequency as the other streams.
31+
requires a component ID but there are no available components in the graph to
32+
associate with it. Thus, the non-existing component ID is subscribed instead so
33+
that the formula can send `None` or `0` values at the same frequency as the
34+
other streams.
3535
"""
3636

3737

3838
class FormulaPool:
39-
"""Creates and owns formula engines from string formulas, or formula generators.
39+
"""Creates and owns formulas from string formulas.
4040
41-
If an engine already exists with a given name, it is reused instead.
41+
If a formula already exists with a given name, it is reused instead.
4242
"""
4343

4444
def __init__(
@@ -62,13 +62,13 @@ def __init__(
6262
resampler_subscription_sender
6363
)
6464

65-
self._string_engines: dict[str, Formula[Quantity]] = {}
66-
self._power_engines: dict[str, Formula[Power]] = {}
67-
self._reactive_power_engines: dict[str, Formula[ReactivePower]] = {}
68-
self._current_engines: dict[str, Formula3Phase[Current]] = {}
65+
self._string_formulas: dict[str, Formula[Quantity]] = {}
66+
self.power_formulas: dict[str, Formula[Power]] = {}
67+
self._reactive_power_formulas: dict[str, Formula[ReactivePower]] = {}
68+
self._current_formulas: dict[str, Formula3Phase[Current]] = {}
6969

70-
self._power_3_phase_engines: dict[str, Formula3Phase[Power]] = {}
71-
self._current_3_phase_engines: dict[str, Formula3Phase[Current]] = {}
70+
self._power_3_phase_formulas: dict[str, Formula3Phase[Power]] = {}
71+
self._current_3_phase_formulas: dict[str, Formula3Phase[Current]] = {}
7272

7373
def from_string(
7474
self,
@@ -83,18 +83,18 @@ def from_string(
8383
actor.
8484
8585
Returns:
86-
A Formula engine that streams values with the formulas applied.
86+
A Formula that streams values with the formulas applied.
8787
"""
8888
channel_key = formula_str + str(metric.value)
89-
if channel_key in self._string_engines:
90-
return self._string_engines[channel_key]
89+
if channel_key in self._string_formulas:
90+
return self._string_formulas[channel_key]
9191
formula = parse(
9292
name=channel_key,
9393
formula=formula_str,
9494
telemetry_fetcher=self._telemetry_fetcher(metric),
9595
create_method=Quantity,
9696
)
97-
self._string_engines[channel_key] = formula
97+
self._string_formulas[channel_key] = formula
9898
return formula
9999

100100
def from_power_formula(self, channel_key: str, formula_str: str) -> Formula[Power]:
@@ -106,10 +106,10 @@ def from_power_formula(self, channel_key: str, formula_str: str) -> Formula[Powe
106106
formula_str: The formula string.
107107
108108
Returns:
109-
A formula engine that evaluates the given formula.
109+
A formula that evaluates the given formula.
110110
"""
111-
if channel_key in self._power_engines:
112-
return self._power_engines[channel_key]
111+
if channel_key in self.power_formulas:
112+
return self.power_formulas[channel_key]
113113

114114
if formula_str == "0.0":
115115
formula_str = f"coalesce(#{NON_EXISTING_COMPONENT_ID}, 0.0)"
@@ -120,7 +120,7 @@ def from_power_formula(self, channel_key: str, formula_str: str) -> Formula[Powe
120120
telemetry_fetcher=self._telemetry_fetcher(Metric.AC_POWER_ACTIVE),
121121
create_method=Power.from_watts,
122122
)
123-
self._power_engines[channel_key] = formula
123+
self.power_formulas[channel_key] = formula
124124

125125
return formula
126126

@@ -135,10 +135,10 @@ def from_reactive_power_formula(
135135
formula_str: The formula string.
136136
137137
Returns:
138-
A formula engine that evaluates the given formula.
138+
A formula that evaluates the given formula.
139139
"""
140-
if channel_key in self._power_engines:
141-
return self._reactive_power_engines[channel_key]
140+
if channel_key in self.power_formulas:
141+
return self._reactive_power_formulas[channel_key]
142142

143143
if formula_str == "0.0":
144144
formula_str = f"coalesce(#{NON_EXISTING_COMPONENT_ID}, 0.0)"
@@ -149,7 +149,7 @@ def from_reactive_power_formula(
149149
telemetry_fetcher=self._telemetry_fetcher(Metric.AC_POWER_REACTIVE),
150150
create_method=ReactivePower.from_volt_amperes_reactive,
151151
)
152-
self._reactive_power_engines[channel_key] = formula
152+
self._reactive_power_formulas[channel_key] = formula
153153

154154
return formula
155155

@@ -164,10 +164,10 @@ def from_power_3_phase_formula(
164164
formula_str: The formula string.
165165
166166
Returns:
167-
A formula engine that evaluates the given formula.
167+
A formula that evaluates the given formula.
168168
"""
169-
if channel_key in self._power_3_phase_engines:
170-
return self._power_3_phase_engines[channel_key]
169+
if channel_key in self._power_3_phase_formulas:
170+
return self._power_3_phase_formulas[channel_key]
171171

172172
if formula_str == "0.0":
173173
formula_str = f"coalesce(#{NON_EXISTING_COMPONENT_ID}, 0.0)"
@@ -199,7 +199,7 @@ def from_power_3_phase_formula(
199199
create_method=Power.from_watts,
200200
),
201201
)
202-
self._power_3_phase_engines[channel_key] = formula
202+
self._power_3_phase_formulas[channel_key] = formula
203203

204204
return formula
205205

@@ -214,10 +214,10 @@ def from_current_3_phase_formula(
214214
formula_str: The formula string.
215215
216216
Returns:
217-
A formula engine that evaluates the given formula.
217+
A formula that evaluates the given formula.
218218
"""
219-
if channel_key in self._current_3_phase_engines:
220-
return self._current_3_phase_engines[channel_key]
219+
if channel_key in self._current_3_phase_formulas:
220+
return self._current_3_phase_formulas[channel_key]
221221

222222
if formula_str == "0.0":
223223
formula_str = f"coalesce(#{NON_EXISTING_COMPONENT_ID}, 0.0)"
@@ -243,27 +243,27 @@ def from_current_3_phase_formula(
243243
create_method=Current.from_amperes,
244244
),
245245
)
246-
self._current_3_phase_engines[channel_key] = formula
246+
self._current_3_phase_formulas[channel_key] = formula
247247

248248
return formula
249249

250250
async def stop(self) -> None:
251-
"""Stop all formula engines."""
252-
for pf in self._power_engines.values():
251+
"""Stop all formulas."""
252+
for pf in self.power_formulas.values():
253253
await pf.stop()
254-
self._power_engines.clear()
254+
self.power_formulas.clear()
255255

256-
for rpf in self._reactive_power_engines.values():
256+
for rpf in self._reactive_power_formulas.values():
257257
await rpf.stop()
258-
self._reactive_power_engines.clear()
258+
self._reactive_power_formulas.clear()
259259

260-
for p3pf in self._power_3_phase_engines.values():
260+
for p3pf in self._power_3_phase_formulas.values():
261261
await p3pf.stop()
262-
self._power_3_phase_engines.clear()
262+
self._power_3_phase_formulas.clear()
263263

264-
for c3pf in self._current_3_phase_engines.values():
264+
for c3pf in self._current_3_phase_formulas.values():
265265
await c3pf.stop()
266-
self._current_3_phase_engines.clear()
266+
self._current_3_phase_formulas.clear()
267267

268268
def _telemetry_fetcher(self, metric: Metric) -> ResampledStreamFetcher:
269269
"""Create a ResampledStreamFetcher for the given metric.

0 commit comments

Comments
 (0)