Skip to content

Commit c2e85f2

Browse files
Add consumption and production operator to Formula Engine
Signed-off-by: Matthias Wende <[email protected]>
1 parent 931848e commit c2e85f2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ def min(
198198
"""
199199
return self._higher_order_builder(self, self._create_method).min(other) # type: ignore
200200

201+
def consumption(self) -> _GenericHigherOrderBuilder:
202+
"""
203+
Return a formula builder that applies the consumption operator on `self`.
204+
205+
The consumption operator returns either the identity if the power value is
206+
positive or 0.
207+
"""
208+
return self._higher_order_builder(self, self._create_method).consumption() # type: ignore
209+
210+
def production(self) -> _GenericHigherOrderBuilder:
211+
"""
212+
Return a formula builder that applies the production operator on `self`.
213+
214+
The production operator returns either the absolute value if the power value is
215+
negative or 0.
216+
"""
217+
return self._higher_order_builder(self, self._create_method).production() # type: ignore
218+
201219

202220
class FormulaEngine(
203221
Generic[QuantityT],

0 commit comments

Comments
 (0)