Summary list

This commit is contained in:
Ricardo Montañana Gómez 2023-08-13 16:19:17 +02:00
parent 90c92e5c56
commit 2729b92f06
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
6 changed files with 145 additions and 2 deletions

11
.vscode/launch.json vendored
View File

@ -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",

View File

@ -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}")
add_executable(manage manage.cc Results.cc Report.cc)
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
target_link_libraries(manage "${TORCH_LIBRARIES}")

60
src/Platform/Results.cc Normal file
View File

@ -0,0 +1,60 @@
#include <filesystem>
#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<double>();
}
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;
}
}
}

38
src/Platform/Results.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef RESULTS_H
#define RESULTS_H
#include <map>
#include <vector>
#include <string>
#include <nlohmann/json.hpp>
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<Result> files;
void load(); // Loads the list of results
void show();
int menu();
};
};
#endif

View File

@ -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")

32
src/Platform/manage.cc Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include <argparse/argparse.hpp>
#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<int>("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<int>("number");
auto results = platform::Results(PATH_RESULTS);
results.manage();
return 0;
}