From cfcf3c16df930ced8e80b754766917c473fbf3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Thu, 28 Sep 2023 17:12:04 +0200 Subject: [PATCH] Add best results Excel --- src/Platform/BestResults.cc | 2 +- src/Platform/BestResultsExcel.cc | 54 +++++++++++++++++++++++++++++--- src/Platform/BestResultsExcel.h | 6 ++-- src/Platform/ExcelFile.h | 8 +++++ src/Platform/ReportExcel.cc | 7 ----- src/Platform/ReportExcel.h | 2 -- 6 files changed, 62 insertions(+), 17 deletions(-) diff --git a/src/Platform/BestResults.cc b/src/Platform/BestResults.cc index 6f47631..013dbea 100644 --- a/src/Platform/BestResults.cc +++ b/src/Platform/BestResults.cc @@ -301,7 +301,7 @@ namespace platform { stats.postHocHolmTest(result); } if (excel) { - BestResultsExcel excel(models, datasets, table, friedman); + BestResultsExcel excel(score, models, datasets, table, friedman); excel.build(); } } diff --git a/src/Platform/BestResultsExcel.cc b/src/Platform/BestResultsExcel.cc index c7401ec..768063e 100644 --- a/src/Platform/BestResultsExcel.cc +++ b/src/Platform/BestResultsExcel.cc @@ -1,23 +1,35 @@ +#include #include "BestResultsExcel.h" #include "Paths.h" +#include namespace platform { - BestResultsExcel::BestResultsExcel(vector models, vector datasets, json table, bool friedman) : models(models), datasets(datasets), table(table), friedman(friedman) + BestResultsExcel::BestResultsExcel(string score, vector models, vector datasets, json table, bool friedman) : score(score), models(models), datasets(datasets), table(table), friedman(friedman) { workbook = workbook_new((Paths::excel() + fileName).c_str()); worksheet = workbook_add_worksheet(workbook, "Best Results"); setProperties("Best Results"); createFormats(); + int maxModelName = (*max_element(models.begin(), models.end(), [](const string& a, const string& b) { return a.size() < b.size(); })).size(); + modelNameSize = max(modelNameSize, maxModelName); + int maxDatasetName = (*max_element(datasets.begin(), datasets.end(), [](const string& a, const string& b) { return a.size() < b.size(); })).size(); + datasetNameSize = max(datasetNameSize, maxDatasetName); formatColumns(); } - BestResultsExcel::~BestResultsExcel() { workbook_close(workbook); } void BestResultsExcel::formatColumns() { - + worksheet_freeze_panes(worksheet, 4, 2); + vector columns_sizes = { 5, datasetNameSize }; + for (int i = 0; i < models.size(); ++i) { + columns_sizes.push_back(modelNameSize); + } + for (int i = 0; i < columns_sizes.size(); ++i) { + worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL); + } } void BestResultsExcel::build() { @@ -27,15 +39,47 @@ namespace platform { } void BestResultsExcel::header() { + row = 0; + string message = "Best results for " + score; + worksheet_merge_range(worksheet, 0, 0, 0, 1 + models.size(), message.c_str(), styles["headerFirst"]); + // Body header + row = 3; + int col = 1; + writeString(row, 0, "NÂș", "bodyHeader"); + writeString(row, 1, "Dataset", "bodyHeader"); + for (const auto& model : models) { + writeString(row, ++col, model.c_str(), "bodyHeader"); + } } void BestResultsExcel::body() { - + row = 4; + int i = 0; + json origin = table.begin().value(); + for (auto const& item : origin.items()) { + writeInt(row, 0, i++, "ints"); + writeString(row, 1, item.key().c_str(), "text"); + int col = 1; + for (const auto& model : models) { + double value = table[model].at(item.key()).at(0).get(); + writeDouble(row, ++col, value, "result"); + } + ++row; + } + // Set Totals + writeString(row, 1, "Total", "bodyHeader"); + int col = 1; + for (const auto& model : models) { + stringstream oss; + oss << "=sum(indirect(address(" << 5 << "," << col + 2 << ")):indirect(address(" << row << "," << col + 2 << ")))"; + worksheet_write_formula(worksheet, row, ++col, oss.str().c_str(), styles["bodyHeader_odd"]); + } } void BestResultsExcel::footer() { + if (friedman) { + } } - } \ No newline at end of file diff --git a/src/Platform/BestResultsExcel.h b/src/Platform/BestResultsExcel.h index 9813d61..f4d3743 100644 --- a/src/Platform/BestResultsExcel.h +++ b/src/Platform/BestResultsExcel.h @@ -10,7 +10,7 @@ using json = nlohmann::json; namespace platform { class BestResultsExcel : ExcelFile { public: - BestResultsExcel(vector models, vector datasets, json table, bool friedman); + BestResultsExcel(string score, vector models, vector datasets, json table, bool friedman); ~BestResultsExcel(); void build(); private: @@ -19,11 +19,13 @@ namespace platform { void footer(); void formatColumns(); const string fileName = "BestResults.xlsx"; + string score; vector models; vector datasets; json table; bool friedman; - + int modelNameSize = 12; // Min size of the column + int datasetNameSize = 25; // Min size of the column }; } #endif //BESTRESULTS_EXCEL_H \ No newline at end of file diff --git a/src/Platform/ExcelFile.h b/src/Platform/ExcelFile.h index 4bfef10..a81acc3 100644 --- a/src/Platform/ExcelFile.h +++ b/src/Platform/ExcelFile.h @@ -1,11 +1,19 @@ #ifndef EXCELFILE_H #define EXCELFILE_H +#include #include #include #include "xlsxwriter.h" using namespace std; namespace platform { + struct separated : numpunct { + char do_decimal_point() const { return ','; } + + char do_thousands_sep() const { return '.'; } + + string do_grouping() const { return "\03"; } + }; class ExcelFile { public: ExcelFile(); diff --git a/src/Platform/ReportExcel.cc b/src/Platform/ReportExcel.cc index 24fe5e4..13e0a9e 100644 --- a/src/Platform/ReportExcel.cc +++ b/src/Platform/ReportExcel.cc @@ -5,13 +5,6 @@ namespace platform { - struct separated : numpunct { - char do_decimal_point() const { return ','; } - - char do_thousands_sep() const { return '.'; } - - string do_grouping() const { return "\03"; } - }; ReportExcel::ReportExcel(json data_, bool compare, lxw_workbook* workbook) : ReportBase(data_, compare), ExcelFile(workbook) { diff --git a/src/Platform/ReportExcel.h b/src/Platform/ReportExcel.h index cc2d57a..0fb9a22 100644 --- a/src/Platform/ReportExcel.h +++ b/src/Platform/ReportExcel.h @@ -7,8 +7,6 @@ #include "Colors.h" namespace platform { using namespace std; - const int MAXLL = 128; - class ReportExcel : public ReportBase, public ExcelFile { public: explicit ReportExcel(json data_, bool compare, lxw_workbook* workbook);