Commit 66b90453 authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: fixing weight computation in Smoothing plugin

parent 3ec9c4ad
...@@ -77,6 +77,11 @@ public: ...@@ -77,6 +77,11 @@ public:
void smoothAndStore(reading_t r) { void smoothAndStore(reading_t r) {
double weight = (double)(r.timestamp - _currTs) / (double)_range; double weight = (double)(r.timestamp - _currTs) / (double)_range;
if (weight > 1.0) {
weight = 1.0;
} else if (weight < 0.0) {
weight = 0.0;
}
_currValue = _last ? (_currValue * (1.0 - weight) + (double)r.value * weight) : (double)r.value; _currValue = _last ? (_currValue * (1.0 - weight) + (double)r.value * weight) : (double)r.value;
_currTs = r.timestamp; _currTs = r.timestamp;
if(r.timestamp - _last > _range) { if(r.timestamp - _last > _range) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment