Crate running_average[][src]

RunningAverage and RealTimeRunningAverage types allow to calculate running average with specified time window width using constant memory.

The RunningAverage type can be used when processing streams of temporal data while RealTimeRunningAverage can be used when measured events are happening in real time.

For example RealTimeRunningAverage can be used to measure download throughput by inserting how many bytes were transferred.

use running_average::RealTimeRunningAverage;
 
// By default use 8 second window with 16 accumulators
let mut tw = RealTimeRunningAverage::default();
 
// Connect and start downloading
// Got 2KB of data
tw.insert(2000);
 
// Waiting for more data
// Got 1KB of data
tw.insert(1000);
 
// Print average transfer for last 8 seconds
println!("{}", tw.measurement());

Structs

ManualTimeSource

TimeSource that has to be manually progressed forward via ManualTimeSource::time_shift() method.

Measurement

Represent result of the calculation of running average

RealTimeRunningAverage

Represents running average calculation window where shift and measurement are using given time source to obtain value of now instant. It is using specified window width that will consist of given number of accumulator buckets to ensure constant memory usage.

RealTimeSource

TimeSource that uses real time clock via Instant::now().

RunningAverage

Represents running average calculation window. It is using specified window width that will consist of given number of accumulator buckets to ensure constant memory usage.

Traits

TimeInstant

Types implementing this trait can be used as Instant type in TimeSource trait and for RunningAverage

TimeSource

Types implementing this trait can be used as TimeSource for RealTimeRunningAverage.

ToRate

Types implementing this trait can be used to calculate Measurement::rate() from. Note: This is not implemented for u64 as it cannot be converted precisely to f64 - use f64 instead for big numbers Note: Duration can be converted to f64 but will be rounded to fit in it so it is not 100% precise for max Duration