OpenFCST: The open-source Fuel Cell Simulation Toolbox
|
This class is for interfacing with SQL databases, for the purpose of accessing and storing simulation results. More...
#include <fcst_db.h>
Public Member Functions | |
FCSTdatabase () | |
Constructor. More... | |
virtual | ~FCSTdatabase () |
Destructor. More... | |
bool | connect (const std::string &db_path_, const bool &create_if_does_not_exist=false) |
Function for connecting to SQL database. More... | |
bool | connect () |
Function for connecting to default SQL database, located at fcst_root/main_db. More... | |
bool | disconnect () |
Function for disconnecting to SQL database. More... | |
bool | has_data (const std::string &model_name, const DatabaseOC &OC) |
Function for testing if db that you are connected to has data for a given model and operating conditions. More... | |
bool | has_data (const std::string &model_name, const DatabaseOC &OC, const double &tolerance) |
Function for testing if db that you are connected to has data for a given model and operating conditions. More... | |
std::vector< std::vector < double > > | get_data (const std::string &model_name, const DatabaseOC &OC) |
Function for getting numerical information for a given model and operating conditions. More... | |
std::vector< std::vector < double > > | get_data (const std::string &model_name, const DatabaseOC &OC, const double &tolerance) |
Function for getting numerical information for a given model and operating conditions. More... | |
std::vector< std::vector < double > > | get_data (const std::string &model_name, const DatabaseOC &OC, const double &tolerance, const std::string &orderby) |
Function for getting numerical information for a given model and operating conditions. More... | |
bool | commit_data (const std::string &model_name, const DatabaseOC &OC, const std::vector< std::string > &column_names, const std::vector< std::vector< double >> &data) |
Function for committing numerical information for a given model and operating conditions. More... | |
std::vector< std::vector < std::string > > | request (const std::string &sqlCmd) |
Wrapper Function for performing direct SQL requests. More... | |
bool | clear_data (const std::string &model_name, const DatabaseOC &OC) |
Function for clearing data for a given model and operating conditions. More... | |
void | cleanUp () |
Function which performs database cleanup, removing erroneous data occurring from SQL errors. More... | |
Private Member Functions | |
std::string | make_new_head_entry (const std::string &model_name, const DatabaseOC &OC) |
bool | create_table (const std::string &table_name, const std::vector< std::string > &column_names) |
bool | fill_empty_table (const std::string &table_name, const std::vector< std::vector< double >> &data, const std::vector< std::string > &column_names) |
std::string | find_table (const std::string &model_name, const DatabaseOC &OC) |
std::string | find_table (const std::string &model_name, const DatabaseOC &OC, const double &tolerance) |
bool | find_matching_head_term (const std::vector< std::string > &OC, const std::vector< std::string > &head_line, const double &tolerance) |
bool | request_no_callback (const std::string &sqlCmd) |
bool | request (const std::string &sqlCmd, const bool &useCallBack, int lockCounter=max_lock) |
bool | create_new_db (const std::string &filePath) |
Function for creating a new default db. More... | |
Static Private Member Functions | |
static int | callback (void *db_, int argc, char **argv, char **azColName) |
Private Attributes | |
sqlite3 * | db |
bool | connected |
std::string | db_path |
std::vector< std::vector < std::string > > | temp |
unsigned int | max_milli |
double | lock_time |
Static Private Attributes | |
static const int | max_lock |
This class is for interfacing with SQL databases, for the purpose of accessing and storing simulation results.
This class provides a database interface for storing generic numerical data to disc. It provides tolerance based selection of data based upon explicit operating conditions.
FcstUtilities::FCSTdatabase::FCSTdatabase | ( | ) |
Constructor.
|
virtual |
Destructor.
|
inlinestaticprivate |
void FcstUtilities::FCSTdatabase::cleanUp | ( | ) |
Function which performs database cleanup, removing erroneous data occurring from SQL errors.
Currently the function removes invalid HEAD entries (entries which are missing corresponding data tables).
bool FcstUtilities::FCSTdatabase::clear_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC | ||
) |
Function for clearing data for a given model and operating conditions.
Takes model name and operating conditions as arguments. OC is a 2d array (vector vector) in which for a given line the first element is the operating condition name and the second element is the value.
Returns true if data is successfully deleted.
See Unit test "testCommitData" for usage demo.
bool FcstUtilities::FCSTdatabase::commit_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const std::vector< std::string > & | column_names, | ||
const std::vector< std::vector< double >> & | data | ||
) |
Function for committing numerical information for a given model and operating conditions.
Takes model name, operating conditions, data column titles, and data as arguments. OC is a 2d array (vector vector) in which for a given line the first element is the operating condition name and the second element is the value. Column_names is a list of column that pertains to the numerical data stored in argument data. Data is a 2d array (vector vector) of doubles containing the data we whish to store.
Returns an empty vector(vector(double)) if no data exists.
Throws exceptions if invalid column names are provided (only characters "123456789abcdefghijklmnopqrstuvwxyz " are permitted, i.e. alpha numeric and whitespace).
Throws exception if data or column_name vectors are empty or do not match in dimension.
See Unit test "testCommitData" for usage demo.
bool FcstUtilities::FCSTdatabase::connect | ( | const std::string & | db_path_, |
const bool & | create_if_does_not_exist = false |
||
) |
Function for connecting to SQL database.
Takes database file path as argument. Returns true if connection successful
bool FcstUtilities::FCSTdatabase::connect | ( | ) |
Function for connecting to default SQL database, located at fcst_root/main_db.
Returns true if connection successful
|
private |
Function for creating a new default db.
|
private |
bool FcstUtilities::FCSTdatabase::disconnect | ( | ) |
Function for disconnecting to SQL database.
Returns true if disconnection successful
|
private |
|
private |
|
private |
|
private |
std::vector<std::vector<double> > FcstUtilities::FCSTdatabase::get_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC | ||
) |
Function for getting numerical information for a given model and operating conditions.
Takes model name and operating conditions as arguments. OC is an object of DatabaseOC type.
N.b: returns an potentially unordered (by rows) list of results. See third overloading of this function.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testGetData" for usage demo.
std::vector<std::vector<double> > FcstUtilities::FCSTdatabase::get_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const double & | tolerance | ||
) |
Function for getting numerical information for a given model and operating conditions.
Takes model name, operating conditions, and a tolerance as arguments. OC is an object of DatabaseOC type. Differences in operating condition values will be compared with provided tolerance (0.0 - 1.0).
N.b: returns an potentially unordered (by rows) list of results. See third overloading of this function.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testGetData" for usage demo.
std::vector<std::vector<double> > FcstUtilities::FCSTdatabase::get_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const double & | tolerance, | ||
const std::string & | orderby | ||
) |
Function for getting numerical information for a given model and operating conditions.
Takes model name, operating conditions, orderby string,and a tolerance as arguments. OC is an object of DatabaseOC type. Differences in operating condition values will be compared with provided tolerance (0.0 - 1.0). Orderby is the name of the column that the results will be ordered by before being returned.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testGetData" for usage demo.
bool FcstUtilities::FCSTdatabase::has_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC | ||
) |
Function for testing if db that you are connected to has data for a given model and operating conditions.
Takes model name and operating conditions as arguments. OC is an object of DatabaseOC type.
Returns true if data exists.
See Unit test "testHasData" for usage demo.
bool FcstUtilities::FCSTdatabase::has_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const double & | tolerance | ||
) |
Function for testing if db that you are connected to has data for a given model and operating conditions.
Takes model name, operating conditions, and a tolerance as arguments. OC is an object of DatabaseOC type. Differences in operating condition values will be compared with provided tolerance (0.0 - 1.0). Returns true if data exists.
See Unit test "testHasData" for usage demo.
|
private |
std::vector<std::vector<std::string> > FcstUtilities::FCSTdatabase::request | ( | const std::string & | sqlCmd | ) |
Wrapper Function for performing direct SQL requests.
Takes a SQL statement as argument. Returns the results of the request in a 2d array (vector vector) of strings.
Note: If you don't know SQL then this is probably not the function for you, try another.
See Unit test "testRequest" for usage demo.
|
private |
|
private |
|
private |
|
private |
Referenced by callback().
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
Referenced by callback().