-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowedRollingStatistics.h
More file actions
43 lines (32 loc) · 940 Bytes
/
WindowedRollingStatistics.h
File metadata and controls
43 lines (32 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef WINDOWEDROLLINGSTATISTICS_H
#define WINDOWEDROLLINGSTATISTICS_H
#include "CircularBuffer.h"
#include <cmath>
namespace util {
/**
* For continuously monitoring a value with statistics covering a number of
* recent samples.
*/
class WindowedRollingStatistics {
public:
explicit WindowedRollingStatistics(size_t windowSize);
void AddValue(double newValue);
void Reset();
// Non-const for performance reasons
double Min();
double Max();
size_t WindowSize() const { return values_.Capacity(); }
size_t Count() const { return values_.Size(); }
double Mean() const { return sumOfValues_ / Count(); }
double StandardDeviation() const;
private:
CircularBuffer<double> values_;
double sumOfValues_;
double sumOfValuesSquared_;
double min_;
double max_;
bool updateMinMax_;
void UpdateMinMax();
};
} // end namespace util
#endif // WINDOWEDROLLINGSTATISTICS_H