Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 16d19753 authored by Michael Ott's avatar Michael Ott
Browse files

Add aggregate support for virtual sensor queries

parent aa688fee
......@@ -95,6 +95,10 @@ public:
(value == rhs.value);}
#endif
inline bool operator < (const SensorDataStoreReading& rhs) const {
return (value < rhs.value);
}
SensorDataStoreReading();
SensorDataStoreReading(const SensorId& sid, const uint64_t ts, const int64_t value);
virtual ~SensorDataStoreReading();
......
......@@ -26,6 +26,9 @@
//================================================================================
#include <iostream>
#include <functional>
#include <numeric>
#include <algorithm>
#include <dcdb/sensor.h>
#include <dcdb/virtualsensor.h>
......@@ -71,6 +74,34 @@ namespace DCDB {
if (publicSensor.is_virtual) {
VSensor vSen(connection, publicSensor);
vSen.query(result, start, end);
if ((result.size() > 0) && (aggregate != AGGREGATE_NONE)) {
switch(aggregate) {
case AGGREGATE_MIN:
result.begin()->value = std::min_element(result.begin(), result.end())->value;;
break;
case AGGREGATE_MAX:
result.begin()->value = std::max_element(result.begin(), result.end())->value;;
break;
case AGGREGATE_AVG: {
int64_t sum = 0;
for (auto r: result) {
sum+= r.value;
}
result.begin()->value = sum / result.size();
break; }
case AGGREGATE_SUM: {
int64_t sum = 0;
for (auto r: result) {
sum+= r.value;
}
result.begin()->value = sum;
break;}
case AGGREGATE_COUNT:
result.begin()->value = result.size();
break;
}
result.erase(std::next(result.begin()), result.end());
}
}
else {
/* Iterate over the sensorIds within the query interval and output the results in CSV format */
......
Markdown is supported
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