Commit 0daba507 authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: various bugfixes to signatures plugin

parent c2c2d613
......@@ -81,6 +81,8 @@ void CSOperator::execOnInit() {
if(_streaming && !_units.empty()) {
_trainingUnit = _units[0]->getName();
_actualBlocks = _units[0]->getInputs().size() < _numBlocks ? _units[0]->getInputs().size() : _numBlocks;
if(_actualBlocks!=_numBlocks)
LOG(warning) << "Operator " + _name + ": cannot enforce " + _numBlocks + ", using " + _actualBlocks + " instead.";
} else {
_actualBlocks = _numBlocks;
}
......@@ -105,7 +107,6 @@ void CSOperator::execOnInit() {
_permVector.clear();
}
_trainingData.clear();
_trainingUnit = "";
}
void CSOperator::compute(U_Ptr unit) {
......@@ -131,6 +132,7 @@ void CSOperator::compute(U_Ptr unit) {
_trainingData.clear();
_trainingPending = false;
_trainingReady = -1;
LOG(info) << "Operator " + _name + ": CS training performed.";
if (_modelOut != "" && !dumpToFile(_modelOut))
LOG(error) << "Operator " + _name + ": cannot save CS data to a file!";
}
......@@ -224,13 +226,13 @@ bool CSOperator::readFromFile(std::string &path) {
void CSOperator::accumulateData(std::vector<std::vector<reading_t>>& v, CSSBPtr s, size_t idx, uint64_t nowTs) {
// We query all new data for the sensor since the last one - we want a clean time series
uint64_t endTs = nowTs;
uint64_t startTs = v[idx].empty() ? endTs - _aggregationWindow : v[idx].back().timestamp;
uint64_t startTs = v[idx].empty() ? endTs - _aggregationWindow : v[idx].back().timestamp+100000;
_buffer.clear();
// This query might possibly fail very often, depending on the batching of sensors
if(!_queryEngine.querySensor(s->getName(), startTs, endTs, _buffer, false))
return;
// We add the queried values only if they are actually "new"
if(!_buffer.empty() && _buffer[0].timestamp>v[idx].back().timestamp) {
if(!_buffer.empty() && (v[idx].empty() || _buffer[0].timestamp>v[idx].back().timestamp)) {
v[idx].insert(v[idx].end(), _buffer.begin(), _buffer.end());
// Triggering training if right amount of sensor readings is reached
if(v[idx].size() >= _trainingSamples)
......@@ -444,8 +446,8 @@ int64_t CSOperator::getAvg(std::vector<reading_t> &v) {
int64_t CSOperator::getDer(std::vector<reading_t> &v) {
int64_t der = 0;
for(size_t idx=1; idx<v.size(); idx++) {
der += v[idx].value - v[idx-1].value;
der += (int64_t)v[idx].value - (int64_t)v[idx-1].value;
}
der = v.size()>1 ? der/(v.size()-1) : 0;
der = v.size()>1 ? der/((int64_t)v.size()-1) : 0;
return der;
}
......@@ -69,7 +69,8 @@ public:
void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) {
SensorBase::printConfig(ll, lg, leadingSpaces);
std::string leading(leadingSpaces, ' ');
LOG_VAR(ll) << leading << " Imaginary: " << (_imag ? "true" : "false");
LOG_VAR(ll) << leading << " Block ID: " << _blockID;
LOG_VAR(ll) << leading << " Imaginary: " << (_imag ? "true" : "false");
}
protected:
......
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