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

Commit 46111551 authored by Michael Ott's avatar Michael Ott
Browse files

Introduce delta flag in sensor meta data

parent d099caad
......@@ -59,7 +59,8 @@ public:
SCALE_SET = 128,
TTL_SET = 256,
INTERVAL_SET = 512,
OPERATIONS_SET = 1024
OPERATIONS_SET = 1024,
DELTA_SET = 2048
} MetadataMask;
SensorMetadata() :
......@@ -74,6 +75,7 @@ public:
ttl(0),
interval(0),
operations(),
delta(false),
setMask(0) {}
SensorMetadata(const SensorMetadata& other) {
......@@ -90,6 +92,7 @@ public:
ttl = other.ttl;
interval = other.interval;
operations = other.operations;
delta = other.delta;
}
SensorMetadata& operator=(const SensorMetadata& other) {
......@@ -105,6 +108,7 @@ public:
ttl = other.ttl;
interval = other.interval;
operations = other.operations;
delta = other.delta;
return *this;
}
......@@ -170,6 +174,9 @@ public:
setOperations(_parseOperations(buf, ','));
oldPos = payload.length();
break;
case 11 :
setDelta(to_bool(buf));
break;
}
}
fieldCtr++;
......@@ -211,6 +218,8 @@ public:
setTTL(stoull(val.second.data()) * 1000000);
} else if (boost::iequals(val.first, "operations")) {
setOperations(val.second.data());
} else if (boost::iequals(val.first, "delta")) {
setDelta(to_bool(val.second.data()));
}
}
}
......@@ -252,6 +261,7 @@ public:
buf += (setMask & INTERVAL_SET) ? to_string(interval / 1000000) + "," : ",";
buf += (setMask & TTL_SET) ? to_string(ttl / 1000000) + "," : ",";
buf += (setMask & OPERATIONS_SET) ? _dumpOperations(',') + "," : ",";
buf += (setMask & DELTA_SET) ? bool_to_str(delta) + "," : ",";
return buf;
}
......@@ -281,6 +291,7 @@ public:
const uint64_t* getInterval() const { return (setMask & INTERVAL_SET) ? &interval : nullptr; }
const set<string>* getOperations() const { return (setMask & OPERATIONS_SET) ? &operations : nullptr; }
const string getOperationsString() const { return (setMask & OPERATIONS_SET) ? _dumpOperations() : ""; }
const bool* getDelta() const { return (setMask & DELTA_SET) ? &delta : nullptr; }
void setIsOperation(bool o) { isOperation = o; setMask = setMask | IS_OPERATION_SET; }
void setIsVirtual(bool v) { isVirtual = v; setMask = setMask | IS_VIRTUAL_SET; }
......@@ -294,6 +305,7 @@ public:
void setInterval(uint64_t i) { interval = i; setMask = setMask | INTERVAL_SET; }
void setOperations(const string& o) { setOperations(_parseOperations(o)); }
void clearOperations() { operations.clear(); setMask = setMask & ~OPERATIONS_SET; }
void setDelta(bool d) { delta = d; setMask = setMask | DELTA_SET; }
// Merges a set of operations with the local one
void setOperations(const set<string>& o) {
......@@ -375,6 +387,9 @@ protected:
config.push_back(boost::property_tree::ptree::value_type("ttl", boost::property_tree::ptree(to_string(ttl / 1000000))));
if(setMask & OPERATIONS_SET)
config.push_back(boost::property_tree::ptree::value_type("operations", boost::property_tree::ptree(_dumpOperations())));
if(setMask & DELTA_SET)
config.push_back(boost::property_tree::ptree::value_type("delta", boost::property_tree::ptree(bool_to_str(delta))));
}
// Protected class members
......@@ -389,6 +404,7 @@ protected:
uint64_t ttl;
uint64_t interval;
set<string> operations;
bool delta;
uint64_t setMask;
};
......
......@@ -129,6 +129,7 @@ public:
const std::string& getMqtt() const { return _mqtt; }
bool getSkipConstVal() const { return _skipConstVal; }
bool getPublish() const { return _publish; }
bool getDelta() const { return _delta; }
unsigned getCacheInterval() const { return _cacheInterval; }
int getSubsampling() const { return _subsamplingFactor; }
const CacheEntry* const getCache() const { return _cache.get(); }
......
......@@ -463,6 +463,7 @@ class ConfiguratorTemplate : public ConfiguratorInterface {
sm->setIsVirtual(false);
if(!sm->getInterval())
sm->setInterval((uint64_t)g->getInterval() * 1000000);
sm->setDelta(s->getDelta());
}
}
g->releaseSensors();
......
......@@ -480,6 +480,8 @@ class ConfiguratorTemplateEntity : public ConfiguratorTemplate<SBase, SGroup> {
sm->setIsVirtual(false);
if (!sm->getInterval())
sm->setInterval((uint64_t)g->getInterval() * 1000000);
sm->setDelta(s->getDelta());
}
}
g->releaseSensors();
......
......@@ -72,7 +72,7 @@ public:
std::string pattern; /**< For non-virtual sensors, this holds a pattern describing the (internal) sensor IDs to which this public sensor matches. */
double scaling_factor; /**< Scaling factor for every sensor reading */
std::string unit; /**< Describes the unit of the sensor. See unitconv.h for known units. */
uint64_t sensor_mask; /**< Determines the properties of the sensor. Currently defined are: integrable, monotonic. */
uint64_t sensor_mask; /**< Determines the properties of the sensor. Currently defined are: integrable, monotonic, delta. */
std::string expression; /**< For virtual sensors, this field holds the expression through which the virtual sensor's value is calculated. */
std::string v_sensorid; /**< For virtual sensors, this field holds a SensorID used for storing cached values in the database. (FIXME: Cache to be implemented) */
uint64_t t_zero; /**< For virtual sensors, this field holds the first point in time at which the sensor carries a value. */
......@@ -123,6 +123,7 @@ typedef enum {
#define INTEGRABLE 1
#define MONOTONIC 2
#define DELTA 4
/**
* This class holds all functions to create/delete/modify the configuration of (virtual and non-virtual) public sensors in DCDB.
......
......@@ -101,6 +101,8 @@ PublicSensor PublicSensor::metadataToPublicSensor(const SensorMetadata& sm) {
sensorMask = sensorMask | INTEGRABLE;
if(sm.getMonotonic() && *sm.getMonotonic())
sensorMask = sensorMask | MONOTONIC;
if(sm.getDelta() && *sm.getDelta())
sensorMask = sensorMask | DELTA;
ps.sensor_mask = sensorMask;
return ps;
}
......@@ -122,6 +124,7 @@ SensorMetadata PublicSensor::publicSensorToMetadata(const PublicSensor& ps) {
sm.setOperations(ps.operations);
sm.setIntegrable(ps.sensor_mask & INTEGRABLE);
sm.setMonotonic(ps.sensor_mask & MONOTONIC);
sm.setDelta(ps.sensor_mask & DELTA);
return sm;
}
......@@ -658,7 +661,7 @@ SCError SensorConfigImpl::publishSensor(const SensorMetadata& sensor)
queryBuf += ", unit";
valuesBuf += ", ?";
}
if(sensor.getIntegrable() || sensor.getMonotonic()) {
if(sensor.getIntegrable() || sensor.getMonotonic() || sensor.getDelta()) {
queryBuf += ", sensor_mask";
valuesBuf += ", ?";
}
......@@ -699,12 +702,14 @@ SCError SensorConfigImpl::publishSensor(const SensorMetadata& sensor)
cass_statement_bind_int64_by_name(statement, "interval", *sensor.getInterval());
if(sensor.getTTL())
cass_statement_bind_int64_by_name(statement, "ttl", *sensor.getTTL());
if(sensor.getIntegrable() || sensor.getMonotonic()) {
if(sensor.getIntegrable() || sensor.getMonotonic() || sensor.getDelta()) {
uint64_t sensorMask = 0;
if(sensor.getIntegrable())
sensorMask = sensorMask | INTEGRABLE;
if(sensor.getMonotonic())
sensorMask = sensorMask | MONOTONIC;
if(sensor.getDelta())
sensorMask = sensorMask | DELTA;
cass_statement_bind_int64_by_name(statement, "sensor_mask", sensorMask);
}
......
......@@ -61,9 +61,9 @@ void SensorAction::printHelp(int argc, char* argv[])
std::cout << " SHOW <public name> - Show details for a given sensor." << std::endl;
std::cout << " SCALINGFACTOR <public name> <fac> - Set scaling factor to <fac>." << std::endl;
std::cout << " UNIT <public name> <unit> - Set unit to <unit>." << std::endl;
std::cout << " SENSORPROPERTY <public name> <sensor property>,<sensor property>,..." << std::endl;
std::cout << " - Set sensor properties. Currently defined are: " << std::endl;
std::cout << " 'integrable' and 'monotonic'." << std::endl;
std::cout << " SENSORPROPERTY <public name> [<sensor property>,<sensor property>,...]" << std::endl;
std::cout << " - Get/Set sensor properties. Valid properties: " << std::endl;
std::cout << " integrable, monotonic, delta" << std::endl;
std::cout << " EXPRESSION <public name> <expr> - Change expression of virt sensor." << std::endl;
std::cout << " TZERO <public name> <t0> - Change t0 of virt sensor." << std::endl;
std::cout << " INTERVAL <public name> <inter> - Change interval of a sensor." << std::endl;
......@@ -143,12 +143,17 @@ int SensorAction::executeCommand(int argc, char* argv[], int argvidx, const char
doUnit(argv[argvidx+1], argv[argvidx+2]);
}
else if (strcasecmp(argv[argvidx], "SENSORPROPERTY") == 0) {
/* SENSORPROPERTY needs two more parameters */
if (argvidx+2 >= argc) {
std::cout << "SENSORPROPERTY needs two more parameters!" << std::endl;
/* SENSORPROPERTY needs at least one parameter */
if (argvidx+1 >= argc) {
std::cout << "SENSORPROPERTY needs at least one more parameter!" << std::endl;
goto executeCommandError;
}
doSensorProperty(argv[argvidx+1], argv[argvidx+2]);
char* cmd = nullptr;
if (argvidx+2 >= argc) {
cmd = argv[argvidx+2];
}
doSensorProperty(argv[argvidx+1], cmd);
}
else if (strcasecmp(argv[argvidx], "EXPRESSION") == 0) {
/* EXPRESSION needs two more parameters */
......@@ -461,21 +466,39 @@ void SensorAction::doSensorProperty(const char* publicName, const char* cmd)
{
uint64_t mask = publicSensor.sensor_mask;
if(strcasestr(cmd,"integrable") && (mask & INTEGRABLE) != INTEGRABLE)
if (cmd != nullptr) {
if(strcasestr(cmd,"integrable")) {
if ((mask & INTEGRABLE) != INTEGRABLE) {
mask = mask | INTEGRABLE;
if(strcasestr(cmd, "monotonic") && (mask & MONOTONIC) != MONOTONIC)
}
} else if(strcasestr(cmd, "monotonic")) {
if ((mask & MONOTONIC) != MONOTONIC) {
mask = mask | MONOTONIC;
if(!strcasestr(cmd, "integrable") && !strcasestr(cmd, "monotonic")) {
}
} else if(strcasestr(cmd, "delta")) {
if ((mask & DELTA) != DELTA) {
mask = mask | DELTA;
}
} else {
std::cout << "Unknown option: " << cmd << std::endl;
std::cout << "Please specify a sensor property: INTEGRABLE and/or MONOTONIC" << std::endl;
std::cout << "Valid sensor properties are: INTEGRABLE, MONOTONIC, DELTA" << std::endl;
}
if(mask != publicSensor.sensor_mask) {
sensorConfig.setSensorMask(publicName, mask);
sensorConfig.setPublishedSensorsWritetime(getTimestamp());
}
}
std::cout << publicSensor.name << ":";
if ((mask & INTEGRABLE) == INTEGRABLE) {
std::cout << " integrable";
} else if ((mask & MONOTONIC) == MONOTONIC) {
std::cout << " monotonic";
} else if ((mask & DELTA) == DELTA) {
std::cout << " delta";
}
std::cout << std::endl;
break;
}
......
......@@ -222,7 +222,10 @@ void DCDBQuery::genOutput(std::list<DCDB::SensorDataStoreReading> &results, quer
}
break;
case DCDB_OP_DERIVATIVE: {
int64_t prevValue = prevReading;
int64_t prevValue = 0;
if ((it->first.sensor_mask & DELTA) != DELTA) {
prevValue = prevReading;
}
if (scaleAndConvert(value, baseScalingFactor, it->second.scalingFactor, baseUnit, it->second.unit) && scaleAndConvert(prevValue, baseScalingFactor, it->second.scalingFactor, baseUnit, it->second.unit)) {
if( (prevT > (uint64_t) 0) && DCDB::derivative(value, prevValue, ts.getRaw(), prevT.getRaw(), &result, unit) == DCDB::DCDB_OP_SUCCESS) {
resultOk = true;
......
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