Refactor BestScore and add experiment to .env

This commit is contained in:
Ricardo Montañana Gómez 2023-10-23 16:12:52 +02:00
parent 7bcd2eed06
commit 1f705f6018
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
7 changed files with 38 additions and 18 deletions

View File

@ -1,10 +1,28 @@
#ifndef BESTSCORE_H #ifndef BESTSCORE_H
#define BESTSCORE_H #define BESTSCORE_H
#include <string> #include <string>
class BestScore { #include <map>
public: #include <utility>
static std::string title() { return "STree_default (linear-ovo)"; } #include "DotEnv.h"
static double score() { return 22.109799; } namespace platform {
static std::string scoreName() { return "accuracy"; } class BestScore {
}; public:
static pair<string, double> getScore(const std::string& metric)
{
static map<pair<string, string>, pair<string, double>> data = {
{{"discretiz", "accuracy"}, {"STree_default (linear-ovo)", 22.109799}},
//{{"odte", "accuracy"}, {"STree_default (linear-ovo)", 22.109799}},
};
auto env = platform::DotEnv();
string experiment = env.get("experiment");
try {
return data[{experiment, metric}];
}
catch (...) {
return { "", 0.0 };
}
}
};
}
#endif #endif

View File

@ -2,7 +2,6 @@
#include <locale> #include <locale>
#include "Datasets.h" #include "Datasets.h"
#include "ReportBase.h" #include "ReportBase.h"
#include "BestScore.h"
#include "DotEnv.h" #include "DotEnv.h"
namespace platform { namespace platform {

View File

@ -1,3 +1,4 @@
#include <iostream>
#include <sstream> #include <sstream>
#include <locale> #include <locale>
#include "ReportConsole.h" #include "ReportConsole.h"
@ -94,9 +95,10 @@ namespace platform {
cout << Colors::MAGENTA() << string(MAXL, '*') << endl; cout << Colors::MAGENTA() << string(MAXL, '*') << endl;
showSummary(); showSummary();
auto score = data["score_name"].get<string>(); auto score = data["score_name"].get<string>();
if (score == BestScore::scoreName()) { auto best = BestScore::getScore(score);
if (best.first != "") {
stringstream oss; stringstream oss;
oss << score << " compared to " << BestScore::title() << " .: " << totalScore / BestScore::score(); oss << score << " compared to " << best.first << " .: " << totalScore / best.second;
cout << headerLine(oss.str()); cout << headerLine(oss.str());
} }
if (!getExistBestFile() && compare) { if (!getExistBestFile() && compare) {

View File

@ -1,7 +1,6 @@
#ifndef REPORTCONSOLE_H #ifndef REPORTCONSOLE_H
#define REPORTCONSOLE_H #define REPORTCONSOLE_H
#include <string> #include <string>
#include <iostream>
#include "ReportBase.h" #include "ReportBase.h"
#include "Colors.h" #include "Colors.h"

View File

@ -163,9 +163,10 @@ namespace platform {
showSummary(); showSummary();
row += 4 + summary.size(); row += 4 + summary.size();
auto score = data["score_name"].get<string>(); auto score = data["score_name"].get<string>();
if (score == BestScore::scoreName()) { auto best = BestScore::getScore(score);
worksheet_merge_range(worksheet, row, 1, row, 5, (score + " compared to " + BestScore::title() + " .:").c_str(), efectiveStyle("text")); if (best.first != "") {
writeDouble(row, 6, totalScore / BestScore::score(), "result"); worksheet_merge_range(worksheet, row, 1, row, 5, (score + " compared to " + best.first + " .:").c_str(), efectiveStyle("text"));
writeDouble(row, 6, totalScore / best.second, "result");
} }
if (!getExistBestFile() && compare) { if (!getExistBestFile() && compare) {
worksheet_write_string(worksheet, row + 1, 0, "*** Best Results File not found. Couldn't compare any result!", styles["summaryStyle"]); worksheet_write_string(worksheet, row + 1, 0, "*** Best Results File not found. Couldn't compare any result!", styles["summaryStyle"]);

View File

@ -1,9 +1,10 @@
#include "Result.h"
#include "BestScore.h"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include "Result.h"
#include "Colors.h" #include "Colors.h"
#include "BestScore.h" #include "DotEnv.h"
#include "CLocale.h" #include "CLocale.h"
namespace platform { namespace platform {
@ -18,8 +19,9 @@ namespace platform {
score += result["score"].get<double>(); score += result["score"].get<double>();
} }
scoreName = data["score_name"]; scoreName = data["score_name"];
if (scoreName == BestScore::scoreName()) { auto best = BestScore::getScore(scoreName);
score /= BestScore::score(); if (best.first != "") {
score /= best.second;
} }
title = data["title"]; title = data["title"];
duration = data["duration"]; duration = data["duration"];

View File

@ -1,6 +1,5 @@
#include "Results.h" #include "Results.h"
#include <algorithm> #include <algorithm>
#include "BestScore.h"
namespace platform { namespace platform {
Results::Results(const string& path, const string& model, const string& score, bool complete, bool partial, bool compare) : Results::Results(const string& path, const string& model, const string& score, bool complete, bool partial, bool compare) :