aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer-binding')
-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();
};