Add colors and enhace input control
This commit is contained in:
parent
55d21294d5
commit
2a3fc9aa45
14
src/Platform/Colors.h
Normal file
14
src/Platform/Colors.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef COLORS_H
|
||||||
|
#define COLORS_H
|
||||||
|
class Colors {
|
||||||
|
public:
|
||||||
|
static std::string MAGENTA() { return "\033[1;35m"; }
|
||||||
|
static std::string BLUE() { return "\033[1;34m"; }
|
||||||
|
static std::string CYAN() { return "\033[1;36m"; }
|
||||||
|
static std::string GREEN() { return "\033[1;32m"; }
|
||||||
|
static std::string YELLOW() { return "\033[1;33m"; }
|
||||||
|
static std::string RED() { return "\033[1;31m"; }
|
||||||
|
static std::string WHITE() { return "\033[1;37m"; }
|
||||||
|
static std::string RESET() { return "\033[0m"; }
|
||||||
|
};
|
||||||
|
#endif // COLORS_H
|
@ -33,7 +33,7 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void Report::header()
|
void Report::header()
|
||||||
{
|
{
|
||||||
cout << string(MAXL, '*') << endl;
|
cout << Colors::MAGENTA() << string(MAXL, '*') << endl;
|
||||||
cout << headerLine("Report " + data["model"].get<string>() + " ver. " + data["version"].get<string>() + " with " + to_string(data["folds"].get<int>()) + " Folds cross validation and " + to_string(data["seeds"].size()) + " random seeds. " + data["date"].get<string>() + " " + data["time"].get<string>());
|
cout << headerLine("Report " + data["model"].get<string>() + " ver. " + data["version"].get<string>() + " with " + to_string(data["folds"].get<int>()) + " Folds cross validation and " + to_string(data["seeds"].size()) + " random seeds. " + data["date"].get<string>() + " " + data["time"].get<string>());
|
||||||
cout << headerLine(data["title"].get<string>());
|
cout << headerLine(data["title"].get<string>());
|
||||||
cout << headerLine("Random seeds: " + fromVector("seeds") + " Stratified: " + (data["stratified"].get<bool>() ? "True" : "False"));
|
cout << headerLine("Random seeds: " + fromVector("seeds") + " Stratified: " + (data["stratified"].get<bool>() ? "True" : "False"));
|
||||||
@ -44,24 +44,32 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void Report::body()
|
void Report::body()
|
||||||
{
|
{
|
||||||
cout << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl;
|
cout << Colors::GREEN() << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl;
|
||||||
cout << "============================== ====== ===== === ======= ======= ======= =============== ================= ===============" << endl;
|
cout << "============================== ====== ===== === ======= ======= ======= =============== ================== ===============" << endl;
|
||||||
json lastResult;
|
json lastResult;
|
||||||
totalScore = 0;
|
totalScore = 0;
|
||||||
|
bool odd = true;
|
||||||
for (const auto& r : data["results"]) {
|
for (const auto& r : data["results"]) {
|
||||||
cout << setw(30) << left << r["dataset"].get<string>() << " ";
|
auto color = odd ? Colors::CYAN() : Colors::BLUE();
|
||||||
|
cout << color << setw(30) << left << r["dataset"].get<string>() << " ";
|
||||||
cout << setw(6) << right << r["samples"].get<int>() << " ";
|
cout << setw(6) << right << r["samples"].get<int>() << " ";
|
||||||
cout << setw(5) << right << r["features"].get<int>() << " ";
|
cout << setw(5) << right << r["features"].get<int>() << " ";
|
||||||
cout << setw(3) << right << r["classes"].get<int>() << " ";
|
cout << setw(3) << right << r["classes"].get<int>() << " ";
|
||||||
cout << setw(7) << setprecision(2) << fixed << r["nodes"].get<float>() << " ";
|
cout << setw(7) << setprecision(2) << fixed << r["nodes"].get<float>() << " ";
|
||||||
cout << setw(7) << setprecision(2) << fixed << r["leaves"].get<float>() << " ";
|
cout << setw(7) << setprecision(2) << fixed << r["leaves"].get<float>() << " ";
|
||||||
cout << setw(7) << setprecision(2) << fixed << r["depth"].get<float>() << " ";
|
cout << setw(7) << setprecision(2) << fixed << r["depth"].get<float>() << " ";
|
||||||
cout << setw(8) << right << setprecision(6) << fixed << r["score_test"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["score_test_std"].get<double>() << " ";
|
cout << setw(8) << right << setprecision(6) << fixed << r["score"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["score_std"].get<double>() << " ";
|
||||||
cout << setw(10) << right << setprecision(6) << fixed << r["test_time"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["test_time_std"].get<double>() << " ";
|
cout << setw(11) << right << setprecision(6) << fixed << r["time"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["time_std"].get<double>() << " ";
|
||||||
cout << " " << r["hyperparameters"].get<string>();
|
try {
|
||||||
|
cout << r["hyperparameters"].get<string>();
|
||||||
|
}
|
||||||
|
catch (const exception& err) {
|
||||||
|
cout << r["hyperparameters"];
|
||||||
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
lastResult = r;
|
lastResult = r;
|
||||||
totalScore += r["score_test"].get<double>();
|
totalScore += r["score"].get<double>();
|
||||||
|
odd = !odd;
|
||||||
}
|
}
|
||||||
if (data["results"].size() == 1) {
|
if (data["results"].size() == 1) {
|
||||||
cout << string(MAXL, '*') << endl;
|
cout << string(MAXL, '*') << endl;
|
||||||
@ -74,12 +82,12 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void Report::footer()
|
void Report::footer()
|
||||||
{
|
{
|
||||||
cout << string(MAXL, '*') << endl;
|
cout << Colors::MAGENTA() << string(MAXL, '*') << endl;
|
||||||
auto score = data["score_name"].get<string>();
|
auto score = data["score_name"].get<string>();
|
||||||
if (score == BestResult::scoreName()) {
|
if (score == BestResult::scoreName()) {
|
||||||
cout << headerLine(score + " compared to " + BestResult::title() + " .: " + to_string(totalScore / BestResult::score()));
|
cout << headerLine(score + " compared to " + BestResult::title() + " .: " + to_string(totalScore / BestResult::score()));
|
||||||
}
|
}
|
||||||
cout << string(MAXL, '*') << endl;
|
cout << string(MAXL, '*') << endl << Colors::RESET();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "Colors.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
const int MAXL = 121;
|
const int MAXL = 121;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "Results.h"
|
#include "Results.h"
|
||||||
#include "Report.h"
|
#include "Report.h"
|
||||||
#include "BestResult.h"
|
#include "BestResult.h"
|
||||||
|
#include "Colors.h"
|
||||||
namespace platform {
|
namespace platform {
|
||||||
Result::Result(const string& path, const string& filename)
|
Result::Result(const string& path, const string& filename)
|
||||||
: path(path)
|
: path(path)
|
||||||
@ -59,25 +60,35 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void Results::show() const
|
void Results::show() const
|
||||||
{
|
{
|
||||||
cout << "Results found: " << files.size() << endl;
|
cout << Colors::GREEN() << "Results found: " << files.size() << endl;
|
||||||
cout << "-------------------" << endl;
|
cout << "-------------------" << endl;
|
||||||
auto i = 0;
|
auto i = 0;
|
||||||
cout << " # Date Model Score Name Score Duration Title" << endl;
|
cout << " # Date Model Score Name Score Duration Title" << endl;
|
||||||
cout << "=== ========== ============ =========== =========== ========= =============================================================" << endl;
|
cout << "=== ========== ============ =========== =========== ========= =============================================================" << endl;
|
||||||
|
bool odd = true;
|
||||||
for (const auto& result : files) {
|
for (const auto& result : files) {
|
||||||
cout << setw(3) << fixed << right << i++ << " ";
|
auto color = odd ? Colors::BLUE() : Colors::CYAN();
|
||||||
|
cout << color << setw(3) << fixed << right << i++ << " ";
|
||||||
cout << result.to_string() << endl;
|
cout << result.to_string() << endl;
|
||||||
if (i == max && max != 0) {
|
if (i == max && max != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
odd = !odd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int Results::getIndex(const string& intent) const
|
int Results::getIndex(const string& intent) const
|
||||||
{
|
{
|
||||||
cout << "Choose result to " << intent << ": ";
|
string color;
|
||||||
int index;
|
if (intent == "delete") {
|
||||||
cin >> index;
|
color = Colors::RED();
|
||||||
if (index >= 0 && index < files.size()) {
|
} else {
|
||||||
|
color = Colors::YELLOW();
|
||||||
|
}
|
||||||
|
cout << color << "Choose result to " << intent << " (cancel=-1): ";
|
||||||
|
string line;
|
||||||
|
getline(cin, line);
|
||||||
|
int index = stoi(line);
|
||||||
|
if (index >= -1 && index < static_cast<int>(files.size())) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
cout << "Invalid index" << endl;
|
cout << "Invalid index" << endl;
|
||||||
@ -85,7 +96,7 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void Results::report(const int index) const
|
void Results::report(const int index) const
|
||||||
{
|
{
|
||||||
cout << "Reporting " << files.at(index).getFilename() << endl;
|
cout << Colors::YELLOW() << "Reporting " << files.at(index).getFilename() << endl;
|
||||||
auto data = files.at(index).load();
|
auto data = files.at(index).load();
|
||||||
Report report(data);
|
Report report(data);
|
||||||
report.show();
|
report.show();
|
||||||
@ -97,7 +108,7 @@ namespace platform {
|
|||||||
bool finished = false;
|
bool finished = false;
|
||||||
string filename, line, options = "qldhsr";
|
string filename, line, options = "qldhsr";
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
cout << "Choose option (quit='q', list='l', delete='d', hide='h', sort='s', report='r'): ";
|
cout << Colors::RESET() << "Choose option (quit='q', list='l', delete='d', hide='h', sort='s', report='r'): ";
|
||||||
getline(cin, line);
|
getline(cin, line);
|
||||||
if (line.size() == 0)
|
if (line.size() == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -131,6 +142,7 @@ namespace platform {
|
|||||||
cout << "Deleting " << filename << endl;
|
cout << "Deleting " << filename << endl;
|
||||||
remove((path + "/" + filename).c_str());
|
remove((path + "/" + filename).c_str());
|
||||||
files.erase(files.begin() + index);
|
files.erase(files.begin() + index);
|
||||||
|
cout << "File: " + filename + " deleted!" << endl;
|
||||||
show();
|
show();
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -161,7 +173,7 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void Results::sortList()
|
void Results::sortList()
|
||||||
{
|
{
|
||||||
cout << "Choose sorting field (date='d', score='s', duration='u', model='m'): ";
|
cout << Colors::YELLOW() << "Choose sorting field (date='d', score='s', duration='u', model='m'): ";
|
||||||
string line;
|
string line;
|
||||||
char option;
|
char option;
|
||||||
getline(cin, line);
|
getline(cin, line);
|
||||||
|
Loading…
Reference in New Issue
Block a user