-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWorkoutStats.h
65 lines (47 loc) · 1.16 KB
/
WorkoutStats.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef WORKOUT_STATS_H
#define WORKOUT_STATS_H
#include <float.h>
#include <math.h>
const unsigned int MIN_WEIGHT_THRESHOLD = 1;
const unsigned int MAX_TICK_WITHOUT_VALUE = 2;
class WorkoutStats {
public:
WorkoutStats() : mNumSamples(20), mCurrNumSamples(0), mTotal(0), mMax(0) {}
void reset() {
mCurrNumSamples = 0;
mTotal = 0;
mMax = 0;
}
void addData(float val) {
mLast = abs(val);
if(val < MIN_WEIGHT_THRESHOLD)
return;
// reduce samples total by one sample value
if (mCurrNumSamples >= mNumSamples) {
mTotal = mTotal * (mNumSamples - 1) / mNumSamples;
}
else
mCurrNumSamples++; // increment the current number
mTotal += val;
if (val > mMax)
mMax = val;
}
float mean() const {
if (mCurrNumSamples != 0)
return mTotal / mCurrNumSamples;
else return 0.0f;
}
float maxVal() const {
return mMax;
}
float last() const {
return mLast;
}
protected:
unsigned int mNumSamples;
unsigned int mCurrNumSamples;
float mTotal;
float mMax;
float mLast;
};
#endif