Skip to content

Commit 5a29f4d

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 5a29f4d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,13 @@ 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
711+
(for debugging purposes).
710712
711713
Returns:
712714
A new sample generated by calling the resampling function with all
@@ -745,6 +747,11 @@ def resample(self, timestamp: datetime) -> Sample[Quantity]:
745747
# So if we need more performance beyond this point, we probably need to
746748
# resort to some C (or similar) implementation.
747749
relevant_samples = list(itertools.islice(self._buffer, min_index, max_index))
750+
if not relevant_samples:
751+
_logger.warning(
752+
"No relevant samples found for component: %s",
753+
component_name,
754+
)
748755
value = (
749756
conf.resampling_function(relevant_samples, conf, props)
750757
if relevant_samples
@@ -826,4 +833,5 @@ async def resample(self, timestamp: datetime) -> None:
826833
raise recv_exception
827834
raise SourceStoppedError(self._source)
828835

829-
await self._sink(self._helper.resample(timestamp))
836+
# pylint: disable=protected-access
837+
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)