Complete excel in b_list
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
DatasetsExcel::DatasetsExcel()
|
DatasetsExcel::DatasetsExcel(json& data) : data(data), ExcelFile()
|
||||||
{
|
{
|
||||||
file_name = "datasets.xlsx";
|
file_name = "datasets.xlsx";
|
||||||
workbook = workbook_new(getFileName().c_str());
|
workbook = workbook_new(getFileName().c_str());
|
||||||
@@ -17,34 +17,37 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void DatasetsExcel::report()
|
void DatasetsExcel::report()
|
||||||
{
|
{
|
||||||
|
int datasetNameSize = 25; // Min size of the column
|
||||||
|
int balanceSize = 75; // Min size of the column
|
||||||
worksheet = workbook_add_worksheet(workbook, "Datasets");
|
worksheet = workbook_add_worksheet(workbook, "Datasets");
|
||||||
formatColumns();
|
worksheet_merge_range(worksheet, 0, 0, 0, 5, "Datasets", styles["headerFirst"]);
|
||||||
worksheet_merge_range(worksheet, 0, 0, 0, 4, "Datasets", styles["headerFirst"]);
|
formatColumns(datasetNameSize, balanceSize);
|
||||||
// Body header
|
// Body header
|
||||||
row = 3;
|
row = 2;
|
||||||
int col = 1;
|
int col = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
// Get Datasets
|
for (const auto& name : { "Nº", "Dataset", "Samples", "Features", "Classes", "Balance" }) {
|
||||||
// auto data = platform::Datasets(false, platform::Paths::datasets());
|
writeString(row, col++, name, "bodyHeader");
|
||||||
// auto datasets = data.getNames();
|
}
|
||||||
auto datasets = std::vector<std::string>{ "iris", "wine", "digits", "breast_cancer" };
|
for (auto& [key, value] : data.items()) {
|
||||||
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++;
|
row++;
|
||||||
|
if (key.size() > datasetNameSize) {
|
||||||
|
datasetNameSize = key.size();
|
||||||
|
}
|
||||||
writeInt(row, 0, i++, "ints");
|
writeInt(row, 0, i++, "ints");
|
||||||
writeString(row, 1, name.c_str(), "text");
|
writeString(row, 1, key.c_str(), "text");
|
||||||
|
writeInt(row, 2, value["samples"], "ints");
|
||||||
|
writeInt(row, 3, value["features"], "ints");
|
||||||
|
writeInt(row, 4, value["classes"], "ints");
|
||||||
|
writeString(row, 5, value["balance"].get<std::string>().c_str(), "text");
|
||||||
}
|
}
|
||||||
row++;
|
row++;
|
||||||
formatColumns();
|
formatColumns(datasetNameSize, balanceSize);
|
||||||
}
|
}
|
||||||
|
void DatasetsExcel::formatColumns(int dataset, int balance)
|
||||||
void DatasetsExcel::formatColumns()
|
|
||||||
{
|
{
|
||||||
worksheet_freeze_panes(worksheet, 4, 2);
|
worksheet_freeze_panes(worksheet, 4, 2);
|
||||||
std::vector<int> columns_sizes = { 5, datasetNameSize };
|
std::vector<int> columns_sizes = { 5, dataset, 10, 10, 10, balance };
|
||||||
for (int i = 0; i < columns_sizes.size(); ++i) {
|
for (int i = 0; i < columns_sizes.size(); ++i) {
|
||||||
worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL);
|
worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL);
|
||||||
}
|
}
|
||||||
|
@@ -11,12 +11,13 @@ namespace platform {
|
|||||||
|
|
||||||
class DatasetsExcel : public ExcelFile {
|
class DatasetsExcel : public ExcelFile {
|
||||||
public:
|
public:
|
||||||
DatasetsExcel();
|
explicit DatasetsExcel(json& data);
|
||||||
~DatasetsExcel();
|
~DatasetsExcel();
|
||||||
void report();
|
void report();
|
||||||
private:
|
private:
|
||||||
void formatColumns();
|
void formatColumns(int dataset, int balance);
|
||||||
int datasetNameSize = 25; // Min size of the column
|
json data;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //DATASETS_EXCEL_H
|
#endif //DATASETS_EXCEL_H
|
@@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <argparse/argparse.hpp>
|
#include <argparse/argparse.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include "Paths.h"
|
#include "Paths.h"
|
||||||
#include "Colors.h"
|
#include "Colors.h"
|
||||||
#include "Datasets.h"
|
#include "Datasets.h"
|
||||||
@@ -15,7 +16,7 @@ struct separated : numpunct<char> {
|
|||||||
std::string do_grouping() const { return "\03"; }
|
std::string do_grouping() const { return "\03"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void outputBalance(const std::string& balance)
|
std::string outputBalance(const std::string& balance)
|
||||||
{
|
{
|
||||||
auto temp = std::string(balance);
|
auto temp = std::string(balance);
|
||||||
while (temp.size() > BALANCE_LENGTH - 1) {
|
while (temp.size() > BALANCE_LENGTH - 1) {
|
||||||
@@ -24,12 +25,12 @@ void outputBalance(const std::string& balance)
|
|||||||
std::cout << setw(52) << " ";
|
std::cout << setw(52) << " ";
|
||||||
temp = temp.substr(BALANCE_LENGTH);
|
temp = temp.substr(BALANCE_LENGTH);
|
||||||
}
|
}
|
||||||
std::cout << temp << std::endl;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
auto data = platform::Datasets(false, platform::Paths::datasets());
|
auto datasets = platform::Datasets(false, platform::Paths::datasets());
|
||||||
argparse::ArgumentParser program("b_list", { project_version.begin(), project_version.end() });
|
argparse::ArgumentParser program("b_list", { project_version.begin(), project_version.end() });
|
||||||
program.add_argument("--excel")
|
program.add_argument("--excel")
|
||||||
.help("Output in Excel format")
|
.help("Output in Excel format")
|
||||||
@@ -44,26 +45,34 @@ int main(int argc, char** argv)
|
|||||||
std::string balanceBars = std::string(BALANCE_LENGTH, '=');
|
std::string balanceBars = std::string(BALANCE_LENGTH, '=');
|
||||||
std::cout << "=== ============================== ====== ===== === " << balanceBars << std::endl;
|
std::cout << "=== ============================== ====== ===== === " << balanceBars << std::endl;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (const auto& dataset : data.getNames()) {
|
json data;
|
||||||
|
for (const auto& dataset : datasets.getNames()) {
|
||||||
auto color = num % 2 ? Colors::CYAN() : Colors::BLUE();
|
auto color = num % 2 ? Colors::CYAN() : Colors::BLUE();
|
||||||
std::cout << color << setw(3) << right << num++ << " ";
|
std::cout << color << setw(3) << right << num++ << " ";
|
||||||
std::cout << setw(30) << left << dataset << " ";
|
std::cout << setw(30) << left << dataset << " ";
|
||||||
data.loadDataset(dataset);
|
datasets.loadDataset(dataset);
|
||||||
auto nSamples = data.getNSamples(dataset);
|
auto nSamples = datasets.getNSamples(dataset);
|
||||||
std::cout << setw(6) << right << nSamples << " ";
|
std::cout << setw(6) << right << nSamples << " ";
|
||||||
std::cout << setw(5) << right << data.getFeatures(dataset).size() << " ";
|
std::cout << setw(5) << right << datasets.getFeatures(dataset).size() << " ";
|
||||||
std::cout << setw(3) << right << data.getNClasses(dataset) << " ";
|
std::cout << setw(3) << right << datasets.getNClasses(dataset) << " ";
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
std::string sep = "";
|
std::string sep = "";
|
||||||
for (auto number : data.getClassesCounts(dataset)) {
|
for (auto number : datasets.getClassesCounts(dataset)) {
|
||||||
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
|
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
|
||||||
sep = " / ";
|
sep = " / ";
|
||||||
}
|
}
|
||||||
outputBalance(oss.str());
|
auto balance = outputBalance(oss.str());
|
||||||
|
std::cout << balance << std::endl;
|
||||||
|
// Store data for Excel report
|
||||||
|
data[dataset] = json::object();
|
||||||
|
data[dataset]["samples"] = nSamples;
|
||||||
|
data[dataset]["features"] = datasets.getFeatures(dataset).size();
|
||||||
|
data[dataset]["classes"] = datasets.getNClasses(dataset);
|
||||||
|
data[dataset]["balance"] = oss.str();
|
||||||
}
|
}
|
||||||
std::cout << Colors::RESET() << std::endl;
|
std::cout << Colors::RESET() << std::endl;
|
||||||
if (excel) {
|
if (excel) {
|
||||||
auto report = platform::DatasetsExcel();
|
auto report = platform::DatasetsExcel(data);
|
||||||
report.report();
|
report.report();
|
||||||
std::cout << "Output saved in " << report.getFileName() << std::endl;
|
std::cout << "Output saved in " << report.getFileName() << std::endl;
|
||||||
}
|
}
|
||||||
|
@@ -87,11 +87,13 @@ namespace platform {
|
|||||||
if (name == "textCentered") {
|
if (name == "textCentered") {
|
||||||
format_set_align(style, LXW_ALIGN_CENTER);
|
format_set_align(style, LXW_ALIGN_CENTER);
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
|
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||||
format_set_border(style, LXW_BORDER_THIN);
|
format_set_border(style, LXW_BORDER_THIN);
|
||||||
} else if (name == "text") {
|
} else if (name == "text") {
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
format_set_border(style, LXW_BORDER_THIN);
|
format_set_border(style, LXW_BORDER_THIN);
|
||||||
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||||
|
format_set_text_wrap(style);
|
||||||
} else if (name == "bodyHeader") {
|
} else if (name == "bodyHeader") {
|
||||||
format_set_bold(style);
|
format_set_bold(style);
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
@@ -101,18 +103,22 @@ namespace platform {
|
|||||||
format_set_bg_color(style, lxw_color_t(colorTitle));
|
format_set_bg_color(style, lxw_color_t(colorTitle));
|
||||||
} else if (name == "result") {
|
} else if (name == "result") {
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
|
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||||
format_set_border(style, LXW_BORDER_THIN);
|
format_set_border(style, LXW_BORDER_THIN);
|
||||||
format_set_num_format(style, "0.0000000");
|
format_set_num_format(style, "0.0000000");
|
||||||
} else if (name == "time") {
|
} else if (name == "time") {
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
format_set_border(style, LXW_BORDER_THIN);
|
format_set_border(style, LXW_BORDER_THIN);
|
||||||
|
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||||
format_set_num_format(style, "#,##0.000000");
|
format_set_num_format(style, "#,##0.000000");
|
||||||
} else if (name == "ints") {
|
} else if (name == "ints") {
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
format_set_num_format(style, "###,##0");
|
format_set_num_format(style, "###,##0");
|
||||||
|
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||||
format_set_border(style, LXW_BORDER_THIN);
|
format_set_border(style, LXW_BORDER_THIN);
|
||||||
} else if (name == "floats") {
|
} else if (name == "floats") {
|
||||||
format_set_border(style, LXW_BORDER_THIN);
|
format_set_border(style, LXW_BORDER_THIN);
|
||||||
|
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||||
format_set_font_size(style, normalSize);
|
format_set_font_size(style, normalSize);
|
||||||
format_set_num_format(style, "#,##0.00");
|
format_set_num_format(style, "#,##0.00");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user