From 64fc7bd9ddcd4251f7fe6b498b9123d2a8fb05db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Tue, 5 Sep 2023 09:26:49 +0200 Subject: [PATCH] Add show dataset detail in report --- src/Platform/ReportConsole.cc | 19 +++++++++++++------ src/Platform/ReportConsole.h | 7 ++++--- src/Platform/Results.cc | 30 +++++++++++++++++++++++++++--- src/Platform/Results.h | 2 ++ 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/Platform/ReportConsole.cc b/src/Platform/ReportConsole.cc index 2e3ed0c..acbb602 100644 --- a/src/Platform/ReportConsole.cc +++ b/src/Platform/ReportConsole.cc @@ -10,14 +10,14 @@ namespace platform { char do_thousands_sep() const { return '.'; } string do_grouping() const { return "\03"; } }; - + string ReportConsole::headerLine(const string& text) { int n = MAXL - text.length() - 3; n = n < 0 ? 0 : n; return "* " + text + string(n, ' ') + "*\n"; } - + void ReportConsole::header() { locale mylocale(cout.getloc(), new separated); @@ -36,14 +36,21 @@ namespace platform { } void ReportConsole::body() { - cout << Colors::GREEN() << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl; - cout << "============================== ====== ===== === ========= ========= ========= =============== ================== ===============" << endl; + cout << Colors::GREEN() << " # Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl; + cout << "=== ============================== ====== ===== === ========= ========= ========= =============== ================== ===============" << endl; json lastResult; double totalScore = 0.0; bool odd = true; + int index = 0; for (const auto& r : data["results"]) { + if (selectedIndex != -1 && index != selectedIndex) { + index++; + continue; + } auto color = odd ? Colors::CYAN() : Colors::BLUE(); - cout << color << setw(30) << left << r["dataset"].get() << " "; + cout << color; + cout << setw(3) << index++ << " "; + cout << setw(30) << left << r["dataset"].get() << " "; cout << setw(6) << right << r["samples"].get() << " "; cout << setw(5) << right << r["features"].get() << " "; cout << setw(3) << right << r["classes"].get() << " "; @@ -63,7 +70,7 @@ namespace platform { totalScore += r["score"].get(); odd = !odd; } - if (data["results"].size() == 1) { + if (data["results"].size() == 1 || selectedIndex != -1) { cout << string(MAXL, '*') << endl; cout << headerLine(fVector("Train scores: ", lastResult["scores_train"], 14, 12)); cout << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12)); diff --git a/src/Platform/ReportConsole.h b/src/Platform/ReportConsole.h index 5c795b7..b34e71f 100644 --- a/src/Platform/ReportConsole.h +++ b/src/Platform/ReportConsole.h @@ -7,12 +7,13 @@ namespace platform { using namespace std; - const int MAXL = 128; - class ReportConsole : public ReportBase{ + const int MAXL = 132; + class ReportConsole : public ReportBase { public: - explicit ReportConsole(json data_) : ReportBase(data_) {}; + explicit ReportConsole(json data_, int index = -1) : ReportBase(data_), selectedIndex(index) {}; virtual ~ReportConsole() = default; private: + int selectedIndex; string headerLine(const string& text); void header() override; void body() override; diff --git a/src/Platform/Results.cc b/src/Platform/Results.cc index a32f715..5ebb08a 100644 --- a/src/Platform/Results.cc +++ b/src/Platform/Results.cc @@ -110,6 +110,17 @@ namespace platform { reporter.show(); } } + void Results::showIndex(const int index, const int idx) const + { + auto data = files.at(index).load(); + if (idx < 0 or idx >= static_cast(data["results"].size())) { + cout << "Invalid index" << endl; + return; + } + cout << Colors::YELLOW() << "Showing " << files.at(index).getFilename() << endl; + ReportConsole reporter(data, idx); + reporter.show(); + } void Results::menu() { char option; @@ -129,9 +140,16 @@ namespace platform { option = line[0]; } else { if (all_of(line.begin(), line.end(), ::isdigit)) { - index = stoi(line); - if (index >= 0 && index < files.size()) { - report(index, false); + int idx = stoi(line); + if (indexList) { + index = idx; + if (index >= 0 && index < files.size()) { + report(index, false); + indexList = false; + continue; + } + } else { + showIndex(index, idx); continue; } } @@ -144,6 +162,7 @@ namespace platform { break; case 'l': show(); + indexList = true; break; case 'd': index = getIndex("delete"); @@ -155,6 +174,7 @@ namespace platform { files.erase(files.begin() + index); cout << "File: " + filename + " deleted!" << endl; show(); + indexList = true; break; case 'h': index = getIndex("hide"); @@ -166,21 +186,25 @@ namespace platform { files.erase(files.begin() + index); show(); menu(); + indexList = true; break; case 's': sortList(); + indexList = true; show(); break; case 'r': index = getIndex("report"); if (index == -1) break; + indexList = false; report(index, false); break; case 'e': index = getIndex("excel"); if (index == -1) break; + indexList = true; report(index, true); break; default: diff --git a/src/Platform/Results.h b/src/Platform/Results.h index 57e240f..bb9c68f 100644 --- a/src/Platform/Results.h +++ b/src/Platform/Results.h @@ -42,10 +42,12 @@ namespace platform { string model; string scoreName; bool complete; + bool indexList = true; vector files; void load(); // Loads the list of results void show() const; void report(const int index, const bool excelReport) const; + void showIndex(const int index, const int idx) const; int getIndex(const string& intent) const; void menu(); void sortList();