Skip to content

API Reference

frequenz.resampling._rust_backend.Resampler(interval: timedelta, resampling_function: ResamplingFunction, *, max_age_in_intervals: int, start: datetime, first_timestamp: bool = True) ¤

The Resampler class is used to resample a time series of samples.

It stores the samples in a buffer and resamples the samples in the buffer when the resample method is called. A resampler can be configured with a resampling function and a resampling interval.

Initializes a new Resampler object.

Parameters:

Name Type Description Default
interval timedelta

The resampling interval.

required
resampling_function ResamplingFunction

The resampling function.

required
max_age_in_intervals int

The maximum age of a sample in intervals.

required
start datetime

The start time of the resampling.

required
first_timestamp bool

Whether the resampled timestamp should be the first timestamp in the buffer or the last timestamp in the buffer. Defaults to True.

True

frequenz.resampling._rust_backend.Resampler.push_sample(*, timestamp: datetime, value: Optional[float]) -> None ¤

Pushes a new sample into the resampler buffer.

Parameters:

Name Type Description Default
timestamp datetime

The timestamp of the sample.

required
value Optional[float]

The value of the sample.

required

frequenz.resampling._rust_backend.Resampler.resample(end: datetime | None = None) -> list[tuple[datetime, Optional[float]]] ¤

Resamples the samples in the buffer until the given end time.

Parameters:

Name Type Description Default
end datetime | None

The end time of the resampling. If None the samples in the buffer will be resampled until the current date/time.

None

Returns:

Type Description
list[tuple[datetime, Optional[float]]]

A list of tuples with the resampled samples.

frequenz.resampling._rust_backend.ResamplingFunction ¤

Bases: Enum

The ResamplingFunction enum represents the different resampling functions that can be used to resample a time series.

frequenz.resampling._rust_backend.ResamplingFunction.Average = 0 class-attribute instance-attribute ¤

Calculates the average of all samples in the time step (ignoring None values)

frequenz.resampling._rust_backend.ResamplingFunction.Coalesce = 7 class-attribute instance-attribute ¤

Returns the first non-None sample in the time step

frequenz.resampling._rust_backend.ResamplingFunction.Count = 5 class-attribute instance-attribute ¤

Counts the number of samples in the time step

frequenz.resampling._rust_backend.ResamplingFunction.First = 6 class-attribute instance-attribute ¤

Returns the first sample in the time step

frequenz.resampling._rust_backend.ResamplingFunction.Last = 4 class-attribute instance-attribute ¤

Returns the last sample in the time step

frequenz.resampling._rust_backend.ResamplingFunction.Max = 2 class-attribute instance-attribute ¤

Calculates the maximum of all samples in the time step

frequenz.resampling._rust_backend.ResamplingFunction.Min = 3 class-attribute instance-attribute ¤

Calculates the minimum of all samples in the time step

frequenz.resampling._rust_backend.ResamplingFunction.Sum = 1 class-attribute instance-attribute ¤

Calculates the sum of all samples in the time step (ignoring None values)

frequenz.resampling._rust_backend.ResamplingFunction.members() -> list[tuple[str, int]] staticmethod ¤

Returns a list of all members of the enum.

Returns:

Type Description
list[tuple[str, int]]

A list of all members of the enum.

frequenz.resampling._rust_backend.ResamplingFunction.values() -> list[int] staticmethod ¤

Returns a list of all values of the enum.

Returns:

Type Description
list[int]

A list of all values of the enum.