From 0010c840d1dccba2ab1f61da7853f51c0537e9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Sun, 10 Mar 2024 12:50:35 +0100 Subject: [PATCH] Replace #define ... with pragma once --- src/CMakeLists.txt | 2 +- src/best/BestResults.h | 5 ++-- src/best/BestResultsExcel.h | 5 ++-- src/best/BestScore.h | 6 ++--- src/best/Statistics.h | 5 ++-- src/common/CLocale.h | 5 ++-- src/common/Colors.h | 5 ++-- src/common/Dataset.h | 5 ++-- src/common/Datasets.h | 6 ++--- src/common/DotEnv.h | 5 ++-- src/common/Paths.h | 5 ++-- src/common/Symbols.h | 5 ++-- src/common/Timer.h | 5 ++-- src/common/Utils.h | 5 ++-- src/grid/GridData.h | 5 ++-- src/grid/GridSearch.h | 5 ++-- src/list/DatasetsExcel.h | 5 ++-- src/list/b_list.cc | 4 ++++ src/main/Experiment.h | 7 +++--- src/main/HyperParameters.h | 5 ++-- src/main/Models.h | 5 ++-- src/main/Result.h | 5 ++-- src/main/modelRegister.h | 7 +++--- src/manage/CommandParser.h | 5 ++-- src/manage/ManageResults.cc | 2 +- src/manage/ManageResults.h | 10 ++++---- src/manage/{Results.cc => ResultsManager.cc} | 25 ++++++++++---------- src/manage/{Results.h => ResultsManager.h} | 11 ++++----- src/reports/ExcelFile.h | 5 ++-- src/reports/ReportBase.h | 5 ++-- src/reports/ReportConsole.h | 5 ++-- src/reports/ReportExcel.h | 5 ++-- tests/TestUtils.h | 5 ++-- 33 files changed, 84 insertions(+), 111 deletions(-) rename src/manage/{Results.cc => ResultsManager.cc} (76%) rename src/manage/{Results.h => ResultsManager.h} (83%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5da450b..bc73589 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) # 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/) add_executable( b_manage ${manage_sources} main/Result.cc diff --git a/src/best/BestResults.h b/src/best/BestResults.h index 1937df7..ce4b0cd 100644 --- a/src/best/BestResults.h +++ b/src/best/BestResults.h @@ -1,5 +1,5 @@ -#ifndef BESTRESULTS_H -#define BESTRESULTS_H +#pragma once + #include #include using json = nlohmann::json; @@ -34,4 +34,3 @@ namespace platform { int maxDatasetName = 0; }; } -#endif //BESTRESULTS_H \ No newline at end of file diff --git a/src/best/BestResultsExcel.h b/src/best/BestResultsExcel.h index 587e72c..00a82dc 100644 --- a/src/best/BestResultsExcel.h +++ b/src/best/BestResultsExcel.h @@ -1,5 +1,5 @@ -#ifndef BESTRESULTS_EXCEL_H -#define BESTRESULTS_EXCEL_H +#pragma once + #include #include #include @@ -34,4 +34,3 @@ namespace platform { int datasetNameSize = 25; // Min size of the column }; } -#endif //BESTRESULTS_EXCEL_H \ No newline at end of file diff --git a/src/best/BestScore.h b/src/best/BestScore.h index d42772c..6d90c38 100644 --- a/src/best/BestScore.h +++ b/src/best/BestScore.h @@ -1,5 +1,5 @@ -#ifndef BESTSCORE_H -#define BESTSCORE_H +#pragma once + #include #include #include @@ -24,5 +24,3 @@ namespace platform { } }; } - -#endif \ No newline at end of file diff --git a/src/best/Statistics.h b/src/best/Statistics.h index aee7409..a37c5b1 100644 --- a/src/best/Statistics.h +++ b/src/best/Statistics.h @@ -1,5 +1,5 @@ -#ifndef STATISTICS_H -#define STATISTICS_H +#pragma once + #include #include #include @@ -60,4 +60,3 @@ namespace platform { std::map> ranksModels; }; } -#endif // !STATISTICS_H \ No newline at end of file diff --git a/src/common/CLocale.h b/src/common/CLocale.h index 4403562..57c6efc 100644 --- a/src/common/CLocale.h +++ b/src/common/CLocale.h @@ -1,5 +1,5 @@ -#ifndef LOCALE_H -#define LOCALE_H +#pragma once + #include #include #include @@ -19,4 +19,3 @@ namespace platform { } }; } -#endif \ No newline at end of file diff --git a/src/common/Colors.h b/src/common/Colors.h index 8a7a0af..6818a2c 100644 --- a/src/common/Colors.h +++ b/src/common/Colors.h @@ -1,5 +1,5 @@ -#ifndef COLORS_H -#define COLORS_H +#pragma once + #include class Colors { public: @@ -13,4 +13,3 @@ public: static std::string IBLUE() { return "\033[0;94m"; } static std::string RESET() { return "\033[0m"; } }; -#endif // COLORS_H \ No newline at end of file diff --git a/src/common/Dataset.h b/src/common/Dataset.h index 092f75c..6c89769 100644 --- a/src/common/Dataset.h +++ b/src/common/Dataset.h @@ -1,5 +1,5 @@ -#ifndef DATASET_H -#define DATASET_H +#pragma once + #include #include #include @@ -75,4 +75,3 @@ namespace platform { }; }; -#endif \ No newline at end of file diff --git a/src/common/Datasets.h b/src/common/Datasets.h index 0f7f0cf..4e8b5d2 100644 --- a/src/common/Datasets.h +++ b/src/common/Datasets.h @@ -1,5 +1,5 @@ -#ifndef DATASETS_H -#define DATASETS_H +#pragma once + #include "Dataset.h" namespace platform { class Datasets { @@ -27,5 +27,3 @@ namespace platform { std::string toString() const; }; }; - -#endif \ No newline at end of file diff --git a/src/common/DotEnv.h b/src/common/DotEnv.h index 8b7a0cf..905e909 100644 --- a/src/common/DotEnv.h +++ b/src/common/DotEnv.h @@ -1,5 +1,5 @@ -#ifndef DOTENV_H -#define DOTENV_H +#pragma once + #include #include #include @@ -52,4 +52,3 @@ namespace platform { } }; } -#endif \ No newline at end of file diff --git a/src/common/Paths.h b/src/common/Paths.h index 6fd61cf..0b7ef32 100644 --- a/src/common/Paths.h +++ b/src/common/Paths.h @@ -1,5 +1,5 @@ -#ifndef PATHS_H -#define PATHS_H +#pragma once + #include #include #include "DotEnv.h" @@ -36,4 +36,3 @@ namespace platform { } }; } -#endif \ No newline at end of file diff --git a/src/common/Symbols.h b/src/common/Symbols.h index 3aa837e..e1c1468 100644 --- a/src/common/Symbols.h +++ b/src/common/Symbols.h @@ -1,5 +1,5 @@ -#ifndef SYMBOLS_H -#define SYMBOLS_H +#pragma once + #include namespace platform { class Symbols { @@ -15,4 +15,3 @@ namespace platform { inline static const std::string notebook{ "\U0001F5C8" }; }; } -#endif // !SYMBOLS_H \ No newline at end of file diff --git a/src/common/Timer.h b/src/common/Timer.h index dd10d94..c12aa70 100644 --- a/src/common/Timer.h +++ b/src/common/Timer.h @@ -1,5 +1,5 @@ -#ifndef TIMER_H -#define TIMER_H +#pragma once + #include #include #include @@ -40,4 +40,3 @@ namespace platform { } }; } /* namespace platform */ -#endif /* TIMER_H */ \ No newline at end of file diff --git a/src/common/Utils.h b/src/common/Utils.h index 1a08ac5..3149fcc 100644 --- a/src/common/Utils.h +++ b/src/common/Utils.h @@ -1,5 +1,5 @@ -#ifndef UTILS_H -#define UTILS_H +#pragma once + #include #include #include @@ -27,4 +27,3 @@ namespace platform { return result; } } -#endif \ No newline at end of file diff --git a/src/grid/GridData.h b/src/grid/GridData.h index 0156453..e4ca2d0 100644 --- a/src/grid/GridData.h +++ b/src/grid/GridData.h @@ -1,5 +1,5 @@ -#ifndef GRIDDATA_H -#define GRIDDATA_H +#pragma once + #include #include #include @@ -23,4 +23,3 @@ namespace platform { std::map grid; }; } /* namespace platform */ -#endif /* GRIDDATA_H */ \ No newline at end of file diff --git a/src/grid/GridSearch.h b/src/grid/GridSearch.h index 4e10735..a7a1e8c 100644 --- a/src/grid/GridSearch.h +++ b/src/grid/GridSearch.h @@ -1,5 +1,5 @@ -#ifndef GRIDSEARCH_H -#define GRIDSEARCH_H +#pragma once + #include #include #include @@ -57,4 +57,3 @@ namespace platform { Timer timer; // used to measure the time of the whole process }; } /* namespace platform */ -#endif /* GRIDSEARCH_H */ \ No newline at end of file diff --git a/src/list/DatasetsExcel.h b/src/list/DatasetsExcel.h index f7a520d..a362bf4 100644 --- a/src/list/DatasetsExcel.h +++ b/src/list/DatasetsExcel.h @@ -1,5 +1,5 @@ -#ifndef DATASETS_EXCEL_H -#define DATASETS_EXCEL_H +#pragma once + #include #include #include @@ -16,4 +16,3 @@ namespace platform { void report(json& data); }; } -#endif //DATASETS_EXCEL_H \ No newline at end of file diff --git a/src/list/b_list.cc b/src/list/b_list.cc index 1cbe4a4..7058afc 100644 --- a/src/list/b_list.cc +++ b/src/list/b_list.cc @@ -75,6 +75,9 @@ void list_datasets(argparse::ArgumentParser& program) void list_results(argparse::ArgumentParser& program) { std::cout << "Results" << std::endl; + auto dataset = program.get("--dataset"); + auto score = program.get("--score"); + } 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()); } ); + program.add_argument("-s", "--score").default_value("accuracy").help("Filter results of the score name supplied"); // Add subparsers program.add_subparser(datasets_command); program.add_subparser(results_command); diff --git a/src/main/Experiment.h b/src/main/Experiment.h index fc9a8f3..6e8c384 100644 --- a/src/main/Experiment.h +++ b/src/main/Experiment.h @@ -1,5 +1,5 @@ -#ifndef EXPERIMENT_H -#define EXPERIMENT_H +#pragma once + #include #include #include @@ -42,5 +42,4 @@ namespace platform { int nfolds{ 0 }; int max_name{ 7 }; // max length of dataset name for formatting (default 7) }; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/HyperParameters.h b/src/main/HyperParameters.h index 3628fb8..a038d40 100644 --- a/src/main/HyperParameters.h +++ b/src/main/HyperParameters.h @@ -1,5 +1,5 @@ -#ifndef HYPERPARAMETERS_H -#define HYPERPARAMETERS_H +#pragma once + #include #include #include @@ -20,4 +20,3 @@ namespace platform { std::map hyperparameters; }; } /* namespace platform */ -#endif /* HYPERPARAMETERS_H */ \ No newline at end of file diff --git a/src/main/Models.h b/src/main/Models.h index a0f526b..1719c92 100644 --- a/src/main/Models.h +++ b/src/main/Models.h @@ -1,5 +1,5 @@ -#ifndef MODELS_H -#define MODELS_H +#pragma once + #include #include #include @@ -39,4 +39,3 @@ namespace platform { Registrar(const std::string& className, function classFactoryFunction); }; } -#endif \ No newline at end of file diff --git a/src/main/Result.h b/src/main/Result.h index bbf0eec..8e79cef 100644 --- a/src/main/Result.h +++ b/src/main/Result.h @@ -1,5 +1,5 @@ -#ifndef RESULT_H -#define RESULT_H +#pragma once + #include #include #include @@ -48,4 +48,3 @@ namespace platform { double score = 0.0; }; }; -#endif \ No newline at end of file diff --git a/src/main/modelRegister.h b/src/main/modelRegister.h index bf69dd6..68fd1de 100644 --- a/src/main/modelRegister.h +++ b/src/main/modelRegister.h @@ -1,5 +1,5 @@ -#ifndef MODEL_REGISTER_H -#define MODEL_REGISTER_H +#pragma once + static platform::Registrar registrarT("TAN", [](void) -> bayesnet::BaseClassifier* { return new bayesnet::TAN();}); static platform::Registrar registrarTLD("TANLd", @@ -27,5 +27,4 @@ static platform::Registrar registrarSvc("SVC", static platform::Registrar registrarRaF("RandomForest", [](void) -> bayesnet::BaseClassifier* { return new pywrap::RandomForest();}); static platform::Registrar registrarXGB("XGBoost", - [](void) -> bayesnet::BaseClassifier* { return new pywrap::XGBoost();}); -#endif \ No newline at end of file + [](void) -> bayesnet::BaseClassifier* { return new pywrap::XGBoost();}); \ No newline at end of file diff --git a/src/manage/CommandParser.h b/src/manage/CommandParser.h index c34554b..65aa544 100644 --- a/src/manage/CommandParser.h +++ b/src/manage/CommandParser.h @@ -1,5 +1,5 @@ -#ifndef COMMAND_PARSER_H -#define COMMAND_PARSER_H +#pragma once + #include #include #include @@ -17,4 +17,3 @@ namespace platform { int index; }; } /* namespace platform */ -#endif /* COMMAND_PARSER_H */ \ No newline at end of file diff --git a/src/manage/ManageResults.cc b/src/manage/ManageResults.cc index c3b4299..973d626 100644 --- a/src/manage/ManageResults.cc +++ b/src/manage/ManageResults.cc @@ -12,7 +12,7 @@ namespace platform { 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; openExcel = false; diff --git a/src/manage/ManageResults.h b/src/manage/ManageResults.h index fc28cc9..394c9ec 100644 --- a/src/manage/ManageResults.h +++ b/src/manage/ManageResults.h @@ -1,7 +1,7 @@ -#ifndef MANAGE_RESULTS_H -#define MANAGE_RESULTS_H +#pragma once + #include -#include "Results.h" +#include "ResultsManager.h" namespace platform { class ManageResults { @@ -23,9 +23,7 @@ namespace platform { bool complete; bool partial; bool compare; - Results results; + ResultsManager results; lxw_workbook* workbook; }; } - -#endif /* MANAGE_RESULTS_H */ \ No newline at end of file diff --git a/src/manage/Results.cc b/src/manage/ResultsManager.cc similarity index 76% rename from src/manage/Results.cc rename to src/manage/ResultsManager.cc index 241bad6..e73e99b 100644 --- a/src/manage/Results.cc +++ b/src/manage/ResultsManager.cc @@ -1,9 +1,10 @@ #include -#include "Results.h" +#include "common/Paths.h" +#include "ResultsManager.h" namespace platform { - Results::Results(const std::string& path, const std::string& model, const std::string& score, bool complete, bool partial) : - path(path), model(model), scoreName(score), complete(complete), partial(partial) + ResultsManager::ResultsManager(const std::string& model, const std::string& score, bool complete, bool partial) : + path(Paths::results()), model(model), scoreName(score), complete(complete), partial(partial) { load(); if (!files.empty()) { @@ -12,7 +13,7 @@ namespace platform { maxModel = 0; } } - void Results::load() + void ResultsManager::load() { using std::filesystem::directory_iterator; 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(); rename((path + "/" + filename).c_str(), (pathHidden + "/" + filename).c_str()); files.erase(files.begin() + index); } - void Results::deleteResult(int index) + void ResultsManager::deleteResult(int index) { auto filename = files.at(index).getFilename(); remove((path + "/" + filename).c_str()); files.erase(files.begin() + index); } - int Results::size() const + int ResultsManager::size() const { return files.size(); } - void Results::sortDate() + void ResultsManager::sortDate() { sort(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getDate() > b.getDate(); }); } - void Results::sortModel() + void ResultsManager::sortModel() { sort(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getModel() > b.getModel(); }); } - void Results::sortDuration() + void ResultsManager::sortDuration() { sort(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getDuration() > b.getDuration(); }); } - void Results::sortScore() + void ResultsManager::sortScore() { sort(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getScore() > b.getScore(); }); } - bool Results::empty() const + bool ResultsManager::empty() const { return files.empty(); } diff --git a/src/manage/Results.h b/src/manage/ResultsManager.h similarity index 83% rename from src/manage/Results.h rename to src/manage/ResultsManager.h index d03c0e1..2e7c55b 100644 --- a/src/manage/Results.h +++ b/src/manage/ResultsManager.h @@ -1,5 +1,5 @@ -#ifndef RESULTS_H -#define RESULTS_H +#pragma once + #include #include #include @@ -7,9 +7,9 @@ #include "main/Result.h" namespace platform { using json = nlohmann::json; - class Results { + class ResultsManager { 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 sortScore(); void sortModel(); @@ -32,5 +32,4 @@ namespace platform { std::vector files; void load(); // Loads the list of results }; -}; -#endif \ No newline at end of file +}; \ No newline at end of file diff --git a/src/reports/ExcelFile.h b/src/reports/ExcelFile.h index 41c4e74..e930856 100644 --- a/src/reports/ExcelFile.h +++ b/src/reports/ExcelFile.h @@ -1,5 +1,5 @@ -#ifndef EXCELFILE_H -#define EXCELFILE_H +#pragma once + #include #include #include @@ -42,4 +42,3 @@ namespace platform { void setDefault(); }; } -#endif // !EXCELFILE_H \ No newline at end of file diff --git a/src/reports/ReportBase.h b/src/reports/ReportBase.h index 466ed30..9c1ac11 100644 --- a/src/reports/ReportBase.h +++ b/src/reports/ReportBase.h @@ -1,5 +1,5 @@ -#ifndef REPORTBASE_H -#define REPORTBASE_H +#pragma once + #include #include #include @@ -33,4 +33,3 @@ namespace platform { bool existBestFile = true; }; }; -#endif \ No newline at end of file diff --git a/src/reports/ReportConsole.h b/src/reports/ReportConsole.h index 5b0f846..07bdd36 100644 --- a/src/reports/ReportConsole.h +++ b/src/reports/ReportConsole.h @@ -1,5 +1,5 @@ -#ifndef REPORTCONSOLE_H -#define REPORTCONSOLE_H +#pragma once + #include #include "common/Colors.h" #include "ReportBase.h" @@ -19,4 +19,3 @@ namespace platform { void showSummary() override; }; }; -#endif \ No newline at end of file diff --git a/src/reports/ReportExcel.h b/src/reports/ReportExcel.h index 8940d6d..5bf7110 100644 --- a/src/reports/ReportExcel.h +++ b/src/reports/ReportExcel.h @@ -1,5 +1,5 @@ -#ifndef REPORTEXCEL_H -#define REPORTEXCEL_H +#pragma once + #include #include #include "common/Colors.h" @@ -22,4 +22,3 @@ namespace platform { void header_notes(int row); }; }; -#endif // !REPORTEXCEL_H \ No newline at end of file diff --git a/tests/TestUtils.h b/tests/TestUtils.h index 72954c0..39530ec 100644 --- a/tests/TestUtils.h +++ b/tests/TestUtils.h @@ -1,5 +1,5 @@ -#ifndef TEST_UTILS_H -#define TEST_UTILS_H +#pragma once + #include #include #include @@ -40,4 +40,3 @@ public: double epsilon = 1e-5; }; -#endif //TEST_UTILS_H \ No newline at end of file