diff --git a/.vscode/launch.json b/.vscode/launch.json index ba01ca6..0a7a483 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -34,6 +34,17 @@ ], "cwd": "/Users/rmontanana/Code/discretizbench", }, + { + "type": "lldb", + "request": "launch", + "name": "manage", + "program": "${workspaceFolder}/build/src/Platform/manage", + "args": [ + "-n", + "20" + ], + "cwd": "/Users/rmontanana/Code/discretizbench", + }, { "name": "Build & debug active file", "type": "cppdbg", diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 3b13abc..0eb26ce 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -5,4 +5,6 @@ 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) -target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}") \ No newline at end of file +add_executable(manage manage.cc Results.cc Report.cc) +target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}") +target_link_libraries(manage "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/src/Platform/Results.cc b/src/Platform/Results.cc new file mode 100644 index 0000000..ee5315b --- /dev/null +++ b/src/Platform/Results.cc @@ -0,0 +1,60 @@ +#include +#include "platformUtils.h" +#include "Results.h" +namespace platform { + const double REFERENCE_SCORE = 22.109799; + 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(); + } + score /= REFERENCE_SCORE; + title = data["title"]; + duration = data["duration"]; + model = data["model"]; + } + json Result::load() + { + 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; + for (const auto& file : directory_iterator(path)) { + auto filename = file.path().filename().string(); + if (filename.find(".json") != string::npos && filename.find("results_") == 0) { + auto result = Result(path, filename); + files.push_back(result); + } + } + } + string Result::to_string() const + { + stringstream oss; + oss << date << " "; + oss << setw(12) << left << model << " "; + oss << right << setw(9) << setprecision(7) << fixed << score << " "; + oss << setw(9) << setprecision(3) << fixed << duration << " "; + oss << setw(50) << left << title << " "; + return oss.str(); + } + void Results::manage() + { + cout << "Results found: " << files.size() << endl; + cout << "========================" << endl; + for (const auto& result : files) { + cout << result.to_string() << endl; + } + } + +} \ No newline at end of file diff --git a/src/Platform/Results.h b/src/Platform/Results.h new file mode 100644 index 0000000..5d36f32 --- /dev/null +++ b/src/Platform/Results.h @@ -0,0 +1,38 @@ +#ifndef RESULTS_H +#define RESULTS_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(); + string to_string() const; + private: + string path; + string filename; + string date; + double score; + string title; + double duration; + string model; + }; + class Results { + public: + explicit Results(const string& path) : path(path) { load(); }; + void manage(); + private: + string path; + vector files; + void load(); // Loads the list of results + void show(); + int menu(); + }; +}; + +#endif \ No newline at end of file diff --git a/src/Platform/main.cc b/src/Platform/main.cc index 24d0a33..7692629 100644 --- a/src/Platform/main.cc +++ b/src/Platform/main.cc @@ -14,7 +14,7 @@ const string PATH_DATASETS = "datasets"; argparse::ArgumentParser manageArguments(int argc, char** argv) { auto env = platform::DotEnv(); - argparse::ArgumentParser program("BayesNetSample"); + argparse::ArgumentParser program("main"); program.add_argument("-d", "--dataset").default_value("").help("Dataset file name"); program.add_argument("-p", "--path") .help("folder where the data files are located, default") diff --git a/src/Platform/manage.cc b/src/Platform/manage.cc new file mode 100644 index 0000000..b901601 --- /dev/null +++ b/src/Platform/manage.cc @@ -0,0 +1,32 @@ +#include +#include +#include "platformUtils.h" +#include "Results.h" + +using namespace std; +const string PATH_RESULTS = "results"; + +argparse::ArgumentParser manageArguments(int argc, char** argv) +{ + argparse::ArgumentParser program("manage"); + program.add_argument("-n", "--number").default_value(0).help("Number of results to show (0 = all)").scan<'i', int>(); + try { + program.parse_args(argc, argv); + auto number = program.get("number"); + } + catch (const exception& err) { + cerr << err.what() << endl; + cerr << program; + exit(1); + } + return program; +} + +int main(int argc, char** argv) +{ + auto program = manageArguments(argc, argv); + auto number = program.get("number"); + auto results = platform::Results(PATH_RESULTS); + results.manage(); + return 0; +}