progressbar.algorithms module

Smoothing algorithms backing SmoothingETA and similar widgets.

Both concrete implementations below seed their running state with the first observed value rather than 0, so an EMA/DEMA-backed ETA doesn’t start out biased toward zero before enough samples have arrived. Both update methods also accept an elapsed argument that they currently ignore – it’s part of the SmoothingAlgorithm contract (for algorithms that might weight by time rather than call count) but neither implementation here uses it.

class progressbar.algorithms.DoubleExponentialMovingAverage(alpha: float = 0.5)[source]

Bases: SmoothingAlgorithm

An EMA of an EMA (DEMA), reducing the lag a single EMA carries.

Reacts to recent changes faster than the plain ExponentialMovingAverage.

Set the smoothing factor.

Parameters:

alpha – Weight given to the newest observation in each of the two nested EMAs (0-1); higher tracks recent values more closely, lower smooths harder.

update(new_value: float, elapsed: timedelta) float[source]

Fold new_value into both nested EMAs.

Parameters:
  • new_value – Latest observed value.

  • elapsed – Ignored, as in ExponentialMovingAverage.update.

Returns:

The DEMA estimate, 2 * ema1 - ema2.

class progressbar.algorithms.ExponentialMovingAverage(alpha: float = 0.5)[source]

Bases: SmoothingAlgorithm

Exponentially weighted moving average (EMA) of the observed values.

More responsive to recent changes than a simple moving average, with less lag.

Set the smoothing factor.

Parameters:

alpha – Weight given to the newest observation on each update() (0-1); higher tracks recent values more closely, lower smooths harder.

update(new_value: float, elapsed: timedelta) float[source]

Fold new_value into the running average.

Parameters:
  • new_value – Latest observed value.

  • elapsed – Accepted for SmoothingAlgorithm compatibility but not used by this implementation – the average is weighted by call count, not by wall-clock time.

Returns:

The updated EMA.

class progressbar.algorithms.SmoothingAlgorithm(**kwargs: Any)[source]

Bases: ABC

Contract for a stateful value smoother fed one sample at a time.

Configure the algorithm.

Parameters:

**kwargs – Algorithm-specific parameters (e.g. alpha).

abstractmethod update(new_value: float, elapsed: timedelta) float[source]

Fold new_value in and return the smoothed value.