From 30a6d5e60d847fc9a58d2fee878483584a38c149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Tue, 14 May 2024 13:22:13 +0200 Subject: [PATCH] Complete reporconsole with classification report --- src/reports/ReportConsole.cpp | 27 ++++++++++++++++----------- src/reports/ReportConsole.h | 3 ++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/reports/ReportConsole.cpp b/src/reports/ReportConsole.cpp index 132d5e2..07fc8b4 100644 --- a/src/reports/ReportConsole.cpp +++ b/src/reports/ReportConsole.cpp @@ -135,7 +135,7 @@ namespace platform { sbody << std::string(MAXL, '*') << Colors::RESET() << std::endl; vbody.push_back(std::string(MAXL, '*') + Colors::RESET() + "\n"); if (data["results"].size() == 1 || selectedIndex != -1) { - vbody.push_back(showClassificationReport(Colors::BLUE())); + vbody.push_back(buildClassificationReport(lastResult, Colors::BLUE())); } } void ReportConsole::showSummary() @@ -168,34 +168,31 @@ namespace platform { std::cout << headerLine("*** Best Results File not found. Couldn't compare any result!"); } } - Scores ReportConsole::aggregateScore(std::string key) + Scores ReportConsole::aggregateScore(json& result, std::string key) { - auto lastResult = data["results"][0]; - auto item = data["results"][0]; - auto scores = Scores(item[key][0]); - for (int i = 1; i < item[key].size(); i++) { - auto score = Scores(item[key][i]); + auto scores = Scores(result[key][0]); + for (int i = 1; i < result[key].size(); i++) { + auto score = Scores(result[key][i]); scores.aggregate(score); } return scores; } - std::string ReportConsole::showClassificationReport(std::string color) + std::string ReportConsole::buildClassificationReport(json& result, std::string color) { std::stringstream oss; - auto result = data["results"][0]; if (result.find("confusion_matrices") == result.end()) return ""; bool second_header = false; int lines_header = 0; std::string color_line; std::string suffix = ""; - auto scores = aggregateScore("confusion_matrices"); + auto scores = aggregateScore(result, "confusion_matrices"); auto output_test = scores.classification_report(color, "Test"); int maxLine = (*std::max_element(output_test.begin(), output_test.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })).size(); bool train_data = result.find("confusion_matrices_train") != result.end(); std::vector output_train; if (train_data) { - auto scores_train = aggregateScore("confusion_matrices_train"); + auto scores_train = aggregateScore(result, "confusion_matrices_train"); output_train = scores_train.classification_report(color, "Train"); } oss << Colors::BLUE(); @@ -224,4 +221,12 @@ namespace platform { oss << Colors::RESET(); return oss.str(); } + std::string ReportConsole::showClassificationReport(std::string color) + { + std::stringstream oss; + for (auto& result : data["results"]) { + oss << buildClassificationReport(result, color); + } + return oss.str(); + } } \ No newline at end of file diff --git a/src/reports/ReportConsole.h b/src/reports/ReportConsole.h index a7ec851..c455848 100644 --- a/src/reports/ReportConsole.h +++ b/src/reports/ReportConsole.h @@ -20,13 +20,14 @@ namespace platform { private: int selectedIndex; std::string headerLine(const std::string& text, int utf); + std::string buildClassificationReport(json& result, std::string color); void header() override; void do_header(); void body() override; void do_body(); void footer(double totalScore); void showSummary() override; - Scores aggregateScore(std::string key); + Scores aggregateScore(json& result, std::string key); std::stringstream sheader; std::stringstream sbody; std::vector vbody;