diff --git a/src/manage/ManageScreen.cpp b/src/manage/ManageScreen.cpp index d31dfe3..3db8d8b 100644 --- a/src/manage/ManageScreen.cpp +++ b/src/manage/ManageScreen.cpp @@ -105,18 +105,27 @@ namespace platform { void ManageScreen::list_result(const std::string& status_message, const std::string& status_color) { - //auto report = DatasetsConsole(); - //report.report(); - //paginator[static_cast(output_type)].setTotal(report.getNumLines()); + auto data = results.at(index).getJson(); + ReportConsole report(data, compare); + auto header_text = report.getHeader(); + auto body = report.getBody(); + paginator[static_cast(output_type)].setTotal(data.size()); // We need to subtract 8 from the page size to make room for the extra header in report auto page_size = paginator[static_cast(OutputType::EXPERIMENTS)].getPageSize(); paginator[static_cast(output_type)].setPage(page_size - 8); - // // header // header(); // + // Results + // + std::cout << header_text; + auto [index_from, index_to] = paginator[static_cast(output_type)].getOffset(); + for (int i = index_from; i <= index_to; i++) { + std::cout << body[i]; + } + // // Status Area // footer(status_message, status_color); @@ -134,11 +143,11 @@ namespace platform { // // Results // - auto data = report.getBody(); + auto body = report.getBody(); std::cout << report.getHeader(); auto [index_from, index_to] = paginator[static_cast(output_type)].getOffset(); for (int i = index_from; i <= index_to; i++) { - std::cout << data[i]; + std::cout << body[i]; } // // Status Area @@ -237,7 +246,7 @@ namespace platform { 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 auto data = results.at(index).getJson(); @@ -278,7 +287,7 @@ namespace platform { void ManageScreen::menu() { char option; - int index, subIndex; + int subIndex; bool finished = false; std::string filename; // tuple @@ -424,10 +433,12 @@ namespace platform { break; } if (indexList) { - report(index, false); + //report(index, false); + output_type = OutputType::RESULT; + list_result(STATUS_OK, STATUS_COLOR); indexList = false; } else { - showIndex(index, subIndex); + showIndex(subIndex); } break; case 'e': diff --git a/src/manage/ManageScreen.h b/src/manage/ManageScreen.h index d1c1667..aea95d2 100644 --- a/src/manage/ManageScreen.h +++ b/src/manage/ManageScreen.h @@ -24,13 +24,14 @@ namespace platform { bool confirmAction(const std::string& intent, const std::string& fileName) const; std::string report(const int index, const bool excelReport); std::string report_compared(); - void showIndex(const int index, const int idx); + void showIndex(const int idx); std::pair sortList(); void menu(); void header(); void footer(const std::string& status, const std::string& color); OutputType output_type; int numFiles; + int index; int index_A, index_B; // used for comparison of experiments int max_status_line; bool indexList; diff --git a/src/reports/ReportConsole.cpp b/src/reports/ReportConsole.cpp index 44168ca..ed3f3b4 100644 --- a/src/reports/ReportConsole.cpp +++ b/src/reports/ReportConsole.cpp @@ -48,16 +48,25 @@ namespace platform { void ReportConsole::do_body() { sbody.str(""); + vbody.clear(); auto tmp = ConfigLocale(); int maxHyper = 15; int maxDataset = 7; for (const auto& r : data["results"]) { maxHyper = std::max(maxHyper, (int)r["hyperparameters"].dump().size()); maxDataset = std::max(maxDataset, (int)r["dataset"].get().size()); - } - sbody << Colors::GREEN() << " # " << std::setw(maxDataset) << std::left << "Dataset" << " Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << std::endl; - sbody << "=== " << std::string(maxDataset, '=') << " ====== ===== === ========= ========= ========= =============== =================== " << std::string(maxHyper, '=') << std::endl; + std::vector header_labels = { " #", "Dataset", "Sampl.", "Feat.", "Cls", "Nodes", "Edges", "Depth", "Score", "Time", "Hyperparameters" }; + sheader << Colors::GREEN(); + std::vector 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; double totalScore = 0.0; int index = 0; @@ -67,47 +76,61 @@ namespace platform { continue; } auto color = (index % 2) ? Colors::CYAN() : Colors::BLUE(); - sbody << color; + std::stringstream line; + line << color; std::string separator{ " " }; if (r.find("notes") != r.end()) { separator = r["notes"].size() > 0 ? Colors::YELLOW() + Symbols::notebook + color : " "; } - sbody << std::setw(3) << std::right << index++ << separator; - sbody << std::setw(maxDataset) << std::left << r["dataset"].get() << " "; - sbody << std::setw(6) << std::right << r["samples"].get() << " "; - sbody << std::setw(5) << std::right << r["features"].get() << " "; - sbody << std::setw(3) << std::right << r["classes"].get() << " "; - sbody << std::setw(9) << std::setprecision(2) << std::fixed << r["nodes"].get() << " "; - sbody << std::setw(9) << std::setprecision(2) << std::fixed << r["leaves"].get() << " "; - sbody << std::setw(9) << std::setprecision(2) << std::fixed << r["depth"].get() << " "; - sbody << std::setw(8) << std::right << std::setprecision(6) << std::fixed << r["score"].get() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["score_std"].get(); + line << std::setw(3) << std::right << index++ << separator; + line << std::setw(maxDataset) << std::left << r["dataset"].get() << " "; + line << std::setw(6) << std::right << r["samples"].get() << " "; + line << std::setw(5) << std::right << r["features"].get() << " "; + line << std::setw(3) << std::right << r["classes"].get() << " "; + line << std::setw(9) << std::setprecision(2) << std::fixed << r["nodes"].get() << " "; + line << std::setw(9) << std::setprecision(2) << std::fixed << r["leaves"].get() << " "; + line << std::setw(9) << std::setprecision(2) << std::fixed << r["depth"].get() << " "; + line << std::setw(8) << std::right << std::setprecision(6) << std::fixed << r["score"].get() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["score_std"].get(); const std::string status = compareResult(r["dataset"].get(), r["score"].get()); - sbody << status; - sbody << std::setw(12) << std::right << std::setprecision(6) << std::fixed << r["time"].get() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["time_std"].get() << " "; - sbody << r["hyperparameters"].dump(); - sbody << std::endl; - sbody << std::flush; + line << status; + line << std::setw(12) << std::right << std::setprecision(6) << std::fixed << r["time"].get() << "±" << std::setw(6) << std::setprecision(4) << std::fixed << r["time_std"].get() << " "; + line << r["hyperparameters"].dump(); + line << std::endl; + vbody.push_back(line.str()); + sbody << line.str(); lastResult = r; totalScore += r["score"].get(); } 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["notes"].size() > 0) { sbody << headerLine("Notes: "); + vbody.push_back(headerLine("Notes: ")); for (const auto& note : lastResult["notes"]) { - sbody << headerLine(note.get()); + line.str(""); + line << headerLine(note.get()); + vbody.push_back(line.str()); + sbody << line.str(); } } } - sbody << headerLine(fVector("Train scores: ", lastResult["scores_train"], 14, 12)); - sbody << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12)); - sbody << headerLine(fVector("Train times: ", lastResult["times_train"], 10, 3)); - sbody << headerLine(fVector("Test times: ", lastResult["times_test"], 10, 3)); + line.str(""); line << headerLine(fVector("Train scores: ", lastResult["scores_train"], 14, 12)); + vbody.push_back(line.str()); sbody << line.str(); + line.str(""); line << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12)); + 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 { footer(totalScore); } sbody << std::string(MAXL, '*') << Colors::RESET() << std::endl; + vbody.push_back(std::string(MAXL, '*') + Colors::RESET() + "\n"); } void ReportConsole::body() { @@ -121,12 +144,15 @@ namespace platform { oss << std::setw(3) << std::right << item.second << " "; oss << std::left << meaning.at(item.first); sbody << headerLine(oss.str(), 2); + vbody.push_back(headerLine(oss.str(), 2)); } } 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(); auto score = data["score_name"].get(); auto best = BestScore::getScore(score); @@ -134,6 +160,7 @@ namespace platform { std::stringstream oss; oss << score << " compared to " << best.first << " .: " << totalScore / best.second; sbody << headerLine(oss.str()); + vbody.push_back(headerLine(oss.str())); } if (!getExistBestFile() && compare) { std::cout << headerLine("*** Best Results File not found. Couldn't compare any result!"); diff --git a/src/reports/ReportConsole.h b/src/reports/ReportConsole.h index 18d3588..01859a1 100644 --- a/src/reports/ReportConsole.h +++ b/src/reports/ReportConsole.h @@ -12,6 +12,8 @@ namespace platform { explicit ReportConsole(json data_, bool compare = false, int index = -1) : ReportBase(data_, compare), selectedIndex(index) {}; virtual ~ReportConsole() = default; std::string fileReport(); + std::string getHeader() { do_header(); do_body(); return sheader.str(); } + std::vector& getBody() { return vbody; } private: int selectedIndex; std::string headerLine(const std::string& text, int utf); @@ -23,5 +25,6 @@ namespace platform { void showSummary() override; std::stringstream sheader; std::stringstream sbody; + std::vector vbody; }; };