Skip to content

Commit 29c1732

Browse files
Log when no relevant samples are found for resampling
These additional logs will help in understanding why certain microgrid components, such as meters, fail to provide relevant samples for resampling. Signed-off-by: Daniel Zullo <[email protected]>
1 parent 6637d7f commit 29c1732

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

benchmarks/timeseries/resampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _do_work() -> None:
4646
for _n_sample in range(samples):
4747
now = now + timedelta(seconds=1 / samples)
4848
helper.add_sample(Sample(now, Quantity(0.0)))
49-
helper.resample(now)
49+
helper.resample(now, helper._name) # pylint: disable=protected-access
5050

5151
print(timeit(_do_work, number=5))
5252

src/frequenz/sdk/timeseries/_resampling.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,12 @@ def _update_buffer_len(self) -> bool:
702702

703703
return True
704704

705-
def resample(self, timestamp: datetime) -> Sample[Quantity]:
705+
def resample(self, timestamp: datetime, component_name: str) -> Sample[Quantity]:
706706
"""Generate a new sample based on all the current *relevant* samples.
707707
708708
Args:
709709
timestamp: The timestamp to be used to calculate the new sample.
710+
component_name: The name of the component that is being resampled.
710711
711712
Returns:
712713
A new sample generated by calling the resampling function with all
@@ -745,6 +746,11 @@ def resample(self, timestamp: datetime) -> Sample[Quantity]:
745746
# So if we need more performance beyond this point, we probably need to
746747
# resort to some C (or similar) implementation.
747748
relevant_samples = list(itertools.islice(self._buffer, min_index, max_index))
749+
if not relevant_samples:
750+
_logger.warning(
751+
"No relevant samples found for component: %s",
752+
component_name,
753+
)
748754
value = (
749755
conf.resampling_function(relevant_samples, conf, props)
750756
if relevant_samples
@@ -826,4 +832,5 @@ async def resample(self, timestamp: datetime) -> None:
826832
raise recv_exception
827833
raise SourceStoppedError(self._source)
828834

829-
await self._sink(self._helper.resample(timestamp))
835+
# pylint: disable=protected-access
836+
await self._sink(self._helper.resample(timestamp, self._helper._name))

tests/timeseries/test_resampling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ async def test_helper_buffer_too_big(
160160
helper.add_sample(sample)
161161
await _advance_time(fake_time, 1)
162162

163-
_ = helper.resample(datetime.now(timezone.utc))
163+
_ = helper.resample(
164+
datetime.now(timezone.utc), helper._name # pylint: disable=protected-access
165+
)
164166
# Ignore errors produced by wrongly finalized gRPC server in unrelated tests
165167
assert (
166168
"frequenz.sdk.timeseries._resampling",

0 commit comments

Comments
 (0)