Skip to content

Commit a2b4475

Browse files
committed
Update ResampledFormulaBuilder to be a subclass of FormulaBuilder
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 1da3fe4 commit a2b4475

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ._tokenizer import Tokenizer, TokenType
1414

1515

16-
class ResampledFormulaBuilder:
16+
class ResampledFormulaBuilder(FormulaBuilder):
1717
"""Provides a way to build a FormulaEngine from resampled data streams."""
1818

1919
def __init__(
@@ -37,8 +37,8 @@ def __init__(
3737
self._channel_registry = channel_registry
3838
self._resampler_subscription_sender = resampler_subscription_sender
3939
self._namespace = namespace
40-
self._formula = FormulaBuilder()
4140
self._metric_id = metric_id
41+
super().__init__()
4242

4343
async def _get_resampled_receiver(self, component_id: int) -> Receiver[Sample]:
4444
"""Get a receiver with the resampled data for the given component id.
@@ -59,7 +59,7 @@ async def _get_resampled_receiver(self, component_id: int) -> Receiver[Sample]:
5959
return self._channel_registry.new_receiver(request.get_channel_name())
6060

6161
async def push_component_metric(
62-
self, component_id: int, nones_are_zeros: bool
62+
self, component_id: int, *, nones_are_zeros: bool
6363
) -> None:
6464
"""Push a resampled component metric stream to the formula engine.
6565
@@ -69,7 +69,7 @@ async def push_component_metric(
6969
False, the returned value will be a None.
7070
"""
7171
receiver = await self._get_resampled_receiver(component_id)
72-
self._formula.push_metric(f"#{component_id}", receiver, nones_are_zeros)
72+
self.push_metric(f"#{component_id}", receiver, nones_are_zeros)
7373

7474
async def from_string(
7575
self,
@@ -99,10 +99,12 @@ async def from_string(
9999

100100
for token in tokenizer:
101101
if token.type == TokenType.COMPONENT_METRIC:
102-
await self.push_component_metric(int(token.value), nones_are_zeros)
102+
await self.push_component_metric(
103+
int(token.value), nones_are_zeros=nones_are_zeros
104+
)
103105
elif token.type == TokenType.OPER:
104-
self._formula.push_oper(token.value)
106+
self.push_oper(token.value)
105107
else:
106108
raise ValueError(f"Unknown token type: {token}")
107109

108-
return self._formula.build()
110+
return self.build()

0 commit comments

Comments
 (0)