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();
}
if (excel) {
// BestResultsExcel excel(score, models, datasets, ranksModels, table, friedman, significance);
BestResultsExcel excel(score, models, datasets, table, friedman, significance);
BestResultsExcel excel(score, models, datasets, table, ranksModels, friedman, significance);
excel.build();
cout << Colors::YELLOW() << "** Excel file generated: " << excel.getFileName() << Colors::RESET() << endl;
}

View File

@ -4,8 +4,8 @@
#include "Statistics.h"
namespace platform {
BestResultsExcel::BestResultsExcel(const string& score, const vector<string>& models, const vector<string>& datasets, const json& table, bool friedman, double significance) :
score(score), models(models), datasets(datasets), table(table), friedman(friedman), significance(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), ranksModels(ranksModels), friedman(friedman), significance(significance)
{
workbook = workbook_new((Paths::excel() + fileName).c_str());
worksheet = workbook_add_worksheet(workbook, "Best Results");
@ -34,20 +34,30 @@ namespace platform {
}
void BestResultsExcel::build()
{
header();
body();
footer();
// Create Sheet with scores
header(false);
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()
{
return Paths::excel() + fileName;
}
void BestResultsExcel::header()
void BestResultsExcel::header(bool ranks)
{
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"]);
// Body header
row = 3;
int col = 1;
@ -57,7 +67,7 @@ namespace platform {
writeString(row, ++col, model.c_str(), "bodyHeader");
}
}
void BestResultsExcel::body()
void BestResultsExcel::body(bool ranks)
{
row = 4;
int i = 0;
@ -67,11 +77,14 @@ namespace platform {
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<double>();
double value = ranks ? ranksModels[item.key()][model] : table[model].at(item.key()).at(0).get<double>();
writeDouble(row, ++col, value, "result");
}
++row;
}
}
void BestResultsExcel::footer(bool ranks)
{
// Set Totals
writeString(row, 1, "Total", "bodyHeader");
int col = 1;
@ -80,10 +93,19 @@ namespace platform {
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"]);
}
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");
vector<int> columns_sizes = { 5, datasetNameSize };
for (int i = 0; i < models.size(); ++i) {
@ -152,5 +174,4 @@ namespace platform {
row++;
}
}
}
}

View File

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