Skip to content

Commit 34a1dd5

Browse files
committed
Pass the whole ResamplerConfig to the ResamplingFunction
Instead of only passing the resampling period, we pass the whole ResamplerConfig so the resampling function has more information on how the resampling is being done to make better decisions. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent eb12a3b commit 34a1dd5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

benchmarks/timeseries/resampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def nop( # pylint: disable=unused-argument
15-
samples: Sequence[Sample], resampling_period_s: float
15+
samples: Sequence[Sample], resampler_config: ResamplerConfig
1616
) -> float:
1717
"""Return 0.0."""
1818
return 0.0

src/frequenz/sdk/timeseries/_resampling.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"""
7272

7373

74-
ResamplingFunction = Callable[[Sequence[Sample], float], float]
74+
ResamplingFunction = Callable[[Sequence[Sample], "ResamplerConfig"], float]
7575
"""Resampling function type.
7676
7777
A resampling function produces a new sample based on a list of pre-existing
@@ -86,23 +86,23 @@
8686
timestamp in the input data).
8787
8888
Args:
89-
input_samples (Sequence[Sample]): the sequence of pre-existing samples.
90-
resampling_period_s (float): the period in seconds (i.e. how ofter a new sample is
91-
produced.
89+
input_samples (Sequence[Sample]): The sequence of pre-existing samples.
90+
resampler_config (ResamplerConfig): The configuration of the resampling
91+
calling this function.
9292
9393
Returns:
9494
new_sample (float): The value of new sample produced after the resampling.
9595
"""
9696

9797

9898
# pylint: disable=unused-argument
99-
def average(samples: Sequence[Sample], resampling_period_s: float) -> float:
99+
def average(samples: Sequence[Sample], resampler_config: ResamplerConfig) -> float:
100100
"""Calculate average of all the provided values.
101101
102102
Args:
103103
samples: The samples to apply the average to. It must be non-empty.
104-
resampling_period_s: The time it passes between resampled data is
105-
produced (in seconds).
104+
resampler_config: The configuration of the resampler calling this
105+
function.
106106
107107
Returns:
108108
The average of all `samples` values.

0 commit comments

Comments
 (0)