geometry changes/fixes/new features
new grid walkers + fixes new test-cases worked on step/and turn detection android offline-data-reader worked on vap-grouping
This commit is contained in:
@@ -60,6 +60,7 @@ public:
|
||||
|
||||
/** add a new user-element and its probability */
|
||||
void add(T element, const double probability) {
|
||||
Assert::isTrue(probability >= 0, "probability must not be negative!");
|
||||
cumProbability += probability;
|
||||
elements.push_back(Entry(element, cumProbability));
|
||||
}
|
||||
|
||||
67
math/MovingAverageTS.h
Normal file
67
math/MovingAverageTS.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef MOVINGAVERAGETS_H
|
||||
#define MOVINGAVERAGETS_H
|
||||
|
||||
#include <vector>
|
||||
#include "../data/Timestamp.h"
|
||||
#include <algorithm>
|
||||
|
||||
template <typename T> class MovingAverageTS {
|
||||
|
||||
private:
|
||||
|
||||
/** timestamp -> value combination */
|
||||
struct Entry {
|
||||
Timestamp ts;
|
||||
T value;
|
||||
Entry(const Timestamp ts, const T& value) : ts(ts), value(value) {;}
|
||||
};
|
||||
|
||||
/** the regional window to use */
|
||||
Timestamp window;
|
||||
|
||||
/** the value history for the window-size */
|
||||
std::vector<Entry> history;
|
||||
|
||||
/** current sum */
|
||||
T sum;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/** ctor with the window-size to use */
|
||||
MovingAverageTS(const Timestamp window, const T zeroElement) : window(window), sum(zeroElement) {
|
||||
|
||||
}
|
||||
|
||||
/** add a new entry */
|
||||
void add(const Timestamp ts, const T& data) {
|
||||
|
||||
// append to history
|
||||
history.push_back(Entry(ts, data));
|
||||
|
||||
// adjust sum
|
||||
sum += data;
|
||||
|
||||
// remove too-old history entries
|
||||
const Timestamp oldest = ts - window;
|
||||
while(history.front().ts < oldest) {
|
||||
|
||||
// adjust sum
|
||||
sum -= history.front().value;
|
||||
|
||||
// remove from history
|
||||
history.erase(history.begin());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** get the current average */
|
||||
T get() const {
|
||||
return sum / history.size();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // MOVINGAVERAGETS_H
|
||||
Reference in New Issue
Block a user