|
57 | 57 |
|
58 | 58 |
|
59 | 59 | class FormulaEngine(Generic[QuantityT]): |
60 | | - """[`FormulaEngine`][frequenz.sdk.timeseries.formula_engine.FormulaEngine]s are a |
61 | | - part of the SDK's data pipeline, and provide a way for the SDK to apply formulas on |
62 | | - resampled data streams. |
| 60 | + """An engine to apply formulas on resampled data streams. |
63 | 61 |
|
64 | | - They are used in the SDK to calculate and stream metrics like |
65 | | - [`grid_power`][frequenz.sdk.timeseries.grid.Grid.power], |
66 | | - [`consumer_power`][frequenz.sdk.timeseries.consumer.Consumer.power], |
67 | | - etc., which are building blocks of the |
68 | | - [Frequenz SDK Microgrid Model][frequenz.sdk.microgrid--frequenz-sdk-microgrid-model]. |
| 62 | + Please refer to the [module documentation][frequenz.sdk.timeseries.formula_engine] |
| 63 | + for more information on how formula engines are used throughout the SDK. |
69 | 64 |
|
70 | | - The SDK creates the formulas by analysing the configuration of components in the |
71 | | - {{glossary("Component Graph")}}. |
72 | | -
|
73 | | - ### Streaming Interface |
74 | | -
|
75 | | - The |
76 | | - [`FormulaEngine.new_receiver()`][frequenz.sdk.timeseries.formula_engine.FormulaEngine.new_receiver] |
77 | | - method can be used to create a |
78 | | - [Receiver](https://frequenz-floss.github.io/frequenz-channels-python/latest/reference/frequenz/channels/#frequenz.channels.Receiver) |
79 | | - that streams the [Sample][frequenz.sdk.timeseries.Sample]s calculated by the formula |
80 | | - engine. |
81 | | -
|
82 | | - ```python |
83 | | - from frequenz.sdk import microgrid |
84 | | -
|
85 | | - battery_pool = microgrid.new_battery_pool(priority=5) |
86 | | -
|
87 | | - async for power in battery_pool.power.new_receiver(): |
88 | | - print(f"{power=}") |
89 | | - ``` |
90 | | -
|
91 | | - ### Composition |
| 65 | + Example: Streaming the power of a battery pool. |
| 66 | + ```python |
| 67 | + from frequenz.sdk import microgrid |
92 | 68 |
|
93 | | - Composite `FormulaEngine`s can be built using arithmetic operations on |
94 | | - `FormulaEngine`s streaming the same type of data. |
| 69 | + battery_pool = microgrid.new_battery_pool(priority=5) |
95 | 70 |
|
96 | | - For example, if you're interested in a particular composite metric that can be |
97 | | - calculated by subtracting |
98 | | - [`new_battery_pool().power`][frequenz.sdk.timeseries.battery_pool.BatteryPool.power] and |
99 | | - [`new_ev_charger_pool().power`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool] |
100 | | - from the |
101 | | - [`grid().power`][frequenz.sdk.timeseries.grid.Grid.power], |
102 | | - we can build a `FormulaEngine` that provides a stream of this calculated metric as |
103 | | - follows: |
| 71 | + async for power in battery_pool.power.new_receiver(): |
| 72 | + print(f"{power=}") |
| 73 | + ``` |
104 | 74 |
|
105 | | - ```python |
106 | | - from frequenz.sdk import microgrid |
| 75 | + Example: Composition of formula engines. |
| 76 | + ```python |
| 77 | + from frequenz.sdk import microgrid |
107 | 78 |
|
108 | | - battery_pool = microgrid.new_battery_pool(priority=5) |
109 | | - ev_charger_pool = microgrid.new_ev_charger_pool(priority=5) |
110 | | - grid = microgrid.grid() |
| 79 | + battery_pool = microgrid.new_battery_pool(priority=5) |
| 80 | + ev_charger_pool = microgrid.new_ev_charger_pool(priority=5) |
| 81 | + grid = microgrid.grid() |
111 | 82 |
|
112 | | - # apply operations on formula engines to create a formula engine that would |
113 | | - # apply these operations on the corresponding data streams. |
114 | | - net_power = ( |
115 | | - grid.power - (battery_pool.power + ev_charger_pool.power) |
116 | | - ).build("net_power") |
| 83 | + # apply operations on formula engines to create a formula engine that would |
| 84 | + # apply these operations on the corresponding data streams. |
| 85 | + net_power = ( |
| 86 | + grid.power - (battery_pool.power + ev_charger_pool.power) |
| 87 | + ).build("net_power") |
117 | 88 |
|
118 | | - async for power in net_power.new_receiver(): |
119 | | - print(f"{power=}") |
120 | | - ``` |
121 | | - """ # noqa: D400, D205 |
| 89 | + async for power in net_power.new_receiver(): |
| 90 | + print(f"{power=}") |
| 91 | + ``` |
| 92 | + """ |
122 | 93 |
|
123 | 94 | def __init__( |
124 | 95 | self, |
@@ -392,54 +363,37 @@ def new_receiver( |
392 | 363 |
|
393 | 364 |
|
394 | 365 | class FormulaEngine3Phase(Generic[QuantityT]): |
395 | | - """A |
396 | | - [`FormulaEngine3Phase`][frequenz.sdk.timeseries.formula_engine.FormulaEngine3Phase] |
397 | | - is similar to a |
398 | | - [`FormulaEngine`][frequenz.sdk.timeseries.formula_engine.FormulaEngine], except that |
399 | | - they stream [3-phase samples][frequenz.sdk.timeseries.Sample3Phase]. All the |
400 | | - current formulas (like |
401 | | - [`Grid.current_per_phase`][frequenz.sdk.timeseries.grid.Grid.current_per_phase], |
402 | | - [`EVChargerPool.current_per_phase`][frequenz.sdk.timeseries.ev_charger_pool.EVChargerPool.current_per_phase], |
403 | | - etc.) are implemented as per-phase formulas. |
404 | | -
|
405 | | - ### Streaming Interface |
406 | | -
|
407 | | - The |
408 | | - [`FormulaEngine3Phase.new_receiver()`][frequenz.sdk.timeseries.formula_engine.FormulaEngine3Phase.new_receiver] |
409 | | - method can be used to create a |
410 | | - [Receiver](https://frequenz-floss.github.io/frequenz-channels-python/latest/reference/frequenz/channels/#frequenz.channels.Receiver) |
411 | | - that streams the [Sample3Phase][frequenz.sdk.timeseries.Sample3Phase] values |
412 | | - calculated by the formula engine. |
413 | | -
|
414 | | - ```python |
415 | | - from frequenz.sdk import microgrid |
416 | | -
|
417 | | - ev_charger_pool = microgrid.new_ev_charger_pool(priority=5) |
418 | | -
|
419 | | - async for sample in ev_charger_pool.current_per_phase.new_receiver(): |
420 | | - print(f"Current: {sample}") |
421 | | - ``` |
422 | | -
|
423 | | - ### Composition |
424 | | -
|
425 | | - `FormulaEngine3Phase` instances can be composed together, just like `FormulaEngine` |
426 | | - instances. |
427 | | -
|
428 | | - ```python |
429 | | - from frequenz.sdk import microgrid |
430 | | -
|
431 | | - ev_charger_pool = microgrid.new_ev_charger_pool(priority=5) |
432 | | - grid = microgrid.grid() |
433 | | -
|
434 | | - # Calculate grid consumption current that's not used by the EV chargers |
435 | | - other_current = (grid.current_per_phase - ev_charger_pool.current_per_phase).build( |
436 | | - "other_current" |
437 | | - ) |
438 | | -
|
439 | | - async for sample in other_current.new_receiver(): |
440 | | - print(f"Other current: {sample}") |
441 | | - ``` |
442 | | - """ # noqa: D205, D400 |
| 366 | + """An engine to apply formulas on 3-phase resampled data streams. |
| 367 | +
|
| 368 | + Please refer to the [module documentation][frequenz.sdk.timeseries.formula_engine] |
| 369 | + for more information on how formula engines are used throughout the SDK. |
| 370 | +
|
| 371 | + Example: Streaming the current of an EV charger pool. |
| 372 | + ```python |
| 373 | + from frequenz.sdk import microgrid |
| 374 | +
|
| 375 | + ev_charger_pool = microgrid.new_ev_charger_pool(priority=5) |
| 376 | +
|
| 377 | + async for sample in ev_charger_pool.current_per_phase.new_receiver(): |
| 378 | + print(f"Current: {sample}") |
| 379 | + ``` |
| 380 | +
|
| 381 | + Example: Composition of formula engines. |
| 382 | + ```python |
| 383 | + from frequenz.sdk import microgrid |
| 384 | +
|
| 385 | + ev_charger_pool = microgrid.new_ev_charger_pool(priority=5) |
| 386 | + grid = microgrid.grid() |
| 387 | +
|
| 388 | + # Calculate grid consumption current that's not used by the EV chargers |
| 389 | + other_current = (grid.current_per_phase - ev_charger_pool.current_per_phase).build( |
| 390 | + "other_current" |
| 391 | + ) |
| 392 | +
|
| 393 | + async for sample in other_current.new_receiver(): |
| 394 | + print(f"Other current: {sample}") |
| 395 | + ``` |
| 396 | + """ |
443 | 397 |
|
444 | 398 | def __init__( |
445 | 399 | self, |
|
0 commit comments