Skip to content

Commit 890b693

Browse files
committed
Improve docs for the FormulaEngine3Phase class
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 46704a4 commit 890b693

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,52 @@ class FormulaEngine3Phase(
413413
QuantityT,
414414
]
415415
):
416-
"""
417-
The FormulaEngine evaluates formulas and streams the results.
416+
"""A
417+
[`FormulaEngine3Phase`][frequenz.sdk.timeseries.formula_engine.FormulaEngine3Phase]
418+
is similar to a
419+
[`FormulaEngine`][frequenz.sdk.timeseries.formula_engine.FormulaEngine], except that
420+
they stream [3-phase samples][frequenz.sdk.timeseries.Sample3Phase]. All the
421+
current formulas (like
422+
[`LogicalMeter.grid_current`][frequenz.sdk.timeseries.logical_meter.LogicalMeter.grid_current],
423+
[`EVChargerPool.current`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.current],
424+
etc.) are implemented as 3-phase formulas.
418425
419-
Use the `FormulaBuilder` to create `FormulaEngine` instances.
420-
"""
426+
### Streaming Interface
427+
428+
The
429+
[`FormulaEngine3Phase.new_receiver()`][frequenz.sdk.timeseries.formula_engine.FormulaEngine3Phase.new_receiver]
430+
method can be used to create a
431+
[Receiver](https://frequenz-floss.github.io/frequenz-channels-python/latest/reference/frequenz/channels/#frequenz.channels.Receiver)
432+
that streams the [Sample3Phase][frequenz.sdk.timeseries.Sample3Phase] values
433+
calculated by the formula engine.
434+
435+
```python
436+
from frequenz.sdk import microgrid
437+
438+
ev_charger_pool = microgrid.ev_charger_pool()
439+
440+
async for sample in ev_charger_pool.current.new_receiver():
441+
print(f"Current: {sample}")
442+
```
443+
444+
### Composition
445+
446+
`FormulaEngine3Phase` instances can be composed together, just like `FormulaEngine`
447+
instances.
448+
449+
```python
450+
from frequenz.sdk import microgrid
451+
452+
logical_meter = microgrid.logical_meter()
453+
ev_charger_pool = microgrid.ev_charger_pool()
454+
455+
# Calculate grid consumption current that's not used by the ev chargers
456+
other_current = (logical_meter.grid_current - ev_charger_pool.current).build("other_current")
457+
458+
async for sample in other_current.new_receiver():
459+
print(f"Other current: {sample}")
460+
```
461+
""" # noqa: D205, D400
421462

422463
def __init__(
423464
self,

0 commit comments

Comments
 (0)