Replace #define ... with pragma once

This commit is contained in:
2024-03-10 12:50:35 +01:00
parent 51f32113c0
commit 0010c840d1
33 changed files with 84 additions and 111 deletions

View File

@@ -42,7 +42,7 @@ add_executable(b_main ${main_sources} common/Datasets.cc common/Dataset.cc repor
target_link_libraries(b_main "${PyClassifiers}" "${BayesNet}" ArffFiles mdlp ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::python Boost::numpy) target_link_libraries(b_main "${PyClassifiers}" "${BayesNet}" ArffFiles mdlp ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::python Boost::numpy)
# b_manage # b_manage
set(manage_sources b_manage.cc ManageResults.cc CommandParser.cc Results.cc) set(manage_sources b_manage.cc ManageResults.cc CommandParser.cc ResultsManager.cc)
list(TRANSFORM manage_sources PREPEND manage/) list(TRANSFORM manage_sources PREPEND manage/)
add_executable( add_executable(
b_manage ${manage_sources} main/Result.cc b_manage ${manage_sources} main/Result.cc

View File

@@ -1,5 +1,5 @@
#ifndef BESTRESULTS_H #pragma once
#define BESTRESULTS_H
#include <string> #include <string>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using json = nlohmann::json; using json = nlohmann::json;
@@ -34,4 +34,3 @@ namespace platform {
int maxDatasetName = 0; int maxDatasetName = 0;
}; };
} }
#endif //BESTRESULTS_H

View File

@@ -1,5 +1,5 @@
#ifndef BESTRESULTS_EXCEL_H #pragma once
#define BESTRESULTS_EXCEL_H
#include <vector> #include <vector>
#include <map> #include <map>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -34,4 +34,3 @@ namespace platform {
int datasetNameSize = 25; // Min size of the column int datasetNameSize = 25; // Min size of the column
}; };
} }
#endif //BESTRESULTS_EXCEL_H

View File

@@ -1,5 +1,5 @@
#ifndef BESTSCORE_H #pragma once
#define BESTSCORE_H
#include <string> #include <string>
#include <map> #include <map>
#include <utility> #include <utility>
@@ -24,5 +24,3 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef STATISTICS_H #pragma once
#define STATISTICS_H
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -60,4 +60,3 @@ namespace platform {
std::map<std::string, std::map<std::string, float>> ranksModels; std::map<std::string, std::map<std::string, float>> ranksModels;
}; };
} }
#endif // !STATISTICS_H

View File

@@ -1,5 +1,5 @@
#ifndef LOCALE_H #pragma once
#define LOCALE_H
#include <locale> #include <locale>
#include <iostream> #include <iostream>
#include <string> #include <string>
@@ -19,4 +19,3 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef COLORS_H #pragma once
#define COLORS_H
#include <string> #include <string>
class Colors { class Colors {
public: public:
@@ -13,4 +13,3 @@ public:
static std::string IBLUE() { return "\033[0;94m"; } static std::string IBLUE() { return "\033[0;94m"; }
static std::string RESET() { return "\033[0m"; } static std::string RESET() { return "\033[0m"; }
}; };
#endif // COLORS_H

View File

@@ -1,5 +1,5 @@
#ifndef DATASET_H #pragma once
#define DATASET_H
#include <torch/torch.h> #include <torch/torch.h>
#include <map> #include <map>
#include <vector> #include <vector>
@@ -75,4 +75,3 @@ namespace platform {
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#ifndef DATASETS_H #pragma once
#define DATASETS_H
#include "Dataset.h" #include "Dataset.h"
namespace platform { namespace platform {
class Datasets { class Datasets {
@@ -27,5 +27,3 @@ namespace platform {
std::string toString() const; std::string toString() const;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#ifndef DOTENV_H #pragma once
#define DOTENV_H
#include <string> #include <string>
#include <map> #include <map>
#include <fstream> #include <fstream>
@@ -52,4 +52,3 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef PATHS_H #pragma once
#define PATHS_H
#include <string> #include <string>
#include <filesystem> #include <filesystem>
#include "DotEnv.h" #include "DotEnv.h"
@@ -36,4 +36,3 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef SYMBOLS_H #pragma once
#define SYMBOLS_H
#include <string> #include <string>
namespace platform { namespace platform {
class Symbols { class Symbols {
@@ -15,4 +15,3 @@ namespace platform {
inline static const std::string notebook{ "\U0001F5C8" }; inline static const std::string notebook{ "\U0001F5C8" };
}; };
} }
#endif // !SYMBOLS_H

View File

@@ -1,5 +1,5 @@
#ifndef TIMER_H #pragma once
#define TIMER_H
#include <chrono> #include <chrono>
#include <string> #include <string>
#include <sstream> #include <sstream>
@@ -40,4 +40,3 @@ namespace platform {
} }
}; };
} /* namespace platform */ } /* namespace platform */
#endif /* TIMER_H */

View File

@@ -1,5 +1,5 @@
#ifndef UTILS_H #pragma once
#define UTILS_H
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -27,4 +27,3 @@ namespace platform {
return result; return result;
} }
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef GRIDDATA_H #pragma once
#define GRIDDATA_H
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -23,4 +23,3 @@ namespace platform {
std::map<std::string, json> grid; std::map<std::string, json> grid;
}; };
} /* namespace platform */ } /* namespace platform */
#endif /* GRIDDATA_H */

View File

@@ -1,5 +1,5 @@
#ifndef GRIDSEARCH_H #pragma once
#define GRIDSEARCH_H
#include <string> #include <string>
#include <map> #include <map>
#include <mpi.h> #include <mpi.h>
@@ -57,4 +57,3 @@ namespace platform {
Timer timer; // used to measure the time of the whole process Timer timer; // used to measure the time of the whole process
}; };
} /* namespace platform */ } /* namespace platform */
#endif /* GRIDSEARCH_H */

View File

@@ -1,5 +1,5 @@
#ifndef DATASETS_EXCEL_H #pragma once
#define DATASETS_EXCEL_H
#include <vector> #include <vector>
#include <map> #include <map>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -16,4 +16,3 @@ namespace platform {
void report(json& data); void report(json& data);
}; };
} }
#endif //DATASETS_EXCEL_H

View File

@@ -75,6 +75,9 @@ void list_datasets(argparse::ArgumentParser& program)
void list_results(argparse::ArgumentParser& program) void list_results(argparse::ArgumentParser& program)
{ {
std::cout << "Results" << std::endl; std::cout << "Results" << std::endl;
auto dataset = program.get<string>("--dataset");
auto score = program.get<string>("--score");
} }
int main(int argc, char** argv) int main(int argc, char** argv)
@@ -107,6 +110,7 @@ int main(int argc, char** argv)
throw std::runtime_error("Dataset must be one of " + datasets.toString()); throw std::runtime_error("Dataset must be one of " + datasets.toString());
} }
); );
program.add_argument("-s", "--score").default_value("accuracy").help("Filter results of the score name supplied");
// Add subparsers // Add subparsers
program.add_subparser(datasets_command); program.add_subparser(datasets_command);
program.add_subparser(results_command); program.add_subparser(results_command);

View File

@@ -1,5 +1,5 @@
#ifndef EXPERIMENT_H #pragma once
#define EXPERIMENT_H
#include <torch/torch.h> #include <torch/torch.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
@@ -42,5 +42,4 @@ namespace platform {
int nfolds{ 0 }; int nfolds{ 0 };
int max_name{ 7 }; // max length of dataset name for formatting (default 7) int max_name{ 7 }; // max length of dataset name for formatting (default 7)
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef HYPERPARAMETERS_H #pragma once
#define HYPERPARAMETERS_H
#include <string> #include <string>
#include <map> #include <map>
#include <vector> #include <vector>
@@ -20,4 +20,3 @@ namespace platform {
std::map<std::string, json> hyperparameters; std::map<std::string, json> hyperparameters;
}; };
} /* namespace platform */ } /* namespace platform */
#endif /* HYPERPARAMETERS_H */

View File

@@ -1,5 +1,5 @@
#ifndef MODELS_H #pragma once
#define MODELS_H
#include <map> #include <map>
#include <bayesnet/BaseClassifier.h> #include <bayesnet/BaseClassifier.h>
#include <bayesnet/ensembles/AODE.h> #include <bayesnet/ensembles/AODE.h>
@@ -39,4 +39,3 @@ namespace platform {
Registrar(const std::string& className, function<bayesnet::BaseClassifier* (void)> classFactoryFunction); Registrar(const std::string& className, function<bayesnet::BaseClassifier* (void)> classFactoryFunction);
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#ifndef RESULT_H #pragma once
#define RESULT_H
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
@@ -48,4 +48,3 @@ namespace platform {
double score = 0.0; double score = 0.0;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#ifndef MODEL_REGISTER_H #pragma once
#define MODEL_REGISTER_H
static platform::Registrar registrarT("TAN", static platform::Registrar registrarT("TAN",
[](void) -> bayesnet::BaseClassifier* { return new bayesnet::TAN();}); [](void) -> bayesnet::BaseClassifier* { return new bayesnet::TAN();});
static platform::Registrar registrarTLD("TANLd", static platform::Registrar registrarTLD("TANLd",
@@ -27,5 +27,4 @@ static platform::Registrar registrarSvc("SVC",
static platform::Registrar registrarRaF("RandomForest", static platform::Registrar registrarRaF("RandomForest",
[](void) -> bayesnet::BaseClassifier* { return new pywrap::RandomForest();}); [](void) -> bayesnet::BaseClassifier* { return new pywrap::RandomForest();});
static platform::Registrar registrarXGB("XGBoost", static platform::Registrar registrarXGB("XGBoost",
[](void) -> bayesnet::BaseClassifier* { return new pywrap::XGBoost();}); [](void) -> bayesnet::BaseClassifier* { return new pywrap::XGBoost();});
#endif

View File

@@ -1,5 +1,5 @@
#ifndef COMMAND_PARSER_H #pragma once
#define COMMAND_PARSER_H
#include <string> #include <string>
#include <vector> #include <vector>
#include <tuple> #include <tuple>
@@ -17,4 +17,3 @@ namespace platform {
int index; int index;
}; };
} /* namespace platform */ } /* namespace platform */
#endif /* COMMAND_PARSER_H */

View File

@@ -12,7 +12,7 @@
namespace platform { namespace platform {
ManageResults::ManageResults(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) : ManageResults::ManageResults(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(Results(Paths::results(), model, score, complete, partial)) numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(ResultsManager(model, score, complete, partial))
{ {
indexList = true; indexList = true;
openExcel = false; openExcel = false;

View File

@@ -1,7 +1,7 @@
#ifndef MANAGE_RESULTS_H #pragma once
#define MANAGE_RESULTS_H
#include <xlsxwriter.h> #include <xlsxwriter.h>
#include "Results.h" #include "ResultsManager.h"
namespace platform { namespace platform {
class ManageResults { class ManageResults {
@@ -23,9 +23,7 @@ namespace platform {
bool complete; bool complete;
bool partial; bool partial;
bool compare; bool compare;
Results results; ResultsManager results;
lxw_workbook* workbook; lxw_workbook* workbook;
}; };
} }
#endif /* MANAGE_RESULTS_H */

View File

@@ -1,9 +1,10 @@
#include <algorithm> #include <algorithm>
#include "Results.h" #include "common/Paths.h"
#include "ResultsManager.h"
namespace platform { namespace platform {
Results::Results(const std::string& path, const std::string& model, const std::string& score, bool complete, bool partial) : ResultsManager::ResultsManager(const std::string& model, const std::string& score, bool complete, bool partial) :
path(path), model(model), scoreName(score), complete(complete), partial(partial) path(Paths::results()), model(model), scoreName(score), complete(complete), partial(partial)
{ {
load(); load();
if (!files.empty()) { if (!files.empty()) {
@@ -12,7 +13,7 @@ namespace platform {
maxModel = 0; maxModel = 0;
} }
} }
void Results::load() void ResultsManager::load()
{ {
using std::filesystem::directory_iterator; using std::filesystem::directory_iterator;
for (const auto& file : directory_iterator(path)) { for (const auto& file : directory_iterator(path)) {
@@ -28,47 +29,47 @@ namespace platform {
} }
} }
} }
void Results::hideResult(int index, const std::string& pathHidden) void ResultsManager::hideResult(int index, const std::string& pathHidden)
{ {
auto filename = files.at(index).getFilename(); auto filename = files.at(index).getFilename();
rename((path + "/" + filename).c_str(), (pathHidden + "/" + filename).c_str()); rename((path + "/" + filename).c_str(), (pathHidden + "/" + filename).c_str());
files.erase(files.begin() + index); files.erase(files.begin() + index);
} }
void Results::deleteResult(int index) void ResultsManager::deleteResult(int index)
{ {
auto filename = files.at(index).getFilename(); auto filename = files.at(index).getFilename();
remove((path + "/" + filename).c_str()); remove((path + "/" + filename).c_str());
files.erase(files.begin() + index); files.erase(files.begin() + index);
} }
int Results::size() const int ResultsManager::size() const
{ {
return files.size(); return files.size();
} }
void Results::sortDate() void ResultsManager::sortDate()
{ {
sort(files.begin(), files.end(), [](const Result& a, const Result& b) { sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
return a.getDate() > b.getDate(); return a.getDate() > b.getDate();
}); });
} }
void Results::sortModel() void ResultsManager::sortModel()
{ {
sort(files.begin(), files.end(), [](const Result& a, const Result& b) { sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
return a.getModel() > b.getModel(); return a.getModel() > b.getModel();
}); });
} }
void Results::sortDuration() void ResultsManager::sortDuration()
{ {
sort(files.begin(), files.end(), [](const Result& a, const Result& b) { sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
return a.getDuration() > b.getDuration(); return a.getDuration() > b.getDuration();
}); });
} }
void Results::sortScore() void ResultsManager::sortScore()
{ {
sort(files.begin(), files.end(), [](const Result& a, const Result& b) { sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
return a.getScore() > b.getScore(); return a.getScore() > b.getScore();
}); });
} }
bool Results::empty() const bool ResultsManager::empty() const
{ {
return files.empty(); return files.empty();
} }

View File

@@ -1,5 +1,5 @@
#ifndef RESULTS_H #pragma once
#define RESULTS_H
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
@@ -7,9 +7,9 @@
#include "main/Result.h" #include "main/Result.h"
namespace platform { namespace platform {
using json = nlohmann::json; using json = nlohmann::json;
class Results { class ResultsManager {
public: public:
Results(const std::string& path, const std::string& model, const std::string& score, bool complete, bool partial); ResultsManager(const std::string& model, const std::string& score, bool complete, bool partial);
void sortDate(); void sortDate();
void sortScore(); void sortScore();
void sortModel(); void sortModel();
@@ -32,5 +32,4 @@ namespace platform {
std::vector<Result> files; std::vector<Result> files;
void load(); // Loads the list of results void load(); // Loads the list of results
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#ifndef EXCELFILE_H #pragma once
#define EXCELFILE_H
#include <locale> #include <locale>
#include <string> #include <string>
#include <map> #include <map>
@@ -42,4 +42,3 @@ namespace platform {
void setDefault(); void setDefault();
}; };
} }
#endif // !EXCELFILE_H

View File

@@ -1,5 +1,5 @@
#ifndef REPORTBASE_H #pragma once
#define REPORTBASE_H
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -33,4 +33,3 @@ namespace platform {
bool existBestFile = true; bool existBestFile = true;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#ifndef REPORTCONSOLE_H #pragma once
#define REPORTCONSOLE_H
#include <string> #include <string>
#include "common/Colors.h" #include "common/Colors.h"
#include "ReportBase.h" #include "ReportBase.h"
@@ -19,4 +19,3 @@ namespace platform {
void showSummary() override; void showSummary() override;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#ifndef REPORTEXCEL_H #pragma once
#define REPORTEXCEL_H
#include <map> #include <map>
#include <xlsxwriter.h> #include <xlsxwriter.h>
#include "common/Colors.h" #include "common/Colors.h"
@@ -22,4 +22,3 @@ namespace platform {
void header_notes(int row); void header_notes(int row);
}; };
}; };
#endif // !REPORTEXCEL_H

View File

@@ -1,5 +1,5 @@
#ifndef TEST_UTILS_H #pragma once
#define TEST_UTILS_H
#include <torch/torch.h> #include <torch/torch.h>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -40,4 +40,3 @@ public:
double epsilon = 1e-5; double epsilon = 1e-5;
}; };
#endif //TEST_UTILS_H