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
#define BESTSCORE_H
#include <string>
class BestScore {
public:
static std::string title() { return "STree_default (linear-ovo)"; }
static double score() { return 22.109799; }
static std::string scoreName() { return "accuracy"; }
};
#include <map>
#include <utility>
#include "DotEnv.h"
namespace platform {
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

View File

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

View File

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

View File

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

View File

@ -163,9 +163,10 @@ namespace platform {
showSummary();
row += 4 + summary.size();
auto score = data["score_name"].get<string>();
if (score == BestScore::scoreName()) {
worksheet_merge_range(worksheet, row, 1, row, 5, (score + " compared to " + BestScore::title() + " .:").c_str(), efectiveStyle("text"));
writeDouble(row, 6, totalScore / BestScore::score(), "result");
auto best = BestScore::getScore(score);
if (best.first != "") {
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) {
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 <fstream>
#include <sstream>
#include "Result.h"
#include "Colors.h"
#include "BestScore.h"
#include "DotEnv.h"
#include "CLocale.h"
namespace platform {
@ -18,8 +19,9 @@ namespace platform {
score += result["score"].get<double>();
}
scoreName = data["score_name"];
if (scoreName == BestScore::scoreName()) {
score /= BestScore::score();
auto best = BestScore::getScore(scoreName);
if (best.first != "") {
score /= best.second;
}
title = data["title"];
duration = data["duration"];

View File

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