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