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

Add support for scaling factor

parent 951d4479
......@@ -11,6 +11,7 @@
#include <string>
#include <list>
#include "dcdb/sensordatastore.h"
#include "dcdb/sensorconfig.h"
#include "dcdb/timestamp.h"
namespace DCDB {
......@@ -21,9 +22,19 @@ namespace DCDB {
virtual ~Sensor();
void query(std::list<SensorDataStoreReading>& reading, TimeStamp& start, TimeStamp& end);
double getScalingFactor() const {
return scalingFactor;
}
void setScalingFactor(double scalingFactor) {
this->scalingFactor = scalingFactor;
}
private:
Connection* connection;
std::string publicName;
PublicSensor publicSensor;
SensorConfig* sensorConfig;
double scalingFactor;
};
} /* namespace DCDB */
......
......@@ -59,7 +59,7 @@ public:
std::string name; /**< The public sensor's (public) name. */
bool is_virtual; /**< Denotes whether the sensor is a virtual sensor. */
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; /**< Unused! */
double scaling_factor; /**< Scaling factor for every sensor reading */
std::string unit; /**< Describes the unit of the sensor. See unitconv.h for known units. */
bool integrable; /**< Determines this sensor as being integrable. */
std::string expression; /**< For virtual sensors, this field holds the expression through which the virtual sensor's value is calculated. */
......
......@@ -7,27 +7,19 @@
#include <iostream>
#include <dcdb/sensor.h>
#include <dcdb/sensorconfig.h>
#include <dcdb/virtualsensor.h>
namespace DCDB {
Sensor::Sensor(DCDB::Connection* connection, std::string publicName) {
this->connection = connection;
this->publicName = publicName;
}
Sensor::~Sensor() {
// TODO Auto-generated destructor stub
}
void Sensor::query(std::list<SensorDataStoreReading>& result, TimeStamp& start, TimeStamp& end) {
Sensor::Sensor(Connection* connection, std::string publicName) {
/* Initialize the SensorConfig interface */
DCDB::SensorConfig sensorConfig(connection);
DCDB::SensorDataStore sensorDataStore(connection);
sensorConfig = new SensorConfig(connection);
this->connection = connection;
scalingFactor = 1;
DCDB::PublicSensor publicSensor;
switch (sensorConfig.getPublicSensorByName(publicSensor, publicName.c_str())) {
/* Retrieve publicSensor ifno */
switch (sensorConfig->getPublicSensorByName(publicSensor, publicName.c_str())) {
case DCDB::SC_OK:
break;
case DCDB::SC_INVALIDSESSION:
......@@ -40,15 +32,23 @@ namespace DCDB {
std::cout << "Unknown error." << std::endl;
return;
}
}
Sensor::~Sensor() {
delete sensorConfig;
}
void Sensor::query(std::list<SensorDataStoreReading>& result, TimeStamp& start, TimeStamp& end) {
SensorDataStore sensorDataStore(connection);
if (publicSensor.is_virtual) {
DCDB::VSensor vSen(connection, publicSensor);
VSensor vSen(connection, publicSensor);
vSen.query(result, start, end);
}
else {
/* Expand the pattern into a list of existing sensors in the time range */
std::list<DCDB::SensorId> sensorIds;
switch (sensorConfig.getSensorListForPattern(sensorIds, publicSensor.pattern, start, end)) {
std::list<SensorId> sensorIds;
switch (sensorConfig->getSensorListForPattern(sensorIds, publicSensor.pattern, start, end)) {
case DCDB::SC_OK:
break;
case DCDB::SC_INVALIDPATTERN:
......@@ -60,9 +60,15 @@ namespace DCDB {
}
/* Iterate over the expanded list of sensorIds and output the results in CSV format */
for (std::list<DCDB::SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
sensorDataStore.query(result, *sit, start, end);
}
if (scalingFactor != 1.0 || publicSensor.scaling_factor != 1.0) {
for (std::list<SensorDataStoreReading>::iterator reading = result.begin(); reading != result.end(); reading++) {
reading->value = ((double) reading->value) * scalingFactor * publicSensor.scaling_factor;
}
}
}
}
......
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