Add class Paths and enhance input
This commit is contained in:
parent
3691cb4a61
commit
55d21294d5
10
src/Platform/Paths.h
Normal file
10
src/Platform/Paths.h
Normal file
@ -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
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<Result> 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();
|
||||
|
@ -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;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <argparse/argparse.hpp>
|
||||
#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<int>("number");
|
||||
auto model = program.get<string>("model");
|
||||
auto score = program.get<string>("score");
|
||||
auto results = platform::Results(PATH_RESULTS, number, model, score);
|
||||
auto results = platform::Results(platform::Paths::results(), number, model, score);
|
||||
results.manage();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "platformUtils.h"
|
||||
#include "Paths.h"
|
||||
|
||||
using namespace torch;
|
||||
|
||||
@ -85,7 +86,7 @@ tuple<Tensor, Tensor, vector<string>, string, map<string, vector<int>>> loadData
|
||||
tuple<vector<vector<int>>, vector<int>, vector<string>, string, map<string, vector<int>>> loadFile(const string& name)
|
||||
{
|
||||
auto handler = ArffFiles();
|
||||
handler.load(PATH + static_cast<string>(name) + ".arff");
|
||||
handler.load(platform::Paths::datasets() + static_cast<string>(name) + ".arff");
|
||||
// Get Dataset X, y
|
||||
vector<mdlp::samples_t>& X = handler.getX();
|
||||
mdlp::labels_t& y = handler.getY();
|
||||
|
Loading…
Reference in New Issue
Block a user