Fix b_manage error if no results were present

This commit is contained in:
2024-03-13 17:56:44 +01:00
parent 3ceea5677c
commit cdf339856a
2 changed files with 16 additions and 9 deletions

View File

@@ -14,12 +14,14 @@ namespace platform {
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(ResultsManager(model, score, complete, partial)) numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(ResultsManager(model, score, complete, partial))
{ {
results.load(); results.load();
results.sortDate(); if (!results.empty()) {
indexList = true; results.sortDate();
openExcel = false; indexList = true;
workbook = NULL; openExcel = false;
if (numFiles == 0 or numFiles > results.size()) { workbook = NULL;
this->numFiles = results.size(); if (numFiles == 0 or numFiles > results.size()) {
this->numFiles = results.size();
}
} }
} }
void ManageResults::doMenu() void ManageResults::doMenu()

View File

@@ -10,6 +10,7 @@ namespace platform {
void ResultsManager::load() void ResultsManager::load()
{ {
using std::filesystem::directory_iterator; using std::filesystem::directory_iterator;
bool found = false;
for (const auto& file : directory_iterator(path)) { for (const auto& file : directory_iterator(path)) {
auto filename = file.path().filename().string(); auto filename = file.path().filename().string();
if (filename.find(".json") != std::string::npos && filename.find("results_") == 0) { if (filename.find(".json") != std::string::npos && filename.find("results_") == 0) {
@@ -18,12 +19,16 @@ namespace platform {
bool addResult = true; bool addResult = true;
if (model != "any" && result.getModel() != model || scoreName != "any" && scoreName != result.getScoreName() || complete && !result.isComplete() || partial && result.isComplete()) if (model != "any" && result.getModel() != model || scoreName != "any" && scoreName != result.getScoreName() || complete && !result.isComplete() || partial && result.isComplete())
addResult = false; addResult = false;
if (addResult) if (addResult) {
files.push_back(result); files.push_back(result);
found = true;
}
} }
} }
maxModel = std::max(size_t(5), (*max_element(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getModel().size() < b.getModel().size(); })).getModel().size()); if (found) {
maxTitle = std::max(size_t(5), (*max_element(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getTitle().size() < b.getTitle().size(); })).getTitle().size()); maxModel = std::max(size_t(5), (*max_element(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getModel().size() < b.getModel().size(); })).getModel().size());
maxTitle = std::max(size_t(5), (*max_element(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getTitle().size() < b.getTitle().size(); })).getTitle().size());
}
} }
void ResultsManager::hideResult(int index, const std::string& pathHidden) void ResultsManager::hideResult(int index, const std::string& pathHidden)
{ {