From 67487ffce1f7bf1bad5c80c2565942b1cbad0b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Sat, 16 Mar 2024 23:37:37 +0100 Subject: [PATCH] shorten dataset name to maximum length --- src/manage/ManageResults.cpp | 2 +- src/reports/DatasetsConsole.cpp | 14 ++++++++------ src/reports/DatasetsConsole.h | 2 +- src/reports/ReportConsole.cpp | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/manage/ManageResults.cpp b/src/manage/ManageResults.cpp index 7fc93f1..6fc956b 100644 --- a/src/manage/ManageResults.cpp +++ b/src/manage/ManageResults.cpp @@ -413,7 +413,7 @@ namespace platform { break; case 'r': if (output_type == OutputType::DATASETS) { - list_datasets(STATUS_OK, STATUS_COLOR); + list(STATUS_OK, STATUS_COLOR); break; } if (indexList) { diff --git a/src/reports/DatasetsConsole.cpp b/src/reports/DatasetsConsole.cpp index 4c4b9a6..1724a53 100644 --- a/src/reports/DatasetsConsole.cpp +++ b/src/reports/DatasetsConsole.cpp @@ -5,14 +5,14 @@ namespace platform { const int DatasetsConsole::BALANCE_LENGTH = 75; - void DatasetsConsole::split_lines(std::string line, const std::string& balance) + void DatasetsConsole::split_lines(int name_len, std::string line, const std::string& balance) { auto temp = std::string(balance); while (temp.size() > DatasetsConsole::BALANCE_LENGTH - 1) { auto part = temp.substr(0, DatasetsConsole::BALANCE_LENGTH); line += part + "\n"; body.push_back(line); - line = string(52, ' '); + line = string(name_len + 22, ' '); temp = temp.substr(DatasetsConsole::BALANCE_LENGTH); } line += temp + "\n"; @@ -36,10 +36,12 @@ namespace platform { header.clear(); body.clear(); auto datasets = platform::Datasets(false, platform::Paths::datasets()); - auto loc = std::locale("es_ES"); + auto loc = std::locale("es_ES.UTF-8"); std::stringstream sheader; + auto datasets_names = datasets.getNames(); + int maxName = std::max(size_t(7), (*max_element(datasets_names.begin(), datasets_names.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })).size()); std::vector header_labels = { " #", "Dataset", "Sampl.", "Feat.", "Cls", "Balance" }; - std::vector header_lengths = { 3, 30, 6, 5, 3, DatasetsConsole::BALANCE_LENGTH }; + std::vector header_lengths = { 3, maxName, 6, 5, 3, DatasetsConsole::BALANCE_LENGTH }; sheader << Colors::GREEN(); for (int i = 0; i < header_labels.size(); i++) { sheader << setw(header_lengths[i]) << left << header_labels[i] << " "; @@ -58,7 +60,7 @@ namespace platform { line.imbue(loc); auto color = num % 2 ? Colors::CYAN() : Colors::BLUE(); line << color << setw(3) << right << num++ << " "; - line << setw(30) << left << dataset << " "; + line << setw(maxName) << left << dataset << " "; datasets.loadDataset(dataset); auto nSamples = datasets.getNSamples(dataset); line << setw(6) << right << nSamples << " "; @@ -71,7 +73,7 @@ namespace platform { oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")"; sep = " / "; } - split_lines(line.str(), oss.str()); + split_lines(maxName, line.str(), oss.str()); // Store data for Excel report data[dataset] = json::object(); data[dataset]["samples"] = nSamples; diff --git a/src/reports/DatasetsConsole.h b/src/reports/DatasetsConsole.h index ab4ec0e..289eb22 100644 --- a/src/reports/DatasetsConsole.h +++ b/src/reports/DatasetsConsole.h @@ -20,7 +20,7 @@ namespace platform { json& getData() { return data; } void report(); private: - void split_lines(std::string line, const std::string& balance); + void split_lines(int name_len, std::string line, const std::string& balance); std::vector header, body; json data; }; diff --git a/src/reports/ReportConsole.cpp b/src/reports/ReportConsole.cpp index 05a626e..44168ca 100644 --- a/src/reports/ReportConsole.cpp +++ b/src/reports/ReportConsole.cpp @@ -91,7 +91,7 @@ namespace platform { totalScore += r["score"].get(); } if (data["results"].size() == 1 || selectedIndex != -1) { - sbody << std::string(MAXL, '*') << std::endl; + sbody << Colors::MAGENTA() << std::string(MAXL, '*') << std::endl; if (lastResult.find("notes") != lastResult.end()) { if (lastResult["notes"].size() > 0) { sbody << headerLine("Notes: ");