Compare commits

...

2 Commits

5 changed files with 109 additions and 53 deletions

View File

@@ -105,18 +105,27 @@ namespace platform {
void ManageScreen::list_result(const std::string& status_message, const std::string& status_color) void ManageScreen::list_result(const std::string& status_message, const std::string& status_color)
{ {
//auto report = DatasetsConsole(); auto data = results.at(index).getJson();
//report.report(); ReportConsole report(data, compare);
//paginator[static_cast<int>(output_type)].setTotal(report.getNumLines()); auto header_text = report.getHeader();
auto body = report.getBody();
paginator[static_cast<int>(output_type)].setTotal(body.size());
// We need to subtract 8 from the page size to make room for the extra header in report // We need to subtract 8 from the page size to make room for the extra header in report
auto page_size = paginator[static_cast<int>(OutputType::EXPERIMENTS)].getPageSize(); auto page_size = paginator[static_cast<int>(OutputType::EXPERIMENTS)].getPageSize();
paginator[static_cast<int>(output_type)].setPage(page_size - 8); paginator[static_cast<int>(output_type)].setPageSize(page_size - 8);
// //
// header // header
// //
header(); header();
// //
// Results
//
std::cout << header_text;
auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset();
for (int i = index_from; i <= index_to; i++) {
std::cout << body[i];
}
//
// Status Area // Status Area
// //
footer(status_message, status_color); footer(status_message, status_color);
@@ -134,11 +143,11 @@ namespace platform {
// //
// Results // Results
// //
auto data = report.getBody(); auto body = report.getBody();
std::cout << report.getHeader(); std::cout << report.getHeader();
auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset(); auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset();
for (int i = index_from; i <= index_to; i++) { for (int i = index_from; i <= index_to; i++) {
std::cout << data[i]; std::cout << body[i];
} }
// //
// Status Area // Status Area
@@ -237,7 +246,7 @@ namespace platform {
return "Reporting " + results.at(index).getFilename(); return "Reporting " + results.at(index).getFilename();
} }
} }
void ManageScreen::showIndex(const int index, const int idx) void ManageScreen::showIndex(const int idx)
{ {
// Show a dataset result inside a report // Show a dataset result inside a report
auto data = results.at(index).getJson(); auto data = results.at(index).getJson();
@@ -278,7 +287,7 @@ namespace platform {
void ManageScreen::menu() void ManageScreen::menu()
{ {
char option; char option;
int index, subIndex; int subIndex;
bool finished = false; bool finished = false;
std::string filename; std::string filename;
// tuple<Option, digit, requires value> // tuple<Option, digit, requires value>
@@ -301,27 +310,27 @@ namespace platform {
}; };
// tuple<Option, digit, requires value> // tuple<Option, digit, requires value>
std::vector<std::tuple<std::string, char, bool>> listOptions = { std::vector<std::tuple<std::string, char, bool>> listOptions = {
{"quit", 'q', false},
{"report", 'r', true}, {"report", 'r', true},
{"list", 'l', false}, {"list", 'l', false},
{"back", 'b', false}, {"back", 'b', false},
{"quit", 'q', false} {"Page", 'p', true},
{"Page+", '+', false},
{"Page-", '-', false}
}; };
auto parser = CommandParser(); auto parser = CommandParser();
while (!finished) { while (!finished) {
bool parserError = true; // force the first iteration bool parserError = true; // force the first iteration
while (parserError) { while (parserError) {
auto [min_index, max_index] = paginator[static_cast<int>(output_type)].getOffset();
if (indexList) { if (indexList) {
auto [min_index, max_index] = paginator[static_cast<int>(output_type)].getOffset();
std::tie(option, index, parserError) = parser.parse(Colors::IGREEN(), mainOptions, 'r', min_index, max_index); std::tie(option, index, parserError) = parser.parse(Colors::IGREEN(), mainOptions, 'r', min_index, max_index);
} else { } else {
std::tie(option, subIndex, parserError) = parser.parse(Colors::IBLUE(), listOptions, 'r', 0, results.at(index).getJson()["results"].size() - 1); std::tie(option, subIndex, parserError) = parser.parse(Colors::IBLUE(), listOptions, 'r', min_index, max_index);
} }
if (parserError) { if (parserError) {
if (indexList) list(parser.getErrorMessage(), Colors::RED());
list(parser.getErrorMessage(), Colors::RED());
else
report(index, false);
} }
} }
switch (option) { switch (option) {
@@ -330,10 +339,13 @@ namespace platform {
list_datasets(STATUS_OK, STATUS_COLOR); list_datasets(STATUS_OK, STATUS_COLOR);
break; break;
case 'p': case 'p':
if (paginator[static_cast<int>(output_type)].setPage(index)) { {
list(STATUS_OK, STATUS_COLOR); auto page = output_type == OutputType::EXPERIMENTS ? index : subIndex;
} else { if (paginator[static_cast<int>(output_type)].setPage(page)) {
list("Invalid page!", Colors::RED()); list(STATUS_OK, STATUS_COLOR);
} else {
list("Invalid page! (" + std::to_string(page) + ")", Colors::RED());
}
} }
break; break;
case '+': case '+':
@@ -371,7 +383,7 @@ namespace platform {
list("B set to " + std::to_string(index), Colors::GREEN()); list("B set to " + std::to_string(index), Colors::GREEN());
} else { } else {
// back to show the report // back to show the report
report(index, false); list(STATUS_OK, STATUS_COLOR);
} }
break; break;
case 'c': case 'c':
@@ -424,10 +436,12 @@ namespace platform {
break; break;
} }
if (indexList) { if (indexList) {
report(index, false); //report(index, false);
output_type = OutputType::RESULT;
list(STATUS_OK, STATUS_COLOR);
indexList = false; indexList = false;
} else { } else {
showIndex(index, subIndex); showIndex(subIndex);
} }
break; break;
case 'e': case 'e':

View File

@@ -24,13 +24,14 @@ namespace platform {
bool confirmAction(const std::string& intent, const std::string& fileName) const; bool confirmAction(const std::string& intent, const std::string& fileName) const;
std::string report(const int index, const bool excelReport); std::string report(const int index, const bool excelReport);
std::string report_compared(); std::string report_compared();
void showIndex(const int index, const int idx); void showIndex(const int idx);
std::pair<std::string, std::string> sortList(); std::pair<std::string, std::string> sortList();
void menu(); void menu();
void header(); void header();
void footer(const std::string& status, const std::string& color); void footer(const std::string& status, const std::string& color);
OutputType output_type; OutputType output_type;
int numFiles; int numFiles;
int index;
int index_A, index_B; // used for comparison of experiments int index_A, index_B; // used for comparison of experiments
int max_status_line; int max_status_line;
bool indexList; bool indexList;

View File

@@ -10,26 +10,37 @@ public:
computePages(); computePages();
}; };
~Paginator() = default; ~Paginator() = default;
// Getters
int getPageSize() const { return pageSize; } int getPageSize() const { return pageSize; }
int getLines() const int getLines() const
{ {
auto [start, end] = getOffset(); auto [start, end] = getOffset();
return std::min(pageSize, end - start + 1); return std::min(pageSize, end - start + 1);
} }
int getPage() const { return page; }
int getTotal() const { return total; } int getTotal() const { return total; }
void setTotal(int total) { this->total = total; computePages(); } int getPages() const { return numPages; }
std::pair<int, int> getOffset() const std::pair<int, int> getOffset() const
{ {
return { (page - 1) * pageSize, std::min(total - 1, page * pageSize - 1) }; return { (page - 1) * pageSize, std::min(total - 1, page * pageSize - 1) };
} }
int getPages() const { return numPages; } // Setters
int getPage() const { return page; } void setTotal(int total) { this->total = total; computePages(); }
void setPageSize(int page) { this->pageSize = page; computePages(); }
bool setPage(int page) { return valid(page) ? this->page = page, true : false; }
// Utils
bool valid(int page) const { return page > 0 && page <= numPages; } bool valid(int page) const { return page > 0 && page <= numPages; }
bool hasPrev(int page) const { return page > 1; } bool hasPrev(int page) const { return page > 1; }
bool hasNext(int page) const { return page < getPages(); } bool hasNext(int page) const { return page < getPages(); }
bool setPage(int page) { return valid(page) ? this->page = page, true : false; }
bool addPage() { return page < numPages ? ++page, true : false; } bool addPage() { return page < numPages ? ++page, true : false; }
bool subPage() { return page > 1 ? --page, true : false; } bool subPage() { return page > 1 ? --page, true : false; }
std::string to_string() const
{
auto offset = getOffset();
return "Paginator: { pageSize: " + std::to_string(pageSize) + ", total: " + std::to_string(total)
+ ", page: " + std::to_string(page) + ", numPages: " + std::to_string(numPages)
+ " Offset [" + std::to_string(offset.first) + ", " + std::to_string(offset.second) + "]}";
}
private: private:
void computePages() void computePages()
{ {

View File

@@ -48,16 +48,25 @@ namespace platform {
void ReportConsole::do_body() void ReportConsole::do_body()
{ {
sbody.str(""); sbody.str("");
vbody.clear();
auto tmp = ConfigLocale(); auto tmp = ConfigLocale();
int maxHyper = 15; int maxHyper = 15;
int maxDataset = 7; int maxDataset = 7;
for (const auto& r : data["results"]) { for (const auto& r : data["results"]) {
maxHyper = std::max(maxHyper, (int)r["hyperparameters"].dump().size()); maxHyper = std::max(maxHyper, (int)r["hyperparameters"].dump().size());
maxDataset = std::max(maxDataset, (int)r["dataset"].get<std::string>().size()); maxDataset = std::max(maxDataset, (int)r["dataset"].get<std::string>().size());
} }
sbody << Colors::GREEN() << " # " << std::setw(maxDataset) << std::left << "Dataset" << " Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << std::endl; std::vector<std::string> header_labels = { " #", "Dataset", "Sampl.", "Feat.", "Cls", "Nodes", "Edges", "Depth", "Score", "Time", "Hyperparameters" };
sbody << "=== " << std::string(maxDataset, '=') << " ====== ===== === ========= ========= ========= =============== =================== " << std::string(maxHyper, '=') << std::endl; sheader << Colors::GREEN();
std::vector<int> header_lengths = { 3, maxDataset, 6, 5, 3, 9, 9, 9, 8, 12, maxHyper };
for (int i = 0; i < header_labels.size(); i++) {
sheader << std::setw(header_lengths[i]) << std::left << header_labels[i] << " ";
}
sheader << std::endl;
for (int i = 0; i < header_labels.size(); i++) {
sheader << std::string(header_lengths[i], '=') << " ";
}
sheader << std::endl;
json lastResult; json lastResult;
double totalScore = 0.0; double totalScore = 0.0;
int index = 0; int index = 0;
@@ -67,47 +76,61 @@ namespace platform {
continue; continue;
} }
auto color = (index % 2) ? Colors::CYAN() : Colors::BLUE(); auto color = (index % 2) ? Colors::CYAN() : Colors::BLUE();
sbody << color; std::stringstream line;
line << color;
std::string separator{ " " }; std::string separator{ " " };
if (r.find("notes") != r.end()) { if (r.find("notes") != r.end()) {
separator = r["notes"].size() > 0 ? Colors::YELLOW() + Symbols::notebook + color : " "; separator = r["notes"].size() > 0 ? Colors::YELLOW() + Symbols::notebook + color : " ";
} }
sbody << std::setw(3) << std::right << index++ << separator; line << std::setw(3) << std::right << index++ << separator;
sbody << std::setw(maxDataset) << std::left << r["dataset"].get<std::string>() << " "; line << std::setw(maxDataset) << std::left << r["dataset"].get<std::string>() << " ";
sbody << std::setw(6) << std::right << r["samples"].get<int>() << " "; line << std::setw(6) << std::right << r["samples"].get<int>() << " ";
sbody << std::setw(5) << std::right << r["features"].get<int>() << " "; line << std::setw(5) << std::right << r["features"].get<int>() << " ";
sbody << std::setw(3) << std::right << r["classes"].get<int>() << " "; line << std::setw(3) << std::right << r["classes"].get<int>() << " ";
sbody << std::setw(9) << std::setprecision(2) << std::fixed << r["nodes"].get<float>() << " "; line << std::setw(9) << std::setprecision(2) << std::fixed << r["nodes"].get<float>() << " ";
sbody << std::setw(9) << std::setprecision(2) << std::fixed << r["leaves"].get<float>() << " "; line << std::setw(9) << std::setprecision(2) << std::fixed << r["leaves"].get<float>() << " ";
sbody << std::setw(9) << std::setprecision(2) << std::fixed << r["depth"].get<float>() << " "; line << std::setw(9) << std::setprecision(2) << std::fixed << r["depth"].get<float>() << " ";
sbody << std::setw(8) << std::right << std::setprecision(6) << std::fixed << r["score"].get<double>() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["score_std"].get<double>(); line << std::setw(8) << std::right << std::setprecision(6) << std::fixed << r["score"].get<double>() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["score_std"].get<double>();
const std::string status = compareResult(r["dataset"].get<std::string>(), r["score"].get<double>()); const std::string status = compareResult(r["dataset"].get<std::string>(), r["score"].get<double>());
sbody << status; line << status;
sbody << std::setw(12) << std::right << std::setprecision(6) << std::fixed << r["time"].get<double>() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["time_std"].get<double>() << " "; line << std::setw(12) << std::right << std::setprecision(6) << std::fixed << r["time"].get<double>() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["time_std"].get<double>() << " ";
sbody << r["hyperparameters"].dump(); line << r["hyperparameters"].dump();
sbody << std::endl; line << std::endl;
sbody << std::flush; vbody.push_back(line.str());
sbody << line.str();
lastResult = r; lastResult = r;
totalScore += r["score"].get<double>(); totalScore += r["score"].get<double>();
} }
if (data["results"].size() == 1 || selectedIndex != -1) { if (data["results"].size() == 1 || selectedIndex != -1) {
sbody << Colors::MAGENTA() << std::string(MAXL, '*') << std::endl; std::stringstream line;
line << Colors::MAGENTA() << std::string(MAXL, '*') << std::endl;
vbody.push_back(line.str());
sbody << line.str();
if (lastResult.find("notes") != lastResult.end()) { if (lastResult.find("notes") != lastResult.end()) {
if (lastResult["notes"].size() > 0) { if (lastResult["notes"].size() > 0) {
sbody << headerLine("Notes: "); sbody << headerLine("Notes: ");
vbody.push_back(headerLine("Notes: "));
for (const auto& note : lastResult["notes"]) { for (const auto& note : lastResult["notes"]) {
sbody << headerLine(note.get<std::string>()); line.str("");
line << headerLine(note.get<std::string>());
vbody.push_back(line.str());
sbody << line.str();
} }
} }
} }
sbody << headerLine(fVector("Train scores: ", lastResult["scores_train"], 14, 12)); line.str(""); line << headerLine(fVector("Train scores: ", lastResult["scores_train"], 14, 12));
sbody << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12)); vbody.push_back(line.str()); sbody << line.str();
sbody << headerLine(fVector("Train times: ", lastResult["times_train"], 10, 3)); line.str(""); line << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12));
sbody << headerLine(fVector("Test times: ", lastResult["times_test"], 10, 3)); vbody.push_back(line.str()); sbody << line.str();
line.str(""); line << headerLine(fVector("Train times: ", lastResult["times_train"], 10, 3));
vbody.push_back(line.str()); sbody << line.str();
line.str(""); line << headerLine(fVector("Test times: ", lastResult["times_test"], 10, 3));
vbody.push_back(line.str()); sbody << line.str();
} else { } else {
footer(totalScore); footer(totalScore);
} }
sbody << std::string(MAXL, '*') << Colors::RESET() << std::endl; sbody << std::string(MAXL, '*') << Colors::RESET() << std::endl;
vbody.push_back(std::string(MAXL, '*') + Colors::RESET() + "\n");
} }
void ReportConsole::body() void ReportConsole::body()
{ {
@@ -121,12 +144,15 @@ namespace platform {
oss << std::setw(3) << std::right << item.second << " "; oss << std::setw(3) << std::right << item.second << " ";
oss << std::left << meaning.at(item.first); oss << std::left << meaning.at(item.first);
sbody << headerLine(oss.str(), 2); sbody << headerLine(oss.str(), 2);
vbody.push_back(headerLine(oss.str(), 2));
} }
} }
void ReportConsole::footer(double totalScore) void ReportConsole::footer(double totalScore)
{ {
sbody << Colors::MAGENTA() << std::string(MAXL, '*') << std::endl; std::stringstream linea;
linea << Colors::MAGENTA() << std::string(MAXL, '*') << std::endl;
vbody.push_back(linea.str()); sbody << linea.str();
showSummary(); showSummary();
auto score = data["score_name"].get<std::string>(); auto score = data["score_name"].get<std::string>();
auto best = BestScore::getScore(score); auto best = BestScore::getScore(score);
@@ -134,6 +160,7 @@ namespace platform {
std::stringstream oss; std::stringstream oss;
oss << score << " compared to " << best.first << " .: " << totalScore / best.second; oss << score << " compared to " << best.first << " .: " << totalScore / best.second;
sbody << headerLine(oss.str()); sbody << headerLine(oss.str());
vbody.push_back(headerLine(oss.str()));
} }
if (!getExistBestFile() && compare) { if (!getExistBestFile() && compare) {
std::cout << headerLine("*** Best Results File not found. Couldn't compare any result!"); std::cout << headerLine("*** Best Results File not found. Couldn't compare any result!");

View File

@@ -12,6 +12,8 @@ namespace platform {
explicit ReportConsole(json data_, bool compare = false, int index = -1) : ReportBase(data_, compare), selectedIndex(index) {}; explicit ReportConsole(json data_, bool compare = false, int index = -1) : ReportBase(data_, compare), selectedIndex(index) {};
virtual ~ReportConsole() = default; virtual ~ReportConsole() = default;
std::string fileReport(); std::string fileReport();
std::string getHeader() { do_header(); do_body(); return sheader.str(); }
std::vector<std::string>& getBody() { return vbody; }
private: private:
int selectedIndex; int selectedIndex;
std::string headerLine(const std::string& text, int utf); std::string headerLine(const std::string& text, int utf);
@@ -23,5 +25,6 @@ namespace platform {
void showSummary() override; void showSummary() override;
std::stringstream sheader; std::stringstream sheader;
std::stringstream sbody; std::stringstream sbody;
std::vector<std::string> vbody;
}; };
}; };