From 17c9522e77060c2ffe7de711aca317f8562e0496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Thu, 25 Jul 2024 17:06:31 +0200 Subject: [PATCH] Add support to old format results --- src/manage/ManageScreen.cpp | 4 ++++ src/reports/ReportConsole.cpp | 18 +++++++++++++++-- src/results/Result.cpp | 37 ++++++++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/manage/ManageScreen.cpp b/src/manage/ManageScreen.cpp index 20d55c4..61b7404 100644 --- a/src/manage/ManageScreen.cpp +++ b/src/manage/ManageScreen.cpp @@ -250,6 +250,10 @@ namespace platform { // // Results // + if (results.empty()) { + std::cout << "No results found!" << std::endl; + return; + } auto [index_from, index_to] = paginator[static_cast(output_type)].getOffset(); for (int i = index_from; i <= index_to; i++) { auto color = (i % 2) ? Colors::BLUE() : Colors::CYAN(); diff --git a/src/reports/ReportConsole.cpp b/src/reports/ReportConsole.cpp index 4e924bd..444a78c 100644 --- a/src/reports/ReportConsole.cpp +++ b/src/reports/ReportConsole.cpp @@ -27,9 +27,23 @@ namespace platform { std::string discretiz_algo = data.find("discretization_algorithm") != data.end() ? data["discretization_algorithm"].get() : "ORIGINAL"; std::string algorithm = data["discretized"].get() ? " (" + discretiz_algo + ")" : ""; std::string smooth = data.find("smooth_strategy") != data.end() ? data["smooth_strategy"].get() : "ORIGINAL"; + std::string stratified; + try { + stratified = data["stratified"].get() ? "True" : "False"; + } + catch (nlohmann::json::type_error) { + stratified = data["stratified"].get() == 1 ? "True" : "False"; + } + std::string discretized; + try { + discretized = data["discretized"].get() ? "True" : "False"; + } + catch (nlohmann::json::type_error) { + discretized = data["discretized"].get() == 1 ? "True" : "False"; + } sheader << headerLine( - "Random seeds: " + fromVector("seeds") + " Discretized: " + (data["discretized"].get() ? "True" : "False") + algorithm - + " Stratified: " + (data["stratified"].get() ? "True" : "False") + " Smooth Strategy: " + smooth + "Random seeds: " + fromVector("seeds") + " Discretized: " + discretized + " " + algorithm + + " Stratified: " + stratified + " Smooth Strategy: " + smooth ); Timer timer; oss << "Execution took " << timer.translate2String(data["duration"].get()) diff --git a/src/results/Result.cpp b/src/results/Result.cpp index ff9dea2..75a89b7 100644 --- a/src/results/Result.cpp +++ b/src/results/Result.cpp @@ -72,20 +72,39 @@ namespace platform { std::string Result::getFilename() const { std::ostringstream oss; - oss << "results_" << data.at("score_name").get() << "_" << data.at("model").get() << "_" - << data.at("platform").get() << "_" << data["date"].get() << "_" - << data["time"].get() << "_" << (data["stratified"] ? "1" : "0") << ".json"; + std::string stratified; + try { + stratified = data["stratified"].get() ? "1" : "0"; + } + catch (nlohmann::json_abi_v3_11_3::detail::type_error) { + stratified = data["stratified"].get() == 1 ? "1" : "0"; + } + oss << "results_" + << data.at("score_name").get() << "_" + << data.at("model").get() << "_" + << data.at("platform").get() << "_" + << data["date"].get() << "_" + << data["time"].get() << "_" + << stratified << ".json"; return oss.str(); } - - std::string Result::to_string(int maxModel, int maxTitle) const { auto tmp = ConfigLocale(); std::stringstream oss; - std::string s = data["stratified"].get() ? "S" : ""; - std::string d = data["discretized"].get() ? "D" : ""; - std::string sd = s + d; + std::string s, d; + try { + s = data["stratified"].get() ? "S" : " "; + } + catch (nlohmann::json_abi_v3_11_3::detail::type_error) { + s = data["stratified"].get() == 1 ? "S" : " "; + } + try { + d = data["discretized"].get() ? "D" : " "; + } + catch (nlohmann::json_abi_v3_11_3::detail::type_error) { + d = data["discretized"].get() == 1 ? "D" : " "; + } auto duration = data["duration"].get(); double durationShow = duration > 3600 ? duration / 3600 : duration > 60 ? duration / 60 : duration; std::string durationUnit = duration > 3600 ? "h" : duration > 60 ? "m" : "s"; @@ -94,7 +113,7 @@ namespace platform { oss << std::setw(11) << std::left << data["score_name"].get() << " "; oss << std::right << std::setw(10) << std::setprecision(7) << std::fixed << score << " "; oss << std::left << std::setw(12) << data["platform"].get() << " "; - oss << std::left << std::setw(2) << sd << " "; + oss << s << d << " "; auto completeString = isComplete() ? "C" : "P"; oss << std::setw(1) << " " << completeString << " "; oss << std::setw(5) << std::right << std::setprecision(2) << std::fixed << durationShow << " " << durationUnit << " ";