summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-18 14:31:44 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit744b3649c4e37c7696e85f2bf021fbd77ea40f4c (patch)
tree00132b99b1c8ca5717aa7dd5e67f5606ea631360
parentdc023f046636f8abb44dab521a8eb74c9f1f7769 (diff)
Return mathematical value on a period if asked
Change-Id: I40799d054e56b3ae9462963d317d8fb458a21122 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--signal-composer-binding/signal.cpp28
-rw-r--r--signal-composer-binding/signal.hpp4
2 files changed, 25 insertions, 7 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 673295a..f80e63b 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -169,8 +169,10 @@ int Signal::recursionCheck()
double Signal::average(int seconds) const
{
- long long int begin = history_.begin()->first,
- end = begin+(seconds*MICRO);
+ long long int begin = history_.begin()->first;
+ long long int end = !seconds ?
+ begin+(seconds*MICRO) :
+ history_.rbegin()->first;
double total = 0.0;
int nbElt = 0;
@@ -181,7 +183,7 @@ double Signal::average(int seconds) const
if(val.second.hasNum)
{
total += val.second.numVal;
- nbElt++;
+ nbElt++;
}
else
{
@@ -197,11 +199,19 @@ double Signal::average(int seconds) const
return total / nbElt;
}
double Signal::minimum() const
+double Signal::minimum(int seconds) const
{
+ long long int begin = history_.begin()->first;
+ long long int end = !seconds ?
+ begin+(seconds*MICRO) :
+ history_.rbegin()->first;
+
double min = DBL_MAX;
for (auto& v : history_)
{
- if(v.second.hasNum && v.second.numVal < min)
+ if(v.first >= end)
+ {break;}
+ else if(v.second.hasNum && v.second.numVal < min)
{min = v.second.numVal;}
else
{
@@ -217,11 +227,19 @@ double Signal::minimum() const
}
double Signal::maximum() const
+double Signal::maximum(int seconds) const
{
+ long long int begin = history_.begin()->first;
+ long long int end = !seconds ?
+ begin+(seconds*MICRO) :
+ history_.rbegin()->first;
+
double max = 0.0;
for (auto& v : history_)
{
- if(v.second.hasNum && v.second.hasNum > max)
+ if(v.first >= end)
+ {break;}
+ else if(v.second.hasNum && v.second.hasNum > max)
{max = v.second.numVal;}
else
{
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index ba7ed60..2088ffd 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -65,8 +65,8 @@ public:
void attachToSourceSignals(bindingApp& bApp);
double average(int seconds = 0) const;
- double minimum() const;
- double maximum() const;
+ double minimum(int seconds = 0) const;
+ double maximum(int seconds = 0) const;
struct SignalValue last() const;
int recursionCheck();
};