diff --git a/CMakeLists.txt b/CMakeLists.txt index c53a3a2..a187279 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ endif (ENABLE_CLANG_TIDY) add_git_submodule("lib/mdlp") add_git_submodule("lib/argparse") add_git_submodule("lib/json") +add_git_submodule("lib/openXLSX") # Subdirectories # -------------- diff --git a/lib/openXLSX b/lib/openXLSX new file mode 160000 index 0000000..b80da42 --- /dev/null +++ b/lib/openXLSX @@ -0,0 +1 @@ +Subproject commit b80da42d1454f361c29117095ebe1989437db390 diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 78c6615..6cd1cf0 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -4,9 +4,9 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/Files) include_directories(${BayesNet_SOURCE_DIR}/lib/mdlp) include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include) include_directories(${BayesNet_SOURCE_DIR}/lib/json/include) -add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc Report.cc) -add_executable(manage manage.cc Results.cc Report.cc) +add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc ReportConsole.cc ReportBase.cc) +add_executable(manage manage.cc Results.cc ReportConsole.cc ReportBase.cc) add_executable(list list.cc platformUtils Datasets.cc) target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}") -target_link_libraries(manage "${TORCH_LIBRARIES}") +target_link_libraries(manage "${TORCH_LIBRARIES}" OpenXLSX::OpenXLSX) target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/src/Platform/Experiment.cc b/src/Platform/Experiment.cc index 88e3125..480a9de 100644 --- a/src/Platform/Experiment.cc +++ b/src/Platform/Experiment.cc @@ -1,7 +1,7 @@ #include "Experiment.h" #include "Datasets.h" #include "Models.h" -#include "Report.h" +#include "ReportConsole.h" namespace platform { using json = nlohmann::json; @@ -91,7 +91,7 @@ namespace platform { void Experiment::report() { json data = build_json(); - Report report(data); + ReportConsole report(data); report.show(); } diff --git a/src/Platform/Report.h b/src/Platform/Report.h deleted file mode 100644 index 105785f..0000000 --- a/src/Platform/Report.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef REPORT_H -#define REPORT_H -#include -#include -#include -#include "Colors.h" - -using json = nlohmann::json; -const int MAXL = 128; -namespace platform { - using namespace std; - class Report { - public: - explicit Report(json data_) { data = data_; }; - virtual ~Report() = default; - void show(); - private: - void header(); - void body(); - void footer(); - string fromVector(const string& key); - json data; - double totalScore; // Total score of all results in a report - }; -}; -#endif \ No newline at end of file diff --git a/src/Platform/ReportBase.cc b/src/Platform/ReportBase.cc new file mode 100644 index 0000000..f22a89f --- /dev/null +++ b/src/Platform/ReportBase.cc @@ -0,0 +1,38 @@ +#include +#include +#include "ReportBase.h" +#include "BestResult.h" + + +namespace platform { + string ReportBase::fromVector(const string& key) + { + stringstream oss; + string sep = ""; + oss << "["; + for (auto& item : data[key]) { + oss << sep << item.get(); + sep = ", "; + } + oss << "]"; + return oss.str(); + } + string ReportBase::fVector(const string& title, const json& data, const int width, const int precision) + { + stringstream oss; + string sep = ""; + oss << title << "["; + for (const auto& item : data) { + oss << sep << fixed << setw(width) << setprecision(precision) << item.get(); + sep = ", "; + } + oss << "]"; + return oss.str(); + } + void ReportBase::show() + { + header(); + body(); + footer(); + } +} \ No newline at end of file diff --git a/src/Platform/ReportBase.h b/src/Platform/ReportBase.h new file mode 100644 index 0000000..2d8a072 --- /dev/null +++ b/src/Platform/ReportBase.h @@ -0,0 +1,25 @@ +#ifndef REPORTBASE_H +#define REPORTBASE_H +#include +#include +#include + +using json = nlohmann::json; +namespace platform { + using namespace std; + class ReportBase { + public: + explicit ReportBase(json data_) { data = data_; }; + virtual ~ReportBase() = default; + void show(); + protected: + json data; + double totalScore; // Total score of all results in a report + string fromVector(const string& key); + string fVector(const string& title, const json& data, const int width, const int precision); + virtual void header() = 0; + virtual void body() = 0; + virtual void footer() = 0; + }; +}; +#endif \ No newline at end of file diff --git a/src/Platform/Report.cc b/src/Platform/ReportConsole.cc similarity index 83% rename from src/Platform/Report.cc rename to src/Platform/ReportConsole.cc index 5690668..52f822d 100644 --- a/src/Platform/Report.cc +++ b/src/Platform/ReportConsole.cc @@ -1,52 +1,23 @@ #include #include -#include "Report.h" +#include "ReportConsole.h" #include "BestResult.h" namespace platform { + struct separated : numpunct { + char do_decimal_point() const { return ','; } + char do_thousands_sep() const { return '.'; } + string do_grouping() const { return "\03"; } + }; string headerLine(const string& text) { int n = MAXL - text.length() - 3; n = n < 0 ? 0 : n; return "* " + text + string(n, ' ') + "*\n"; } - string Report::fromVector(const string& key) - { - stringstream oss; - string sep = ""; - oss << "["; - for (auto& item : data[key]) { - oss << sep << item.get(); - sep = ", "; - } - oss << "]"; - return oss.str(); - } - string fVector(const string& title, const json& data, const int width, const int precision) - { - stringstream oss; - string sep = ""; - oss << title << "["; - for (const auto& item : data) { - oss << sep << fixed << setw(width) << setprecision(precision) << item.get(); - sep = ", "; - } - oss << "]"; - return oss.str(); - } - void Report::show() - { - header(); - body(); - footer(); - } - struct separated : numpunct { - char do_decimal_point() const { return ','; } - char do_thousands_sep() const { return '.'; } - string do_grouping() const { return "\03"; } - }; - void Report::header() + + void ReportConsole::header() { locale mylocale(cout.getloc(), new separated); locale::global(mylocale); @@ -62,7 +33,7 @@ namespace platform { cout << string(MAXL, '*') << endl; cout << endl; } - void Report::body() + void ReportConsole::body() { cout << Colors::GREEN() << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl; cout << "============================== ====== ===== === ========= ========= ========= =============== ================== ===============" << endl; @@ -100,7 +71,7 @@ namespace platform { cout << string(MAXL, '*') << endl; } } - void Report::footer() + void ReportConsole::footer() { cout << Colors::MAGENTA() << string(MAXL, '*') << endl; auto score = data["score_name"].get(); @@ -110,6 +81,5 @@ namespace platform { cout << headerLine(oss.str()); } cout << string(MAXL, '*') << endl << Colors::RESET(); - } } \ No newline at end of file diff --git a/src/Platform/ReportConsole.h b/src/Platform/ReportConsole.h new file mode 100644 index 0000000..d09f5e1 --- /dev/null +++ b/src/Platform/ReportConsole.h @@ -0,0 +1,24 @@ +#ifndef REPORTCONSOLE_H +#define REPORTCONSOLE_H +#include +#include +#include +#include "ReportBase.h" +#include "Colors.h" + +using json = nlohmann::json; +const int MAXL = 128; +namespace platform { + using namespace std; + class ReportConsole : public ReportBase{ + public: + explicit ReportConsole(json data_) : ReportBase(data_) {}; + virtual ~ReportConsole() = default; + private: + + void header() override; + void body() override; + void footer() override; + }; +}; +#endif \ No newline at end of file diff --git a/src/Platform/ReportExcel.h b/src/Platform/ReportExcel.h new file mode 100644 index 0000000..9cb4313 --- /dev/null +++ b/src/Platform/ReportExcel.h @@ -0,0 +1,16 @@ +#ifndef REPORTEXCEL_H +#define REPORTEXCEL_H +#include "ReportBase.h" +namespace platform { + using namespace std; + class ReportExcel : public ReportBase{ + public: + explicit ReportExcel(json data_) : ReportBase(data_) {}; + virtual ~ReportExcel() = default; + private: + void header() override; + void body() override; + void footer() override; + }; +}; +#endif // !REPORTEXCEL_H \ No newline at end of file diff --git a/src/Platform/Results.cc b/src/Platform/Results.cc index 818f51e..7c19871 100644 --- a/src/Platform/Results.cc +++ b/src/Platform/Results.cc @@ -1,7 +1,7 @@ #include #include "platformUtils.h" #include "Results.h" -#include "Report.h" +#include "ReportConsole.h" #include "BestResult.h" #include "Colors.h" namespace platform { @@ -98,7 +98,7 @@ namespace platform { { cout << Colors::YELLOW() << "Reporting " << files.at(index).getFilename() << endl; auto data = files.at(index).load(); - Report report(data); + ReportConsole report(data); report.show(); } void Results::menu()