Add ranks sheet to excel best results

This commit is contained in:
Ricardo Montañana Gómez 2023-10-04 16:26:57 +02:00
parent 55e742438f
commit 5e938d5cca
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
3 changed files with 111 additions and 90 deletions

View File

@ -290,8 +290,7 @@ namespace platform {
ranksModels = stats.getRanks(); ranksModels = stats.getRanks();
} }
if (excel) { if (excel) {
// BestResultsExcel excel(score, models, datasets, ranksModels, table, friedman, significance); BestResultsExcel excel(score, models, datasets, table, ranksModels, friedman, significance);
BestResultsExcel excel(score, models, datasets, table, friedman, significance);
excel.build(); excel.build();
cout << Colors::YELLOW() << "** Excel file generated: " << excel.getFileName() << Colors::RESET() << endl; cout << Colors::YELLOW() << "** Excel file generated: " << excel.getFileName() << Colors::RESET() << endl;
} }

View File

@ -4,8 +4,8 @@
#include "Statistics.h" #include "Statistics.h"
namespace platform { namespace platform {
BestResultsExcel::BestResultsExcel(const string& score, const vector<string>& models, const vector<string>& datasets, const json& table, bool friedman, double significance) : BestResultsExcel::BestResultsExcel(const string& score, const vector<string>& models, const vector<string>& datasets, const json& table, const map<string, map<string, float>>& ranksModels, bool friedman, double significance) :
score(score), models(models), datasets(datasets), table(table), friedman(friedman), significance(significance) score(score), models(models), datasets(datasets), table(table), ranksModels(ranksModels), friedman(friedman), significance(significance)
{ {
workbook = workbook_new((Paths::excel() + fileName).c_str()); workbook = workbook_new((Paths::excel() + fileName).c_str());
worksheet = workbook_add_worksheet(workbook, "Best Results"); worksheet = workbook_add_worksheet(workbook, "Best Results");
@ -34,20 +34,30 @@ namespace platform {
} }
void BestResultsExcel::build() void BestResultsExcel::build()
{ {
header(); // Create Sheet with scores
body(); header(false);
footer(); body(false);
footer(false);
if (friedman) {
// Create Sheet with ranks
worksheet = workbook_add_worksheet(workbook, "Ranks");
formatColumns();
header(true);
body(true);
footer(true);
// Create Sheet with Friedman Test
doFriedman();
}
} }
string BestResultsExcel::getFileName() string BestResultsExcel::getFileName()
{ {
return Paths::excel() + fileName; return Paths::excel() + fileName;
} }
void BestResultsExcel::header() void BestResultsExcel::header(bool ranks)
{ {
row = 0; row = 0;
string message = "Best results for " + score; string message = ranks ? "Ranks for score " + score : "Best results for " + score;
worksheet_merge_range(worksheet, 0, 0, 0, 1 + models.size(), message.c_str(), styles["headerFirst"]); worksheet_merge_range(worksheet, 0, 0, 0, 1 + models.size(), message.c_str(), styles["headerFirst"]);
// Body header // Body header
row = 3; row = 3;
int col = 1; int col = 1;
@ -57,7 +67,7 @@ namespace platform {
writeString(row, ++col, model.c_str(), "bodyHeader"); writeString(row, ++col, model.c_str(), "bodyHeader");
} }
} }
void BestResultsExcel::body() void BestResultsExcel::body(bool ranks)
{ {
row = 4; row = 4;
int i = 0; int i = 0;
@ -67,11 +77,14 @@ namespace platform {
writeString(row, 1, item.key().c_str(), "text"); writeString(row, 1, item.key().c_str(), "text");
int col = 1; int col = 1;
for (const auto& model : models) { for (const auto& model : models) {
double value = table[model].at(item.key()).at(0).get<double>(); double value = ranks ? ranksModels[item.key()][model] : table[model].at(item.key()).at(0).get<double>();
writeDouble(row, ++col, value, "result"); writeDouble(row, ++col, value, "result");
} }
++row; ++row;
} }
}
void BestResultsExcel::footer(bool ranks)
{
// Set Totals // Set Totals
writeString(row, 1, "Total", "bodyHeader"); writeString(row, 1, "Total", "bodyHeader");
int col = 1; int col = 1;
@ -80,10 +93,19 @@ namespace platform {
oss << "=sum(indirect(address(" << 5 << "," << col + 2 << ")):indirect(address(" << row << "," << col + 2 << ")))"; 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"]); worksheet_write_formula(worksheet, row, ++col, oss.str().c_str(), styles["bodyHeader_odd"]);
} }
if (ranks) {
row++;
writeString(row, 1, "Average ranks", "bodyHeader");
int col = 1;
for (const auto& model : models) {
stringstream oss;
oss << "=sum(indirect(address(" << 5 << "," << col + 2 << ")):indirect(address(" << row - 1 << "," << col + 2 << ")))/" << datasets.size();
worksheet_write_formula(worksheet, row, ++col, oss.str().c_str(), styles["bodyHeader_odd"]);
} }
void BestResultsExcel::footer() }
}
void BestResultsExcel::doFriedman()
{ {
if (friedman) {
worksheet = workbook_add_worksheet(workbook, "Friedman"); worksheet = workbook_add_worksheet(workbook, "Friedman");
vector<int> columns_sizes = { 5, datasetNameSize }; vector<int> columns_sizes = { 5, datasetNameSize };
for (int i = 0; i < models.size(); ++i) { for (int i = 0; i < models.size(); ++i) {
@ -153,4 +175,3 @@ namespace platform {
} }
} }
} }
}

View File

@ -12,25 +12,26 @@ namespace platform {
class BestResultsExcel : ExcelFile { class BestResultsExcel : ExcelFile {
public: public:
BestResultsExcel(const string& score, const vector<string>& models, const vector<string>& datasets, const json& table, bool friedman, double significance); BestResultsExcel(const string& score, const vector<string>& models, const vector<string>& datasets, const json& table, const map<string, map<string, float>>& ranks, bool friedman, double significance);
~BestResultsExcel(); ~BestResultsExcel();
void build(); void build();
string getFileName(); string getFileName();
private: private:
void header(); void header(bool ranks);
void body(); void body(bool ranks);
void footer(); void footer(bool ranks);
void formatColumns(); void formatColumns();
void doFriedman();
const string fileName = "BestResults.xlsx"; const string fileName = "BestResults.xlsx";
const string& score; string score;
const vector<string>& models; vector<string> models;
const vector<string>& datasets; vector<string> datasets;
const json& table; json table;
map<string, map<string, float>> ranksModels;
bool friedman; bool friedman;
double significance; double significance;
int modelNameSize = 12; // Min size of the column int modelNameSize = 12; // Min size of the column
int datasetNameSize = 25; // Min size of the column int datasetNameSize = 25; // Min size of the column
// map<string, map<string, float>>& ranksModels;
}; };
} }
#endif //BESTRESULTS_EXCEL_H #endif //BESTRESULTS_EXCEL_H