Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MovingStats ¶
type MovingStats interface { // Add adds the given values to the moving stats instance. Add(values ...float64) // Window returns the number of values kept in the moving stats instance. Window() int // SlotsFilled returns whether all slots in the moving stats instance have been filled. SlotsFilled() bool // Values returns the values in the moving stats instance, as stats.Float64Data. Values() stats.Float64Data // Count returns the number of values in the moving stats instance. Count() int // Avg returns the average of the values in the moving stats instance. // If no values have been added or any other error occurs, 0.0 is returned. Avg() float64 // Median returns the median of the values in the moving stats instance. // If no values have been added or any other error occurs, 0.0 is returned. Median() float64 // Min returns the minimum of the values in the moving stats instance. // If no values have been added or any other error occurs, 0.0 is returned. Min() float64 // Max returns the maximum of the values in the moving stats instance. // If no values have been added or any other error occurs, 0.0 is returned. Max() float64 // UnsafeDoStat runs the given function on the values in the moving stats instance. // If the function returns an error, that error is returned. // Functions passed to UnsafeDoStat must not modify the values slice or call Add(). This will result in undefined behavior. UnsafeDoStat(func(stats.Float64Data) (float64, error)) (float64, error) // UnsafeDo runs the given function on the values in the moving stats instance. // If the function returns an error, that error is returned. // Functions passed to UnsafeDo must not modify the values slice or call Add(). This will result in undefined behavior. UnsafeDo(func(stats.Float64Data) error) error }
MovingStats holds the most recently added N values (N = Options.Window) and provides a bridge from those data to the github.com/montanaflynn/stats Float64Data type for statistical calculations.
Avg() and Median() are the only statistical methods provided by this package; they wrap the relevant functions from github.com/montanaflynn/stats but return 0.0 if an error occurs.
(Avg() is the (non-geometric) mean of the values, and Median() is the median.)
func New ¶
func New(opts Options) MovingStats
New returns a new MovingStats instance with the given options.
func NewConcurrent ¶
func NewConcurrent(opts Options) MovingStats
NewConcurrent returns a new concurrency-safe MovingStats instance with the given options.
type Options ¶
type Options struct { // Whether to ignore NaN values when adding values to the moving stats instance. IgnoreNanValues bool // Whether to ignore Inf values when adding values to the moving stats instance. IgnoreInfValues bool // The number of values to keep in the moving stats instance. Window int }
Options configures a new movingStats instance.