diff --git a/src/Platform/BestResults.cc b/src/Platform/BestResults.cc index 5c06eb6..b0e75f7 100644 --- a/src/Platform/BestResults.cc +++ b/src/Platform/BestResults.cc @@ -1,9 +1,8 @@ #include #include #include -#include "platformUtils.h" #include "BestResults.h" -#include "Results.h" +#include "Result.h" #include "Colors.h" namespace platform { @@ -33,7 +32,8 @@ namespace platform { } } string bestFileName = path + "/" + bestResultFile(); - if (file_exists(bestFileName)) { + if (FILE* fileTest = fopen(bestFileName.c_str(), "r")) { + fclose(fileTest); cout << Colors::MAGENTA() << "File " << bestFileName << " already exists and it shall be overwritten." << Colors::RESET(); } ofstream file(bestFileName); diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index c87fb7f..b40a311 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -6,15 +6,14 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include) include_directories(${BayesNet_SOURCE_DIR}/lib/json/include) include_directories(${BayesNet_SOURCE_DIR}/lib/libxlsxwriter/include) 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 ReportExcel.cc ReportBase.cc Datasets.cc platformUtils.cc) +add_executable(manage manage.cc Results.cc Result.cc ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc platformUtils.cc) add_executable(list list.cc platformUtils Datasets.cc) -add_executable(best best.cc BestResults.cc Results.cc ReportBase.cc ReportExcel.cc platformUtils.cc) +add_executable(best best.cc BestResults.cc Result.cc) target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}") if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux") target_link_libraries(manage "${TORCH_LIBRARIES}" libxlsxwriter.so ArffFiles mdlp stdc++fs) - target_link_libraries(best "${TORCH_LIBRARIES}" libxlsxwriter.so stdc++fs) + target_link_libraries(best stdc++fs) else() target_link_libraries(manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp) - target_link_libraries(best "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}") endif() target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/src/Platform/Result.cc b/src/Platform/Result.cc new file mode 100644 index 0000000..a438238 --- /dev/null +++ b/src/Platform/Result.cc @@ -0,0 +1,50 @@ +#include +#include +#include "Result.h" +#include "Colors.h" +#include "BestScore.h" +namespace platform { + Result::Result(const string& path, const string& filename) + : path(path) + , filename(filename) + { + auto data = load(); + date = data["date"]; + score = 0; + for (const auto& result : data["results"]) { + score += result["score"].get(); + } + scoreName = data["score_name"]; + if (scoreName == BestScore::scoreName()) { + score /= BestScore::score(); + } + title = data["title"]; + duration = data["duration"]; + model = data["model"]; + complete = data["results"].size() > 1; + } + + json Result::load() const + { + ifstream resultData(path + "/" + filename); + if (resultData.is_open()) { + json data = json::parse(resultData); + return data; + } + throw invalid_argument("Unable to open result file. [" + path + "/" + filename + "]"); + } + + string Result::to_string() const + { + stringstream oss; + oss << date << " "; + oss << setw(12) << left << model << " "; + oss << setw(11) << left << scoreName << " "; + oss << right << setw(11) << setprecision(7) << fixed << score << " "; + auto completeString = isComplete() ? "C" : "P"; + oss << setw(1) << " " << completeString << " "; + oss << setw(9) << setprecision(3) << fixed << duration << " "; + oss << setw(50) << left << title << " "; + return oss.str(); + } +} \ No newline at end of file diff --git a/src/Platform/Result.h b/src/Platform/Result.h new file mode 100644 index 0000000..76a47d2 --- /dev/null +++ b/src/Platform/Result.h @@ -0,0 +1,37 @@ +#ifndef RESULT_H +#define RESULT_H +#include +#include +#include +#include +namespace platform { + using namespace std; + using json = nlohmann::json; + + class Result { + public: + Result(const string& path, const string& filename); + json load() const; + string to_string() const; + string getFilename() const { return filename; }; + string getDate() const { return date; }; + double getScore() const { return score; }; + string getTitle() const { return title; }; + double getDuration() const { return duration; }; + string getModel() const { return model; }; + string getScoreName() const { return scoreName; }; + bool isComplete() const { return complete; }; + private: + string path; + string filename; + string date; + double score; + string title; + double duration; + string model; + string scoreName; + bool complete; + }; +}; + +#endif \ No newline at end of file diff --git a/src/Platform/Results.cc b/src/Platform/Results.cc index 51ecc87..f5e3481 100644 --- a/src/Platform/Results.cc +++ b/src/Platform/Results.cc @@ -6,34 +6,6 @@ #include "BestScore.h" #include "Colors.h" namespace platform { - Result::Result(const string& path, const string& filename) - : path(path) - , filename(filename) - { - auto data = load(); - date = data["date"]; - score = 0; - for (const auto& result : data["results"]) { - score += result["score"].get(); - } - scoreName = data["score_name"]; - if (scoreName == BestScore::scoreName()) { - score /= BestScore::score(); - } - title = data["title"]; - duration = data["duration"]; - model = data["model"]; - complete = data["results"].size() > 1; - } - json Result::load() const - { - ifstream resultData(path + "/" + filename); - if (resultData.is_open()) { - json data = json::parse(resultData); - return data; - } - throw invalid_argument("Unable to open result file. [" + path + "/" + filename + "]"); - } void Results::load() { using std::filesystem::directory_iterator; @@ -52,19 +24,6 @@ namespace platform { max = files.size(); } } - string Result::to_string() const - { - stringstream oss; - oss << date << " "; - oss << setw(12) << left << model << " "; - oss << setw(11) << left << scoreName << " "; - oss << right << setw(11) << setprecision(7) << fixed << score << " "; - auto completeString = isComplete() ? "C" : "P"; - oss << setw(1) << " " << completeString << " "; - oss << setw(9) << setprecision(3) << fixed << duration << " "; - oss << setw(50) << left << title << " "; - return oss.str(); - } void Results::show() const { cout << Colors::GREEN() << "Results found: " << files.size() << endl; diff --git a/src/Platform/Results.h b/src/Platform/Results.h index 60748ba..b322cfb 100644 --- a/src/Platform/Results.h +++ b/src/Platform/Results.h @@ -5,34 +5,11 @@ #include #include #include +#include "Result.h" namespace platform { using namespace std; using json = nlohmann::json; - class Result { - public: - Result(const string& path, const string& filename); - json load() const; - string to_string() const; - string getFilename() const { return filename; }; - string getDate() const { return date; }; - double getScore() const { return score; }; - string getTitle() const { return title; }; - double getDuration() const { return duration; }; - string getModel() const { return model; }; - string getScoreName() const { return scoreName; }; - bool isComplete() const { return complete; }; - private: - string path; - string filename; - string date; - double score; - string title; - double duration; - string model; - string scoreName; - bool complete; - }; class Results { public: Results(const string& path, const int max, const string& model, const string& score, bool complete, bool partial, bool compare) :