Skip to content

TimeRolling

A generic wrapper for performing time rolling computations.

This can be wrapped around any object which implements both an update and a revert method. Inputs to update are stored in a queue. Elements of the queue are popped when they are too old.

Parameters

  • obj (river.utils.rolling.Rollable)

    An object that implements both an update method and a rollingmethod.

  • period (datetime.timedelta)

    A duration of time, expressed as a datetime.timedelta.

Examples

For instance, here is how you can compute a rolling average over a period of 3 days:

>>> from river import stats, utils

>>> X = {
...     dt.datetime(2019, 1, 1): 1,
...     dt.datetime(2019, 1, 2): 5,
...     dt.datetime(2019, 1, 3): 9,
...     dt.datetime(2019, 1, 4): 13
... }

>>> rmean = utils.TimeRolling(stats.Mean(), period=dt.timedelta(days=3))
>>> for t, x in X.items():
...     print(rmean.update(x, t=t).get())
1.0
3.0
5.0
9.0

Methods

update