Commit d070d6b0 authored by Axel Auweter's avatar Axel Auweter
Browse files

Do not return garbage when a virtual sensor cannot be evaluated at a given time.

parent 4e4f834d
......@@ -30,6 +30,19 @@
namespace DCDB {
namespace VirtualSensor {
/**
* @brief Exception class for errors during Physical Sensor Evaluation
*
* Exceptions of this type are thrown whenever the the evaluation of
* a physical sensor is impossible due to data being out of range.
* What() returns a human readable error string.
*/
class PhysicalSensorEvaluatorException : public std::runtime_error
{
public:
PhysicalSensorEvaluatorException(const std::string& msg) : runtime_error(msg) {}
};
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
......
......@@ -11,6 +11,7 @@
#include "dcdbglobals.h"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstdlib>
......@@ -219,7 +220,14 @@ int64_t VSensorExpressionImpl::physicalSensorInterpolator(Connection* connection
readingBefore.value = (int64_t)value;
}
else {
std::cerr << "Cannot find reading for sensor " << sensor.name << " prior to time " << t.getString() << "(" << t.getRaw() << ")" << std::endl;
std::stringstream msg;
msg << "Cannot find reading for sensor " << sensor.name << " prior to time " << t.getString() << "(" << t.getRaw() << ")" << std::endl;
cass_iterator_free(rows);
cass_result_free(cresult);
cass_statement_free(statement);
cass_future_free(future);
cass_prepared_free(prepared);
throw(PhysicalSensorEvaluatorException(msg.str()));
}
cass_iterator_free(rows);
cass_result_free(cresult);
......@@ -265,7 +273,14 @@ int64_t VSensorExpressionImpl::physicalSensorInterpolator(Connection* connection
readingAfter.value = (int64_t)value;
}
else {
std::cerr << "Cannot find reading for sensor " << sensor.name << " following time " << t.getString() << "(" << t.getRaw() << ")" << std::endl;
std::stringstream msg;
msg << "Cannot find reading for sensor " << sensor.name << " following time " << t.getString() << "(" << t.getRaw() << ")" << std::endl;
cass_iterator_free(rows);
cass_result_free(cresult);
cass_statement_free(statement);
cass_future_free(future);
cass_prepared_free(prepared);
throw(PhysicalSensorEvaluatorException(msg.str()));
}
cass_iterator_free(rows);
cass_result_free(cresult);
......@@ -455,12 +470,17 @@ VSError VSensorImpl::query(std::list<SensorDataStoreReading>& result, TimeStamp&
i <= (tzero.getRaw() + (n_end * frequency));
i += frequency)
{
int64_t eval = expression->evaluateAt(i);
TimeStamp t(i);
SensorDataStoreReading r;
r.timeStamp = t;
r.value = eval;
result.push_back(r);
try {
int64_t eval = expression->evaluateAt(i);
TimeStamp t(i);
SensorDataStoreReading r;
r.timeStamp = t;
r.value = eval;
result.push_back(r);
}
catch (PhysicalSensorEvaluatorException& e) {
std::cerr << e.what();
}
}
return VS_OK;
......
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