Move ResultsDatasetConsole to results folder

This commit is contained in:
2024-05-18 18:41:17 +02:00
parent 25bd7a42c6
commit b9e0c92334
9 changed files with 23 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
#ifndef REPORTBASE_H
#define REPORTBASE_H
#include <string>
#include <map>
#include <nlohmann/json.hpp>
#include "common/Paths.h"
#include "common/Symbols.h"

View File

@@ -3,6 +3,7 @@
#include "best/BestScore.h"
#include "common/CLocale.h"
#include "ReportConsole.h"
#include "main/Scores.h"
namespace platform {
std::string ReportConsole::headerLine(const std::string& text, int utf = 0)

View File

@@ -3,7 +3,6 @@
#include "best/BestScore.h"
#include "ReportExcel.h"
namespace platform {
ReportExcel::ReportExcel(json data_, bool compare, lxw_workbook* workbook, lxw_worksheet* worksheet) : ReportBase(data_, compare), ExcelFile(workbook, worksheet)
{
createFile();
@@ -194,6 +193,18 @@ namespace platform {
writeDouble(row, ++col, item, style);
}
}
// Classificacion report
if (lastResult.find("confusion_matrices") != lastResult.end()) {
// auto score = platform2::Scores::create_aggregate(lastResult, "confusion_matrices");
// row++;
// writeString(row, 1, "Classification Report", "bodyHeader");
// row++;
// auto output = platform2::Scores::classification_report("", "test");
// for (const auto& item : output) {
// writeString(row, 1, item, "text");
// row++;
// }
}
// Set with of columns to show those totals completely
worksheet_set_column(worksheet, 1, 1, 12, NULL);
for (int i = 2; i < 7; ++i) {

View File

@@ -1,7 +1,5 @@
#ifndef REPORT_EXCEL_H
#define REPORT_EXCEL_H
#include <map>
#include <xlsxwriter.h>
#include "common/Colors.h"
#include "ReportBase.h"
#include "ExcelFile.h"

View File

@@ -1,85 +0,0 @@
#include <iostream>
#include "common/Colors.h"
#include "results/ResultsDataset.h"
#include "ResultsDatasetConsole.h"
namespace platform {
bool ResultsDatasetsConsole::report(const std::string& dataset, const std::string& score, const std::string& model)
{
auto results = platform::ResultsDataset(dataset, model, score);
results.load();
if (results.empty()) {
std::cerr << Colors::RED() << "No results found for dataset " << dataset << " and model " << model << Colors::RESET() << std::endl;
return false;
}
results.sortModel();
int maxModel = results.maxModelSize();
int maxHyper = results.maxHyperSize();
double maxResult = results.maxResultScore();
//
// Build data for the Report
//
data = json::object();
data["dataset"] = dataset;
data["score"] = score;
data["model"] = model;
data["lengths"]["maxModel"] = maxModel;
data["lengths"]["maxHyper"] = maxHyper;
data["maxResult"] = maxResult;
data["results"] = json::array();
data["max_models"] = json::object(); // Max score per model
for (const auto& result : results) {
auto results = result.getData();
if (!data["max_models"].contains(result.getModel())) {
data["max_models"][result.getModel()] = 0;
}
for (const auto& item : results["results"]) {
if (item["dataset"] == dataset) {
// Store data for Excel report
json res = json::object();
res["date"] = result.getDate();
res["time"] = result.getTime();
res["model"] = result.getModel();
res["score"] = item["score"].get<double>();
res["hyperparameters"] = item["hyperparameters"].dump();
data["results"].push_back(res);
if (item["score"].get<double>() > data["max_models"][result.getModel()]) {
data["max_models"][result.getModel()] = item["score"].get<double>();
}
break;
}
}
}
//
// List the results
//
oss.str("");
header.clear();
body.clear();
oss << Colors::GREEN() << "Results of dataset " << dataset << " - for " << model << " model" << std::endl;
oss << "There are " << results.size() << " results" << std::endl;
oss << Colors::GREEN() << " # " << std::setw(maxModel + 1) << std::left << "Model" << "Date Time Score Hyperparameters" << std::endl;
oss << "=== " << std::string(maxModel, '=') << " ========== ======== =========== " << std::string(maxHyper, '=') << std::endl;
header.push_back(oss.str());
auto i = 0;
for (const auto& item : data["results"]) {
oss.str("");
auto color = (i % 2) ? Colors::BLUE() : Colors::CYAN();
auto score = item["score"].get<double>();
color = score == data["max_models"][item["model"].get<std::string>()] ? Colors::YELLOW() : color;
color = score == maxResult ? Colors::RED() : color;
oss << color << std::setw(3) << std::fixed << std::right << i++ << " ";
oss << std::setw(maxModel) << std::left << item["model"].get<std::string>() << " ";
oss << color << item["date"].get<std::string>() << " ";
oss << color << item["time"].get<std::string>() << " ";
oss << std::setw(11) << std::setprecision(9) << std::fixed << score << " ";
oss << item["hyperparameters"].get<std::string>() << std::endl;
body.push_back(oss.str());
}
return true;
}
}

View File

@@ -1,18 +0,0 @@
#ifndef RESULTSDATASETSCONSOLE_H
#define RESULTSDATASETSCONSOLE_H
#include <locale>
#include <string>
#include <sstream>
#include <nlohmann/json.hpp>
#include "results/ResultsDataset.h"
#include "ReportsPaged.h"
namespace platform {
class ResultsDatasetsConsole : public ReportsPaged {
public:
ResultsDatasetsConsole() = default;
~ResultsDatasetsConsole() = default;
bool report(const std::string& dataset, const std::string& score, const std::string& model);
};
}
#endif