diff --git a/src/Platform/Paths.h b/src/Platform/Paths.h new file mode 100644 index 0000000..756e61a --- /dev/null +++ b/src/Platform/Paths.h @@ -0,0 +1,10 @@ +#ifndef PATHS_H +#define PATHS_H +namespace platform { + class Paths { + public: + static std::string datasets() { return "datasets/"; } + static std::string results() { return "results/"; } + }; +} +#endif \ No newline at end of file diff --git a/src/Platform/Results.cc b/src/Platform/Results.cc index c33cf37..48c7e9a 100644 --- a/src/Platform/Results.cc +++ b/src/Platform/Results.cc @@ -22,7 +22,7 @@ namespace platform { duration = data["duration"]; model = data["model"]; } - json Result::load() + json Result::load() const { ifstream resultData(path + "/" + filename); if (resultData.is_open()) { @@ -70,7 +70,6 @@ namespace platform { if (i == max && max != 0) { break; } - } } int Results::getIndex(const string& intent) const @@ -81,70 +80,98 @@ namespace platform { if (index >= 0 && index < files.size()) { return index; } - cout << "Invalid index" << endl; return -1; } + void Results::report(const int index) const + { + cout << "Reporting " << files.at(index).getFilename() << endl; + auto data = files.at(index).load(); + Report report(data); + report.show(); + } void Results::menu() { - cout << "Choose option (quit='q', list='l', delete='d', hide='h', sort='s', report='r'): "; char option; int index; - string filename; - cin >> option; - switch (option) { - case 'q': - exit(0); - case 'l': - show(); - menu(); - break; - case 'd': - index = getIndex("delete"); - if (index == -1) + bool finished = false; + string filename, line, options = "qldhsr"; + while (!finished) { + cout << "Choose option (quit='q', list='l', delete='d', hide='h', sort='s', report='r'): "; + getline(cin, line); + if (line.size() == 0) + continue; + if (options.find(line[0]) != string::npos) { + if (line.size() > 1) { + cout << "Invalid option" << endl; + continue; + } + option = line[0]; + } else { + index = stoi(line); + if (index >= 0 && index < files.size()) { + report(index); + } else { + cout << "Invalid option" << endl; + } + continue; + } + switch (option) { + case 'q': + finished = true; break; - filename = files[index].getFilename(); - cout << "Deleting " << filename << endl; - remove((path + "/" + filename).c_str()); - files.erase(files.begin() + index); - show(); - menu(); - break; - case 'h': - index = getIndex("hide"); - if (index == -1) + case 'l': + show(); break; - filename = files[index].getFilename(); - cout << "Hiding " << filename << endl; - rename((path + "/" + filename).c_str(), (path + "/." + filename).c_str()); - files.erase(files.begin() + index); - show(); - menu(); - break; - case 's': - sortList(); - show(); - menu(); - break; - case 'r': - index = getIndex("report"); - if (index == -1) + case 'd': + index = getIndex("delete"); + if (index == -1) + break; + filename = files[index].getFilename(); + cout << "Deleting " << filename << endl; + remove((path + "/" + filename).c_str()); + files.erase(files.begin() + index); + show(); break; - filename = files[index].getFilename(); - cout << "Reporting " << filename << endl; - auto data = files[index].load(); - Report report(data); - report.show(); - menu(); - break; - + case 'h': + index = getIndex("hide"); + if (index == -1) + break; + filename = files[index].getFilename(); + cout << "Hiding " << filename << endl; + rename((path + "/" + filename).c_str(), (path + "/." + filename).c_str()); + files.erase(files.begin() + index); + show(); + menu(); + break; + case 's': + sortList(); + show(); + break; + case 'r': + index = getIndex("report"); + if (index == -1) + break; + report(index); + break; + default: + cout << "Invalid option" << endl; + } } } void Results::sortList() { cout << "Choose sorting field (date='d', score='s', duration='u', model='m'): "; + string line; char option; - cin >> option; + getline(cin, line); + if (line.size() == 0) + return; + if (line.size() > 1) { + cout << "Invalid option" << endl; + return; + } + option = line[0]; switch (option) { case 'd': sortDate(); @@ -161,7 +188,6 @@ namespace platform { default: cout << "Invalid option" << endl; } - } void Results::sortDate() { @@ -195,6 +221,7 @@ namespace platform { } show(); menu(); + cout << "Done!" << endl; } } \ No newline at end of file diff --git a/src/Platform/Results.h b/src/Platform/Results.h index bd4768b..e6b1552 100644 --- a/src/Platform/Results.h +++ b/src/Platform/Results.h @@ -11,7 +11,7 @@ namespace platform { class Result { public: Result(const string& path, const string& filename); - json load(); + json load() const; string to_string() const; string getFilename() const { return filename; }; string getDate() const { return date; }; @@ -42,6 +42,7 @@ namespace platform { vector files; void load(); // Loads the list of results void show() const; + void report(const int index) const; int getIndex(const string& intent) const; void menu(); void sortList(); diff --git a/src/Platform/main.cc b/src/Platform/main.cc index 7692629..0618c89 100644 --- a/src/Platform/main.cc +++ b/src/Platform/main.cc @@ -6,10 +6,10 @@ #include "DotEnv.h" #include "Models.h" #include "modelRegister.h" +#include "Paths.h" + using namespace std; -const string PATH_RESULTS = "results"; -const string PATH_DATASETS = "datasets"; argparse::ArgumentParser manageArguments(int argc, char** argv) { @@ -18,8 +18,7 @@ argparse::ArgumentParser manageArguments(int argc, char** argv) 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") - .default_value(string{ PATH_DATASETS } - ); + .default_value(string{ platform::Paths::datasets() }); program.add_argument("-m", "--model") .help("Model to use " + platform::Models::instance()->toString()) .action([](const std::string& value) { @@ -115,7 +114,7 @@ int main(int argc, char** argv) experiment.go(filesToTest, path); experiment.setDuration(timer.getDuration()); if (saveResults) - experiment.save(PATH_RESULTS); + experiment.save(platform::Paths::results()); else experiment.report(); cout << "Done!" << endl; diff --git a/src/Platform/manage.cc b/src/Platform/manage.cc index 74e4a2c..34e66cd 100644 --- a/src/Platform/manage.cc +++ b/src/Platform/manage.cc @@ -1,10 +1,10 @@ #include #include #include "platformUtils.h" +#include "Paths.h" #include "Results.h" using namespace std; -const string PATH_RESULTS = "results"; argparse::ArgumentParser manageArguments(int argc, char** argv) { @@ -35,7 +35,7 @@ int main(int argc, char** argv) auto number = program.get("number"); auto model = program.get("model"); auto score = program.get("score"); - auto results = platform::Results(PATH_RESULTS, number, model, score); + auto results = platform::Results(platform::Paths::results(), number, model, score); results.manage(); return 0; } diff --git a/src/Platform/platformUtils.cc b/src/Platform/platformUtils.cc index 6fca9d9..74e97fd 100644 --- a/src/Platform/platformUtils.cc +++ b/src/Platform/platformUtils.cc @@ -1,4 +1,5 @@ #include "platformUtils.h" +#include "Paths.h" using namespace torch; @@ -85,7 +86,7 @@ tuple, string, map>> loadData tuple>, vector, vector, string, map>> loadFile(const string& name) { auto handler = ArffFiles(); - handler.load(PATH + static_cast(name) + ".arff"); + handler.load(platform::Paths::datasets() + static_cast(name) + ".arff"); // Get Dataset X, y vector& X = handler.getX(); mdlp::labels_t& y = handler.getY();