Skip to content

Commit

Permalink
enhanced plot_facts service to plot full history
Browse files Browse the repository at this point in the history
  • Loading branch information
shipra25jain authored and Greg8978 committed Jul 12, 2016
1 parent 9f0ba6b commit 26fe151
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
48 changes: 36 additions & 12 deletions database_manager/src/run_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
#include "toaster_msgs/FactList.h"
#include <fstream>



std::vector<std::string> agentList;

ros::Time begin ;
std::vector<toaster_msgs::Fact> myFactList;
std::vector<toaster_msgs::Property> myPropertyList;
std::vector<toaster_msgs::Id> myEntityList;
Expand Down Expand Up @@ -1942,18 +1940,34 @@ bool plot_facts_db(toaster_msgs::PlotFactsDB::Request &req, toaster_msgs::PlotFa
char *err_msg = NULL;
int ret;
long long int i;


ros::Time now = ros::Time::now();
// sql query to get events related to the requested entity
// within the given time window and for the requested fact.
sql = (std::string)"SELECT * from events_table where subject_id='" +


if(req.fullTime)
{
// if the request is to plot the status of given fact from starting till now.
sql = (std::string)"SELECT * from events_table where subject_id='" +
boost::lexical_cast<std::string>(req.subjectID) + "' and target_id='" +
boost::lexical_cast<std::string>(req.targetID) + "' and time>='"+
boost::lexical_cast<std::string>(begin.toNSec()) + "' and time<='" +
boost::lexical_cast<std::string>(now.toNSec()) + "' and (predicate ='" +
boost::lexical_cast<std::string>(req.reqFact) + "' or predicate='!" +
boost::lexical_cast<std::string>(req.reqFact) + "');";
}
else
{
// if the request is to plot the status of given fact for given time window
sql = (std::string)"SELECT * from events_table where subject_id='" +
boost::lexical_cast<std::string>(req.subjectID) + "' and target_id='" +
boost::lexical_cast<std::string>(req.targetID) + "' and time>='" +
boost::lexical_cast<std::string>(req.timeStart) + "' and time<='" +
boost::lexical_cast<std::string>(req.timeEnd) + "' and (predicate ='" +
boost::lexical_cast<std::string>(req.reqFact) + "' or predicate='!" +
boost::lexical_cast<std::string>(req.reqFact) + "');";

boost::lexical_cast<std::string>(req.reqFact) + "');";
}
// results of the query are stored in the table
ret = sqlite3_get_table(database, sql.c_str(), &pazResult, &pnRow, &pnColumn, &err_msg);

Expand All @@ -1965,10 +1979,20 @@ bool plot_facts_db(toaster_msgs::PlotFactsDB::Request &req, toaster_msgs::PlotFa
} else {
std::map<long long int, int> fn;
std::vector<long long int> data(pnRow + 2);
std::string start = boost::lexical_cast<std::string>(req.timeStart);
std::string start;
std::string end;
if(!req.fullTime)
{
start = boost::lexical_cast<std::string>(req.timeStart);
end = boost::lexical_cast<std::string>(req.timeEnd);
}
else
{
start = boost::lexical_cast<std::string>(begin.toNSec());
end = boost::lexical_cast<std::string>(now.toNSec());
}
data[0] = std::atoll(start.c_str());
long long int timeStart = data[0];
std::string end = boost::lexical_cast<std::string>(req.timeEnd);
std::string reqFact = boost::lexical_cast<std::string>(req.reqFact);
long long int timeEnd = std::atoll(end.c_str());

Expand Down Expand Up @@ -2034,6 +2058,7 @@ bool plot_facts_db(toaster_msgs::PlotFactsDB::Request &req, toaster_msgs::PlotFa
}
}


////////////////////////////////////////////
/////////TO LOAD and SAVE the database///////
////////////////////////////////////////////
Expand Down Expand Up @@ -2326,8 +2351,7 @@ void initServer() {
int main(int argc, char **argv) {
ros::init(argc, argv, "database_server");
ros::NodeHandle node;


begin = ros::Time::now();
//// SERVICES DECLARATION /////

ros::ServiceServer set_info_service;
Expand Down
1 change: 1 addition & 0 deletions toaster_msgs/srv/PlotFactsDB.srv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ string subjectID
string targetID
uint64 timeStart
uint64 timeEnd
bool fullTime
string reqFact
---
bool boolAnswer

0 comments on commit 26fe151

Please sign in to comment.