Skip to content

Commit 1af5c63

Browse files
committed
Update LogicalMeter to accept a nones_are_zeros parameter
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 467b901 commit 1af5c63

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/frequenz/sdk/timeseries/logical_meter/_logical_meter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def __init__(
5252
self._tasks: List[asyncio.Task[None]] = []
5353

5454
async def _engine_from_formula_string(
55-
self, formula: str, metric_id: ComponentMetricId
55+
self, formula: str, metric_id: ComponentMetricId, nones_are_zeros: bool
5656
) -> FormulaEngine:
5757
builder = FormulaBuilder(
5858
self._namespace,
5959
self._channel_registry,
6060
self._resampler_subscription_sender,
6161
metric_id,
6262
)
63-
return await builder.from_string(formula, False)
63+
return await builder.from_string(formula, nones_are_zeros)
6464

6565
async def _run_formula(
6666
self, formula: FormulaEngine, sender: Sender[Sample]
@@ -78,13 +78,16 @@ async def start_formula(
7878
self,
7979
formula: str,
8080
component_metric_id: ComponentMetricId,
81+
nones_are_zeros: bool = False,
8182
) -> Receiver[Sample]:
8283
"""Start execution of the given formula name.
8384
8485
Args:
8586
formula: formula to execute.
8687
component_metric_id: The metric ID to use when fetching receivers from the
8788
resampling actor.
89+
nones_are_zeros: Whether to treat None values from the stream as 0s. If
90+
False, the returned value will be a None.
8891
8992
Returns:
9093
A Receiver that streams values with the formulas applied.
@@ -94,8 +97,7 @@ async def start_formula(
9497
return self._output_channels[channel_key].new_receiver()
9598

9699
formula_engine = await self._engine_from_formula_string(
97-
formula,
98-
component_metric_id,
100+
formula, component_metric_id, nones_are_zeros
99101
)
100102
out_chan = Broadcast[Sample](channel_key)
101103
self._output_channels[channel_key] = out_chan

0 commit comments

Comments
 (0)