Begin b_list excel
This commit is contained in:
51
src/list/DatasetsExcel.cc
Normal file
51
src/list/DatasetsExcel.cc
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <sstream>
|
||||
#include "DatasetsExcel.h"
|
||||
#include "Paths.h"
|
||||
|
||||
|
||||
namespace platform {
|
||||
DatasetsExcel::DatasetsExcel()
|
||||
{
|
||||
file_name = "datasets.xlsx";
|
||||
workbook = workbook_new(getFileName().c_str());
|
||||
setProperties("Datasets");
|
||||
}
|
||||
DatasetsExcel::~DatasetsExcel()
|
||||
{
|
||||
workbook_close(workbook);
|
||||
}
|
||||
void DatasetsExcel::report()
|
||||
{
|
||||
worksheet = workbook_add_worksheet(workbook, "Datasets");
|
||||
formatColumns();
|
||||
worksheet_merge_range(worksheet, 0, 0, 0, 4, "Datasets", styles["headerFirst"]);
|
||||
// Body header
|
||||
row = 3;
|
||||
int col = 1;
|
||||
int i = 0;
|
||||
// Get Datasets
|
||||
// auto data = platform::Datasets(false, platform::Paths::datasets());
|
||||
// auto datasets = data.getNames();
|
||||
auto datasets = std::vector<std::string>{ "iris", "wine", "digits", "breast_cancer" };
|
||||
int maxDatasetName = (*std::max_element(datasets.begin(), datasets.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })).size();
|
||||
datasetNameSize = std::max(datasetNameSize, maxDatasetName);
|
||||
writeString(row, 0, "Nº", "bodyHeader");
|
||||
writeString(row, 1, "Dataset", "bodyHeader");
|
||||
for (auto const& name : datasets) {
|
||||
row++;
|
||||
writeInt(row, 0, i++, "ints");
|
||||
writeString(row, 1, name.c_str(), "text");
|
||||
}
|
||||
row++;
|
||||
formatColumns();
|
||||
}
|
||||
|
||||
void DatasetsExcel::formatColumns()
|
||||
{
|
||||
worksheet_freeze_panes(worksheet, 4, 2);
|
||||
std::vector<int> columns_sizes = { 5, datasetNameSize };
|
||||
for (int i = 0; i < columns_sizes.size(); ++i) {
|
||||
worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL);
|
||||
}
|
||||
}
|
||||
}
|
22
src/list/DatasetsExcel.h
Normal file
22
src/list/DatasetsExcel.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef DATASETS_EXCEL_H
|
||||
#define DATASETS_EXCEL_H
|
||||
#include "ExcelFile.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace platform {
|
||||
|
||||
class DatasetsExcel : public ExcelFile {
|
||||
public:
|
||||
DatasetsExcel();
|
||||
~DatasetsExcel();
|
||||
void report();
|
||||
private:
|
||||
void formatColumns();
|
||||
int datasetNameSize = 25; // Min size of the column
|
||||
};
|
||||
}
|
||||
#endif //DATASETS_EXCEL_H
|
71
src/list/b_list.cc
Normal file
71
src/list/b_list.cc
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <argparse/argparse.hpp>
|
||||
#include "Paths.h"
|
||||
#include "Colors.h"
|
||||
#include "Datasets.h"
|
||||
#include "DatasetsExcel.h"
|
||||
#include "config.h"
|
||||
|
||||
const int BALANCE_LENGTH = 75;
|
||||
|
||||
struct separated : numpunct<char> {
|
||||
char do_decimal_point() const { return ','; }
|
||||
char do_thousands_sep() const { return '.'; }
|
||||
std::string do_grouping() const { return "\03"; }
|
||||
};
|
||||
|
||||
void outputBalance(const std::string& balance)
|
||||
{
|
||||
auto temp = std::string(balance);
|
||||
while (temp.size() > BALANCE_LENGTH - 1) {
|
||||
auto part = temp.substr(0, BALANCE_LENGTH);
|
||||
std::cout << part << std::endl;
|
||||
std::cout << setw(52) << " ";
|
||||
temp = temp.substr(BALANCE_LENGTH);
|
||||
}
|
||||
std::cout << temp << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto data = platform::Datasets(false, platform::Paths::datasets());
|
||||
argparse::ArgumentParser program("b_list", { project_version.begin(), project_version.end() });
|
||||
program.add_argument("--excel")
|
||||
.help("Output in Excel format")
|
||||
.default_value(false)
|
||||
.implicit_value(true);
|
||||
program.parse_args(argc, argv);
|
||||
auto excel = program.get<bool>("--excel");
|
||||
locale mylocale(std::cout.getloc(), new separated);
|
||||
locale::global(mylocale);
|
||||
std::cout.imbue(mylocale);
|
||||
std::cout << Colors::GREEN() << " # Dataset Sampl. Feat. Cls Balance" << std::endl;
|
||||
std::string balanceBars = std::string(BALANCE_LENGTH, '=');
|
||||
std::cout << "=== ============================== ====== ===== === " << balanceBars << std::endl;
|
||||
int num = 0;
|
||||
for (const auto& dataset : data.getNames()) {
|
||||
auto color = num % 2 ? Colors::CYAN() : Colors::BLUE();
|
||||
std::cout << color << setw(3) << right << num++ << " ";
|
||||
std::cout << setw(30) << left << dataset << " ";
|
||||
data.loadDataset(dataset);
|
||||
auto nSamples = data.getNSamples(dataset);
|
||||
std::cout << setw(6) << right << nSamples << " ";
|
||||
std::cout << setw(5) << right << data.getFeatures(dataset).size() << " ";
|
||||
std::cout << setw(3) << right << data.getNClasses(dataset) << " ";
|
||||
std::stringstream oss;
|
||||
std::string sep = "";
|
||||
for (auto number : data.getClassesCounts(dataset)) {
|
||||
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
|
||||
sep = " / ";
|
||||
}
|
||||
outputBalance(oss.str());
|
||||
}
|
||||
std::cout << Colors::RESET() << std::endl;
|
||||
if (excel) {
|
||||
auto report = platform::DatasetsExcel();
|
||||
report.report();
|
||||
std::cout << "Output saved in " << report.getFileName() << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user