pyavg
is a Python library that provides a set of classes for calculating averages from input data using various methods. It supports both basic and specialized smoothing and filtering algorithms.
You can install the library via PyPI:
pip install d3d4.pyavg
The library offers classes for different average calculation methods, including:
- Basic Moving Average (bi_avg.Stat)
- Cumulative Average (cumulative.Stat)
- Exponential Smoothing (exp_smooth.Stat)
- PID Controller-Based Average (pid.Stat)
- Ring Buffer for Averaging (ring_buff.Stat)
- Advanced Smoothing Algorithms (smooth.Stat)
Each class implements a common interface, making it easy to switch between methods as needed.
from pyavg import BiAvgStat
# Create an object for moving average calculation
stat = BiAvgStat(window_size=5)
# Add values
stat.add(10)
stat.add(20)
stat.add(30)
# Get the current average
print(stat.get_average()) # -> 20.0
from pyavg import CumulativeStat
# Create an object for cumulative average calculation
stat = CumulativeStat()
# Add values
stat.add(10)
stat.add(20)
stat.add(30)
# Get the current average
print(stat.get_average()) # -> 20.0
from pyavg import ExpSmoothStat
# Create an object for exponential smoothing
stat = ExpSmoothStat(alpha=0.5)
# Add values
stat.add(10)
stat.add(20)
stat.add(30)
# Get the current smoothed value
print(stat.get_average()) # -> smoothed value
Each class provides the following key methods:
add(value: float):
adds a new value to the calculation.get_average() -> float:
returns the current average.
For details on implementation and additional parameters, refer to the source code or library documentation.
- Python 3.6 or higher.
This project is licensed under the MIT License. See the LICENSE file for more details.
If you’d like to contribute or add a new average calculation method, feel free to submit a Pull Request or reach out through GitHub Issues.