Commit 1828a11b authored by Alessio Netti's avatar Alessio Netti
Browse files

DCDBQuery: queries on raw MQTT topics

- Now it is possible to perform queries on raw topics without doing
a lookup on the publishedsensors table, by using the -d option
parent 2564afba
......@@ -59,7 +59,7 @@ bool AnalyticsController::initialize(Configuration& settings, const string& conf
_dcdbCfg->getPublicSensorsVerbose(publicSensors);
for (const auto &s : publicSensors)
if (!s.is_virtual) {
topics.push_back(s.name);
topics.push_back(s.pattern);
}
publicSensors.clear();
......
......@@ -43,7 +43,7 @@ void usage(void)
if (isatty(fileno(stdin))) {
/* 0---------1---------2---------3---------4---------5---------6---------7--------- */
std::cout << "Usage:" << std::endl
<< "dcdbquery [-h <hostname>] [-r] [-l] <Sensor 1> [<Sensor 2> ...] <Start> <End>" << std::endl
<< "dcdbquery [-h <hostname>] [-d] [-r] [-l] <Sensor 1> [<Sensor 2> ...] <Start> <End>" << std::endl
<< "where" << std::endl
<< " <hostname> - the name of the DB server" << std::endl
<< " <Sensor n> - a public sensor name" << std::endl
......@@ -52,6 +52,8 @@ void usage(void)
<< "Return the readings for the sensors in the interval from <Start> to <End>." << std::endl
<< "<Start> and <End> times should be supplied as 'yyyy-mm-dd hh:mm:ss' or unix" << std::endl
<< "timestamps." << std::endl
<< "When the -d option is specified, specified sensor names are used to perform" << std::endl
<< "a direct raw query without looking up public sensor names." << std::endl
<< "When the -r option is specified, timestamps will be reported in internal (raw)" << std::endl
<< "format (nanoseconds since epoch) insted of ISO human readable form." << std::endl
<< "When the -l option is specified, times for <Start>, <End>, and in the generated" << std::endl
......@@ -112,14 +114,18 @@ int main(int argc, char * const argv[])
myQuery = new DCDBQuery();
/* Get the options */
bool direct = false;
int ret;
const char *host = getenv("DCDB_HOSTNAME");
if (!host) {
host = "localhost";
}
while ((ret=getopt(argcReal, argvReal, "+h:rlf"))!=-1) {
while ((ret=getopt(argcReal, argvReal, "+h:drlf"))!=-1) {
switch(ret) {
case 'd':
direct = true;
break;
case 'h':
host = optarg;
break;
......@@ -159,7 +165,7 @@ int main(int argc, char * const argv[])
sensors.push_back(argvReal[arg]);
}
myQuery->doQuery(host, sensors, start, end);
myQuery->doQuery(host, sensors, start, end, direct);
delete myQuery;
......
......@@ -203,7 +203,7 @@ void DCDBQuery::genOutput(std::list<DCDB::SensorDataStoreReading> &results, quer
}
}
void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DCDB::TimeStamp start, DCDB::TimeStamp end)
void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DCDB::TimeStamp start, DCDB::TimeStamp end, bool direct)
{
/* Create a new connection to the database */
connection = new DCDB::Connection();
......@@ -265,10 +265,17 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
queryCfg.unit = DCDB::UnitConv::fromString(modifierStr);
}
}
std::list<DCDB::PublicSensor> publicSensors;
sensorConfig.getPublicSensorsByWildcard(publicSensors, sensorName.c_str());
for (auto sen: publicSensors) {
queries.insert(std::pair<DCDB::PublicSensor,queryConfig_t>(sen, queryCfg));
if(!direct) {
std::list <DCDB::PublicSensor> publicSensors;
sensorConfig.getPublicSensorsByWildcard(publicSensors, sensorName.c_str());
for (auto sen: publicSensors) {
queries.insert(std::pair<DCDB::PublicSensor, queryConfig_t>(sen, queryCfg));
}
} else {
DCDB::PublicSensor pS;
pS.name = sensorName;
pS.pattern = sensorName;
queries.insert(std::pair<DCDB::PublicSensor, queryConfig_t>(pS, queryCfg));
}
}
}
......
......@@ -87,7 +87,7 @@ public:
void check(std::list<std::string>::iterator it , double* scalingFactor);
void checkModifier(std::list<std::string>::iterator it, struct outputFormat *format);
void doQuery(const char* hostname, std::list<std::string> sensors, DCDB::TimeStamp start, DCDB::TimeStamp end);
void doQuery(const char* hostname, std::list<std::string> sensors, DCDB::TimeStamp start, DCDB::TimeStamp end, bool direct=false);
DCDBQuery();
virtual ~DCDBQuery() {};
......
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