23 return (std::get<0>(*first) < std::get<0>(*second));
32 Evaluator::Evaluator(std::list<evalulatorTupleSharedPtr> objectListEntry, std::list<std::string> sceneListEntry,
33 double GainValueThresholdEntry, std::string
NBVPath, std::string dbPath):
36 for (
const std::string &it : sceneListEntry)
41 std::list<evalulatorTupleSharedPtr> bufferObjectList;
44 while(objectListEntry.size()>0)
47 std::string objectMetaName =std::get<2>(*(*objectListEntry.begin()));
48 std::string objectName =std::get<3>(*(*objectListEntry.begin()));
49 std::string objectObservedId =std::get<4>(*(*objectListEntry.begin()));
50 fValue += std::get<0>(*(*objectListEntry.begin()));
52 SceneMap[std::get<1>(*(*objectListEntry.begin()))].push_back(std::get<2>(*(*objectListEntry.begin())));
53 objectListEntry.pop_front();
54 bufferObjectList = objectListEntry;
58 if(std::get<2>(*tuple) == objectMetaName)
60 SceneMap[std::get<1>(*tuple)].push_back(std::get<2>(*tuple));
61 fValue += std::get<0>(*tuple);
62 bufferObjectList.remove(tuple);
67 objectListEntry = bufferObjectList;
85 ret += std::get<0>(*it);
87 return ret/list.size();
95 for (std::unordered_map<std::string,std::list<std::string>>::iterator it=
SceneMap.begin(); it!=
SceneMap.end(); ++it)
99 for (
const std::string &it3 : it->second)
101 if(it3 == std::get<1>(*it2))
109 if(!test)
return false;
114 bool Evaluator::Evaluate(std::list<objectTupleSharedPtr> oldList, std::list<objectTupleSharedPtr> newList)
132 ROS_DEBUG_STREAM(
"Evaluator::getIntermediateObjects Weight value are now sorted");
133 std::list<objectTupleSharedPtr> bufferTupleList;
134 ROS_DEBUG_STREAM(
"Evaluator::getIntermediateObjects begin from filtering iteration process");
153 ROS_DEBUG_STREAM(
"Evaluator::getIntermediateObjects end from filtering iteration process");
154 ROS_DEBUG_STREAM(
"Evaluator::getIntermediateObjects gotten list from intermediate object");
157 ROS_DEBUG_STREAM(
"Evaluator::getIntermediateObjects Object " <<std::get<2>(*tuple)
158 <<
" with observed Id " << std::get<3>(*tuple)
159 <<
" and value " << std::get<0>(*tuple));
167 std::string output =
"<InterObj>";
170 ROS_DEBUG_STREAM(
"Evaluator::PublishIntermediateObjectForWorldModel Object " << std::get<2>(*tuple) <<
" with observed Id " << std::get<3>(*tuple)
171 <<
" got intermediate object weight " << std::get<0>(*tuple));
172 output +=
"<obj name=\""+std::get<2>(*tuple)+
"\" observedId=\""+std::get<3>(*tuple)+
"\">" + std::to_string(std::get<0>(*tuple)) +
"</obj>";
174 output +=
"</InterObj>";
176 std::ofstream file(
NBVPath, std::ios::out | std::ios::trunc);
184 static int callback(
void *NotUsed,
int argc,
char **argv,
char **azColName){
187 for(i=0; i<argc; i++){
188 ROS_DEBUG(
"Evaluator::PublishIntermediateObjectInDomainTable %s = %s\n", azColName[i], argv[i] ? argv[i] :
"NULL");
195 std::stringstream sqlReq;
197 sqlReq <<
"CREATE TABLE model_weight(id INT PRIMARY KEY NOT NULL,type VARCHAR(100),observedId " 198 <<
"VARCHAR(100), weight VARCHAR(100));";
199 const std::string& sqlReqString = sqlReq.str();
200 const char* SQLREQ = sqlReqString.c_str();
202 sqlite3_open(
DbPath.c_str(), &database);
203 int sqliteReturn = sqlite3_exec(database, SQLREQ,
callback, 0, &zErrMsg);
204 if( sqliteReturn != SQLITE_OK )
206 ROS_WARN_STREAM(
"Evaluator::PublishIntermediateObjectInDomainTable SQL error : " << zErrMsg);
207 sqlite3_free(zErrMsg);
211 ROS_DEBUG_STREAM(
"Evaluator::PublishIntermediateObjectInDomainTable Model weight table created.");
214 std::stringstream clearReq;
215 clearReq <<
"DELETE FROM model_weight";
217 const std::string& clearReqString = clearReq.str();
218 const char* SQLCLEAR = clearReqString.c_str();
219 sqliteReturn = sqlite3_exec(database, SQLCLEAR,
callback, 0, &zErrMsg);
220 if( sqliteReturn != SQLITE_OK )
222 ROS_WARN_STREAM(
"Evaluator::PublishIntermediateObjectInDomainTable SQL error : " << zErrMsg);
223 sqlite3_free(zErrMsg);
227 ROS_DEBUG_STREAM(
"Evaluator::PublishIntermediateObjectInDomainTable table cleared.");
230 std::stringstream insertReq;
231 unsigned int counter = 0;
234 insertReq <<
"INSERT INTO model_weight (id,type,observedId,weight)" 235 <<
"VALUES (" << counter <<
", '"<< std::get<2>(*tuple) <<
"', '"<< std::get<3>(*tuple) <<
"', '" 236 << std::get<0>(*tuple) <<
"');";
239 const std::string& insertReqString = insertReq.str();
240 const char* SQLINSERT = insertReqString.c_str();
241 sqliteReturn = sqlite3_exec(database, SQLINSERT,
callback, 0, &zErrMsg);
242 if( sqliteReturn != SQLITE_OK )
244 ROS_WARN_STREAM(
"Evaluator::PublishIntermediateObjectInDomainTable SQL error : " << zErrMsg);
245 sqlite3_free(zErrMsg);
249 ROS_DEBUG_STREAM(
"Evaluator::PublishIntermediateObjectInDomainTable Weights inserted.");
251 sqlite3_close(database);
bool Validation(std::list< objectTupleSharedPtr > listToValidate)
std::tuple< double, std::string, std::string, std::string > objectTuple
std::shared_ptr< objectTuple > objectTupleSharedPtr
std::list< objectTupleSharedPtr > ProcessedObjectList
std::list< objectTupleSharedPtr > getIntermediateObjects()
void PublishIntermediateObjectForWorldModel()
std::unordered_map< std::string, std::list< std::string > > SceneMap
double GainValueThreshold
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
double CalcAverageF(std::list< objectTupleSharedPtr > list)
void PublishIntermediateObjectInDomainTable()
bool compare_evaluator_tuple(const objectTupleSharedPtr &first, const objectTupleSharedPtr &second)
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
bool Evaluate(std::list< objectTupleSharedPtr > oldList, std::list< objectTupleSharedPtr > newList)
std::shared_ptr< evalulatorTuple > evalulatorTupleSharedPtr