Added use_postgres arg

This commit is contained in:
BuildTools 2021-09-23 15:06:14 -05:00
parent cf90d2ab2b
commit 76154631ee

View File

@ -539,36 +539,43 @@ int main(int argc, char *argv[]) {
batch_size = std::stoi(opt_batch);
if (use_postgres) {
std::cout << "Importing Models and Exploits into Database: ";
import_models(parsednm, parsedxp); //directly use the strings parsednm and parsedxp as SQL commands
gettimeofday(&tf3,NULL);
double tdiff3=(tf3.tv_sec-ts3.tv_sec)*1000.0+(tf3.tv_usec-ts3.tv_usec)/1000.0;
std::cout << "Done\n";
printf("------>The time to load .nm and .xp into the database took %lf ms.<------\n",tdiff3);
printf("\n");
std::cout << "Importing Models and Exploits into Database: ";
import_models(parsednm, parsedxp); //directly use the strings parsednm and parsedxp as SQL commands
gettimeofday(&tf3,NULL);
double tdiff3=(tf3.tv_sec-ts3.tv_sec)*1000.0+(tf3.tv_usec-ts3.tv_usec)/1000.0;
std::cout << "Done\n";
printf("------>The time to load .nm and .xp into the database took %lf ms.<------\n",tdiff3);
printf("\n");
}
//------------------------------------------
//program block 3:
//------------------------------------------
AGGenInstance _instance;
//the following five assignments to _instance's members are all from db_function.cpp
_instance.facts = fetch_facts();
//The above function call returned an Keyvalue object and assigned the object to facts. The object mainly contains hash table and string vector based on all initial property and value.
//the following 4 lines can be used to check the content of the facts. It is based on the initial property and value from table quality, postcondition and topology.
//for(std::string abc: _instance.facts.get_str_vector()){
// std::cout<<"Fact: "<<abc<<"\n";
//std::cout<<"Hash number: "<<_instance.facts[abc]<<"\n";
//std::cout<<"Operator: " <<abc[3]<<"\n";
//std::cout<<"Operator: " <<fetch_all_qualities(_instance.facts).get_op();
//}
_instance.initial_qualities = fetch_all_qualities(_instance.facts); //prepare all the initial qualities, return a Quality vector of (quality plus facts)
_instance.initial_topologies = fetch_all_topologies(_instance.facts); //prepare all the initial topologies, return a Topology vector of (topology plus facts)
_instance.assets = fetch_all_assets(_instance.facts); //fetch each asset name and its related qualities.
_instance.exploits = fetch_all_exploits(); //fetch each exploit and its precondition and post conditions from initial exploits
auto ex = fetch_all_exploits(); //make a copy of initial exploits
//the following five assignments are only applicable when use_postgres is set to true
if (use_postgres) {
_instance.facts = fetch_facts();
//The above function call returned an Keyvalue object and assigned the object to facts. The object mainly contains hash table and string vector based on all initial property and value.
//the following 4 lines can be used to check the content of the facts. It is based on the initial property and value from table quality, postcondition and topology.
//for(std::string abc: _instance.facts.get_str_vector()){
// std::cout<<"Fact: "<<abc<<"\n";
//std::cout<<"Hash number: "<<_instance.facts[abc]<<"\n";
//std::cout<<"Operator: " <<abc[3]<<"\n";
//std::cout<<"Operator: " <<fetch_all_qualities(_instance.facts).get_op();
//}
_instance.initial_qualities = fetch_all_qualities(_instance.facts); //prepare all the initial qualities, return a Quality vector of (quality plus facts)
_instance.initial_topologies = fetch_all_topologies(_instance.facts); //prepare all the initial topologies, return a Topology vector of (topology plus facts)
_instance.assets = fetch_all_assets(_instance.facts); //fetch each asset name and its related qualities.
_instance.exploits = fetch_all_exploits(); //fetch each exploit and its precondition and post conditions from initial exploits
auto ex = fetch_all_exploits(); //make a copy of initial exploits
}
else {
std::cout << parsednm << std::endl;
std::cout << "Not yet implemented." << std::endl;
return(1);
}
std::cout << "Assets: " << _instance.assets.size() << "\n"; //# of assets, vector size
std::cout << "Exploits: " << _instance.exploits.size() << "\n"; //# of exploits, vector size
std::cout << "Facts: " << _instance.facts.size() << "\n"; //how many different parameters and values are there? class size() method