Skip to content

Commit 713e00e

Browse files
committed
Fix missing conversion to QuantityT
The underlying channel is transporting `Quantity` objects, but the `ResampledFormulaBuilder` is returning `QuantityT`, i.e. a specific sub-type of `Quantity` (which has more methods than `Quantity`). If this object is used to access the extra methods, then it will fail. This bug was never triggered because the actual value is just always used as an abstract `Quantity` (only `.base_value` is used), so the conversion is not needed strictly speaking, but we need to use the type system properly, and fix the issue at another level. This will be properly fixed when we make `Quantity` abstract, and we allow using a raw `float` for stuff that can be parametrized with quantities. In this case the resampler will just send raw `float`s, so we will not need to use `Quantity` at all when we are just operating with raw data, and only apply the finally concrete `Quantity` type when the data reaches the end user. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 2f44dbc commit 713e00e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@ def _get_resampled_receiver(
7474

7575
request = ComponentMetricRequest(self._namespace, component_id, metric_id, None)
7676
self._resampler_requests.append(request)
77-
return self._channel_registry.get_or_create(
78-
Sample[QuantityT], request.get_channel_name()
79-
).new_receiver()
77+
resampled_channel = self._channel_registry.get_or_create(
78+
Sample[Quantity], request.get_channel_name()
79+
)
80+
resampled_receiver = resampled_channel.new_receiver().map(
81+
lambda sample: Sample(
82+
sample.timestamp,
83+
self._create_method(sample.value.base_value)
84+
if sample.value is not None
85+
else None,
86+
)
87+
)
88+
return resampled_receiver
8089

8190
async def subscribe(self) -> None:
8291
"""Subscribe to all resampled component metric streams."""

0 commit comments

Comments
 (0)