Commit 86475ea5 authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: changes to QueryEngine

- When the start and end timestamps of a query are equal, it is enforced
that only one sensor value will be retrieved
parent 0c7355bc
......@@ -164,26 +164,36 @@ public:
uint64_t cacheSize = _cache.size()>1 ? _cache.size()-1 : 1;
uint64_t staleThreshold = (_maxHistory / cacheSize) * (uint64_t)_batchSize * 4;
uint64_t now = getTimestamp();
//Converting relative offsets to absolute timestamp for staleness checking
uint64_t startTsInt = rel ? now - startTs : startTs;
uint64_t endTsInt = rel ? now - endTs : endTs;
//Getting the cache indexes to access sensor data
int64_t startIdx = rel ? getOffset(startTs) : searchTimestamp(startTs, true);
int64_t endIdx = rel ? getOffset(endTs) : searchTimestamp(endTs, false);
//Managing invalid time offsets
if(startIdx < 0 || endIdx < 0)
return buffer;
//Managing obsolete data
if(tsAbs(startTsInt, _cache[startIdx].timestamp) > staleThreshold || tsAbs(endTsInt, _cache[endIdx].timestamp) > staleThreshold)
return buffer;
if(startIdx <= endIdx)
buffer->insert(buffer->end(), _cache.begin() + startIdx, _cache.begin() + endIdx + 1);
if(startTs!=endTs) {
//Converting relative offsets to absolute timestamp for staleness checking
uint64_t startTsInt = rel ? now - startTs : startTs;
uint64_t endTsInt = rel ? now - endTs : endTs;
//Getting the cache indexes to access sensor data
int64_t startIdx = rel ? getOffset(startTs) : searchTimestamp(startTs, true);
int64_t endIdx = rel ? getOffset(endTs) : searchTimestamp(endTs, false);
//Managing invalid time offsets
if(startIdx < 0 || endIdx < 0)
return buffer;
//Managing obsolete data
if(tsAbs(startTsInt, _cache[startIdx].timestamp) > staleThreshold || tsAbs(endTsInt, _cache[endIdx].timestamp) > staleThreshold)
return buffer;
if(startIdx <= endIdx)
buffer->insert(buffer->end(), _cache.begin() + startIdx, _cache.begin() + endIdx + 1);
else {
buffer->insert(buffer->end(), _cache.begin() + startIdx, _cache.end());
buffer->insert(buffer->end(), _cache.begin(), _cache.begin() + endIdx + 1);
}
}
else {
buffer->insert(buffer->end(), _cache.begin() + startIdx, _cache.end());
buffer->insert(buffer->end(), _cache.begin(), _cache.begin() + endIdx + 1);
// If start and end timestamps are equal we retrieve only one value
uint64_t tsInt = rel ? now - startTs : startTs;
int64_t intIdx = rel ? getOffset(startTs) : searchTimestamp(startTs, false);
if(intIdx < 0 || tsAbs(tsInt, _cache[intIdx].timestamp) > staleThreshold)
return buffer;
buffer->push_back(_cache[intIdx]);
}
return buffer;
}
......
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