Create Base class for paged reports
This commit is contained in:
@@ -40,7 +40,7 @@ target_link_libraries(b_grid ${MPI_CXX_LIBRARIES} "${PyClassifiers}" "${BayesNet
|
||||
add_executable(b_list commands/b_list.cpp ${list_sources}
|
||||
common/Datasets.cpp common/Dataset.cpp
|
||||
main/Models.cpp
|
||||
reports/ReportExcel.cpp reports/ExcelFile.cpp reports/ReportBase.cpp reports/DatasetsExcel.cpp reports/DatasetsConsole.cpp reports/ResultsDatasetConsole.cpp
|
||||
reports/ReportExcel.cpp reports/ExcelFile.cpp reports/ReportBase.cpp reports/DatasetsExcel.cpp reports/DatasetsConsole.cpp reports/ResultsDatasetConsole.cpp reports/ReportsPaged.cpp
|
||||
results/Result.cpp results/ResultsDatasetExcel.cpp results/ResultsDataset.cpp
|
||||
)
|
||||
target_link_libraries(b_list "${PyClassifiers}" "${BayesNet}" ArffFiles mdlp ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::python Boost::numpy "${XLSXWRITER_LIB}")
|
||||
@@ -61,7 +61,7 @@ list(TRANSFORM manage_sources PREPEND manage/)
|
||||
add_executable(
|
||||
b_manage commands/b_manage.cpp ${manage_sources}
|
||||
common/Datasets.cpp common/Dataset.cpp
|
||||
reports/ReportConsole.cpp reports/ReportExcel.cpp reports/ReportExcelCompared.cpp reports/ReportBase.cpp reports/ExcelFile.cpp reports/DatasetsConsole.cpp reports/ResultsDatasetConsole.cpp
|
||||
reports/ReportConsole.cpp reports/ReportExcel.cpp reports/ReportExcelCompared.cpp reports/ReportBase.cpp reports/ExcelFile.cpp reports/DatasetsConsole.cpp reports/ResultsDatasetConsole.cpp reports/ReportsPaged.cpp
|
||||
results/Result.cpp results/ResultsDataset.cpp
|
||||
)
|
||||
target_link_libraries(b_manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)
|
||||
|
@@ -37,7 +37,7 @@ void list_results(argparse::ArgumentParser& program)
|
||||
auto model = program.get<string>("model");
|
||||
auto excel = program.get<bool>("excel");
|
||||
auto report = platform::ResultsDatasetsConsole();
|
||||
report.list_results(dataset, score, model);
|
||||
report.report(dataset, score, model);
|
||||
std::cout << report.getOutput();
|
||||
if (excel) {
|
||||
auto data = report.getData();
|
||||
|
@@ -18,25 +18,11 @@ namespace platform {
|
||||
line += temp + "\n";
|
||||
body.push_back(line);
|
||||
}
|
||||
std::string DatasetsConsole::getOutput() const
|
||||
{
|
||||
std::string s;
|
||||
for (const auto& piece : header) s += piece;
|
||||
for (const auto& piece : body) s += piece;
|
||||
return s;
|
||||
}
|
||||
std::string DatasetsConsole::getHeader() const
|
||||
{
|
||||
std::string s;
|
||||
for (const auto& piece : header) s += piece;
|
||||
return s;
|
||||
}
|
||||
void DatasetsConsole::report()
|
||||
{
|
||||
header.clear();
|
||||
body.clear();
|
||||
auto datasets = platform::Datasets(false, platform::Paths::datasets());
|
||||
auto loc = std::locale("es_ES.UTF-8");
|
||||
std::stringstream sheader;
|
||||
auto datasets_names = datasets.getNames();
|
||||
int maxName = std::max(size_t(7), (*max_element(datasets_names.begin(), datasets_names.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })).size());
|
||||
@@ -66,9 +52,8 @@ namespace platform {
|
||||
line << setw(6) << right << nSamples << " ";
|
||||
line << setw(5) << right << datasets.getFeatures(dataset).size() << " ";
|
||||
line << setw(3) << right << datasets.getNClasses(dataset) << " ";
|
||||
std::stringstream oss;
|
||||
oss.imbue(loc);
|
||||
std::string sep = "";
|
||||
oss.str("");
|
||||
for (auto number : datasets.getClassesCounts(dataset)) {
|
||||
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
|
||||
sep = " / ";
|
||||
|
@@ -3,26 +3,20 @@
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "ReportsPaged.h"
|
||||
|
||||
namespace platform {
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
class DatasetsConsole {
|
||||
class DatasetsConsole : public ReportsPaged {
|
||||
public:
|
||||
static const int BALANCE_LENGTH;
|
||||
DatasetsConsole() = default;
|
||||
~DatasetsConsole() = default;
|
||||
std::string getOutput() const;
|
||||
std::string getHeader() const;
|
||||
std::vector<std::string>& getBody() { return body; }
|
||||
int getNumLines() const { return body.size(); }
|
||||
json& getData() { return data; }
|
||||
void report();
|
||||
private:
|
||||
void split_lines(int name_len, std::string line, const std::string& balance);
|
||||
std::vector<std::string> header, body;
|
||||
json data;
|
||||
};
|
||||
}
|
||||
|
||||
|
24
src/reports/ReportsPaged.cpp
Normal file
24
src/reports/ReportsPaged.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "common/Colors.h"
|
||||
#include "ReportsPaged.h"
|
||||
|
||||
namespace platform {
|
||||
ReportsPaged::ReportsPaged()
|
||||
{
|
||||
loc = std::locale("es_ES.UTF-8");
|
||||
oss.imbue(loc);
|
||||
}
|
||||
std::string ReportsPaged::getOutput() const
|
||||
{
|
||||
std::string s;
|
||||
for (const auto& piece : header) s += piece;
|
||||
for (const auto& piece : body) s += piece;
|
||||
return s;
|
||||
}
|
||||
std::string ReportsPaged::getHeader() const
|
||||
{
|
||||
std::string s;
|
||||
for (const auto& piece : header) s += piece;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
26
src/reports/ReportsPaged.h
Normal file
26
src/reports/ReportsPaged.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace platform {
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ReportsPaged {
|
||||
public:
|
||||
ReportsPaged();
|
||||
~ReportsPaged() = default;
|
||||
std::string getOutput() const;
|
||||
std::string getHeader() const;
|
||||
std::vector<std::string>& getBody() { return body; }
|
||||
int getNumLines() const { return body.size(); }
|
||||
json& getData() { return data; }
|
||||
protected:
|
||||
std::vector<std::string> header, body;
|
||||
json data;
|
||||
std::stringstream oss;
|
||||
std::locale loc;
|
||||
};
|
||||
}
|
||||
|
@@ -1,18 +1,16 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "common/Colors.h"
|
||||
#include "results/ResultsDataset.h"
|
||||
#include "ResultsDatasetConsole.h"
|
||||
namespace platform {
|
||||
void ResultsDatasetsConsole::list_results(const std::string& dataset, const std::string& score, const std::string& model)
|
||||
void ResultsDatasetsConsole::report(const std::string& dataset, const std::string& score, const std::string& model)
|
||||
{
|
||||
output.str("");
|
||||
auto loc = std::locale("es_ES");
|
||||
output.imbue(loc);
|
||||
auto results = platform::ResultsDataset(dataset, model, score);
|
||||
results.load();
|
||||
results.sortModel();
|
||||
if (results.empty()) {
|
||||
output << Colors::RED() << "No results found for dataset " << dataset << " and model " << model << Colors::RESET() << std::endl;
|
||||
std::cerr << Colors::RED() << "No results found for dataset " << dataset << " and model " << model << Colors::RESET() << std::endl;
|
||||
return;
|
||||
}
|
||||
int maxModel = results.maxModelSize();
|
||||
@@ -55,24 +53,28 @@ namespace platform {
|
||||
//
|
||||
// List the results
|
||||
//
|
||||
output << Colors::GREEN() << "Results of dataset " << dataset << " - for " << model << " model" << std::endl;
|
||||
output << "There are " << results.size() << " results" << std::endl;
|
||||
output << Colors::GREEN() << " # " << std::setw(maxModel + 1) << std::left << "Model" << "Date Time Score Hyperparameters" << std::endl;
|
||||
output << "=== " << std::string(maxModel, '=') << " ========== ======== =========== " << std::string(maxHyper, '=') << std::endl;
|
||||
numLines = 4;
|
||||
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;
|
||||
output << color << std::setw(3) << std::fixed << std::right << i++ << " ";
|
||||
output << std::setw(maxModel) << std::left << item["model"].get<std::string>() << " ";
|
||||
output << color << item["date"].get<std::string>() << " ";
|
||||
output << color << item["time"].get<std::string>() << " ";
|
||||
output << std::setw(11) << std::setprecision(9) << std::fixed << score << " ";
|
||||
output << item["hyperparameters"].get<std::string>() << std::endl;
|
||||
numLines++;
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,20 +5,14 @@
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "results/ResultsDataset.h"
|
||||
#include "ReportsPaged.h"
|
||||
|
||||
namespace platform {
|
||||
class ResultsDatasetsConsole {
|
||||
class ResultsDatasetsConsole : public ReportsPaged {
|
||||
public:
|
||||
ResultsDatasetsConsole() = default;
|
||||
~ResultsDatasetsConsole() = default;
|
||||
std::string getOutput() const { return output.str(); }
|
||||
int getNumLines() const { return numLines; }
|
||||
json& getData() { return data; }
|
||||
void list_results(const std::string& dataset, const std::string& score, const std::string& model);
|
||||
private:
|
||||
std::stringstream output;
|
||||
json data;
|
||||
int numLines = 0;
|
||||
void report(const std::string& dataset, const std::string& score, const std::string& model);
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user