From 38978aa7b7be81cdf304b453a8743e4e47635421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Fri, 15 Mar 2024 19:54:03 +0100 Subject: [PATCH] Add message of Excel file created in b_manage --- src/manage/ManageResults.cpp | 30 +++++++++++++++++------------- src/manage/ManageResults.h | 1 + src/manage/Paginator.hpp | 2 +- src/manage/ResultsManager.cpp | 8 ++++++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/manage/ManageResults.cpp b/src/manage/ManageResults.cpp index 606c070..1e50727 100644 --- a/src/manage/ManageResults.cpp +++ b/src/manage/ManageResults.cpp @@ -13,21 +13,19 @@ namespace platform { const std::string STATUS_OK = "Ok."; const std::string STATUS_COLOR = Colors::GREEN(); ManageResults::ManageResults(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) : - numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(ResultsManager(model, score, complete, partial)) + numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, didExcel(false), results(ResultsManager(model, score, complete, partial)) { results.load(); - if (!results.empty()) { - results.sortDate(); - indexList = true; - openExcel = false; - workbook = NULL; - if (numFiles == 0 or numFiles > results.size()) { - this->numFiles = results.size(); - } + results.sortDate(); + sort_field = "Date"; + indexList = true; + openExcel = false; + workbook = NULL; + if (numFiles == 0 or numFiles > results.size()) { + this->numFiles = results.size(); } paginator = Paginator(numFiles, results.size()); page = 1; - sort_field = "Date"; } void ManageResults::doMenu() { @@ -41,6 +39,9 @@ namespace platform { if (openExcel) { workbook_close(workbook); } + if (didExcel) { + std::cout << Colors::MAGENTA() << "Excel file created: " << Paths::excel() + Paths::excelResults() << std::endl; + } std::cout << Colors::RESET() << "Done!" << std::endl; } void ManageResults::list(const std::string& status_message_init, const std::string& status_color, int index_A, int index_B) @@ -51,7 +52,7 @@ namespace platform { int maxModel = results.maxModelSize(); int maxTitle = results.maxTitleSize(); std::vector header_lengths = { 3, 10, maxModel, 10, 9, 3, 7, maxTitle }; - int maxLine = std::accumulate(header_lengths.begin(), header_lengths.end(), 0) + header_lengths.size() - 1; + int maxLine = std::max(size_t(140), std::accumulate(header_lengths.begin(), header_lengths.end(), 0) + header_lengths.size() - 1); auto temp = ConfigLocale(); auto [index_from, index_to] = paginator.getOffset(page); std::string suffix = ""; @@ -61,8 +62,9 @@ namespace platform { if (partial) { suffix = " Only listing partial results "; } - std::string header = " " + std::to_string(index_to - index_from + 1) + " Results on screen - Page " - + std::to_string(page) + " of " + std::to_string(paginator.getPages()) + " "; + std::string header = " " + std::to_string(index_to - index_from + 1) + " Results on screen of " + + std::to_string(results.size()) + " - Page " + std::to_string(page) + " of " + + std::to_string(paginator.getPages()) + " "; std::string prefix = std::string(maxLine - suffix.size() - header.size(), ' '); std::cout << Colors::CLRSCR() << Colors::REVERSE() << Colors::WHITE() << header << prefix << Colors::MAGENTA() << suffix << std::endl; @@ -136,12 +138,14 @@ namespace platform { auto data_B = results.at(index_B).getJson(); ReportExcelCompared reporter(data_A, data_B); reporter.report(); + didExcel = true; return results.at(index_A).getFilename() + " Vs " + results.at(index_B).getFilename(); } std::string ManageResults::report(const int index, const bool excelReport) { auto data = results.at(index).getJson(); if (excelReport) { + didExcel = true; ReportExcel reporter(data, compare, workbook); reporter.show(); openExcel = true; diff --git a/src/manage/ManageResults.h b/src/manage/ManageResults.h index f181772..0bdceb0 100644 --- a/src/manage/ManageResults.h +++ b/src/manage/ManageResults.h @@ -21,6 +21,7 @@ namespace platform { int numFiles; bool indexList; bool openExcel; + bool didExcel; bool complete; bool partial; bool compare; diff --git a/src/manage/Paginator.hpp b/src/manage/Paginator.hpp index a524cd7..ba3570d 100644 --- a/src/manage/Paginator.hpp +++ b/src/manage/Paginator.hpp @@ -7,7 +7,7 @@ public: Paginator() = default; Paginator(int pageSize, int total) : pageSize(pageSize), total(total) { - numPages = (total + pageSize - 1) / pageSize; + numPages = pageSize > 0 ? (total + pageSize - 1) / pageSize : 0; }; ~Paginator() = default; int getPageSize() const { return pageSize; } diff --git a/src/manage/ResultsManager.cpp b/src/manage/ResultsManager.cpp index cc15a87..0f3c7fa 100644 --- a/src/manage/ResultsManager.cpp +++ b/src/manage/ResultsManager.cpp @@ -48,6 +48,8 @@ namespace platform { } void ResultsManager::sortDate() { + if (empty()) + return; sort(files.begin(), files.end(), [](const Result& a, const Result& b) { if (a.getDate() == b.getDate()) { return a.getModel() < b.getModel(); @@ -57,6 +59,8 @@ namespace platform { } void ResultsManager::sortModel() { + if (empty()) + return; sort(files.begin(), files.end(), [](const Result& a, const Result& b) { if (a.getModel() == b.getModel()) { return a.getDate() > b.getDate(); @@ -66,12 +70,16 @@ namespace platform { } void ResultsManager::sortDuration() { + if (empty()) + return; sort(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getDuration() > b.getDuration(); }); } void ResultsManager::sortScore() { + if (files.empty()) + return; sort(files.begin(), files.end(), [](const Result& a, const Result& b) { if (a.getScore() == b.getScore()) { return a.getDate() > b.getDate();