Refactor datasetsExcel
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
DatasetsExcel::DatasetsExcel(json& data) : data(data), ExcelFile()
|
DatasetsExcel::DatasetsExcel()
|
||||||
{
|
{
|
||||||
file_name = "datasets.xlsx";
|
file_name = "datasets.xlsx";
|
||||||
workbook = workbook_new(getFileName().c_str());
|
workbook = workbook_new(getFileName().c_str());
|
||||||
@@ -15,39 +15,35 @@ namespace platform {
|
|||||||
{
|
{
|
||||||
workbook_close(workbook);
|
workbook_close(workbook);
|
||||||
}
|
}
|
||||||
void DatasetsExcel::report()
|
void DatasetsExcel::report(json& data)
|
||||||
{
|
{
|
||||||
int datasetNameSize = 25; // Min size of the column
|
int datasetNameSize = 25; // Min size of the column
|
||||||
int balanceSize = 75; // 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");
|
||||||
|
// Header
|
||||||
worksheet_merge_range(worksheet, 0, 0, 0, 5, "Datasets", styles["headerFirst"]);
|
worksheet_merge_range(worksheet, 0, 0, 0, 5, "Datasets", styles["headerFirst"]);
|
||||||
formatColumns(datasetNameSize, balanceSize);
|
|
||||||
// Body header
|
// Body header
|
||||||
row = 2;
|
row = 2;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
int i = 0;
|
|
||||||
for (const auto& name : { "Nº", "Dataset", "Samples", "Features", "Classes", "Balance" }) {
|
for (const auto& name : { "Nº", "Dataset", "Samples", "Features", "Classes", "Balance" }) {
|
||||||
writeString(row, col++, name, "bodyHeader");
|
writeString(row, col++, name, "bodyHeader");
|
||||||
}
|
}
|
||||||
|
// Body
|
||||||
for (auto& [key, value] : data.items()) {
|
for (auto& [key, value] : data.items()) {
|
||||||
row++;
|
row++;
|
||||||
if (key.size() > datasetNameSize) {
|
if (key.size() > datasetNameSize) {
|
||||||
datasetNameSize = key.size();
|
datasetNameSize = key.size();
|
||||||
}
|
}
|
||||||
writeInt(row, 0, i++, "ints");
|
writeInt(row, 0, row - 3, "ints");
|
||||||
writeString(row, 1, key.c_str(), "text");
|
writeString(row, 1, key.c_str(), "text");
|
||||||
writeInt(row, 2, value["samples"], "ints");
|
writeInt(row, 2, value["samples"], "ints");
|
||||||
writeInt(row, 3, value["features"], "ints");
|
writeInt(row, 3, value["features"], "ints");
|
||||||
writeInt(row, 4, value["classes"], "ints");
|
writeInt(row, 4, value["classes"], "ints");
|
||||||
writeString(row, 5, value["balance"].get<std::string>().c_str(), "text");
|
writeString(row, 5, value["balance"].get<std::string>().c_str(), "text");
|
||||||
}
|
}
|
||||||
row++;
|
// Format columns
|
||||||
formatColumns(datasetNameSize, balanceSize);
|
|
||||||
}
|
|
||||||
void DatasetsExcel::formatColumns(int dataset, int balance)
|
|
||||||
{
|
|
||||||
worksheet_freeze_panes(worksheet, 3, 2);
|
worksheet_freeze_panes(worksheet, 3, 2);
|
||||||
std::vector<int> columns_sizes = { 5, dataset, 10, 10, 10, balance };
|
std::vector<int> columns_sizes = { 5, datasetNameSize, 10, 10, 10, balanceSize };
|
||||||
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,13 +11,9 @@ namespace platform {
|
|||||||
|
|
||||||
class DatasetsExcel : public ExcelFile {
|
class DatasetsExcel : public ExcelFile {
|
||||||
public:
|
public:
|
||||||
explicit DatasetsExcel(json& data);
|
DatasetsExcel();
|
||||||
~DatasetsExcel();
|
~DatasetsExcel();
|
||||||
void report();
|
void report(json& data);
|
||||||
private:
|
|
||||||
void formatColumns(int dataset, int balance);
|
|
||||||
json data;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //DATASETS_EXCEL_H
|
#endif //DATASETS_EXCEL_H
|
@@ -72,8 +72,8 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
std::cout << Colors::RESET() << std::endl;
|
std::cout << Colors::RESET() << std::endl;
|
||||||
if (excel) {
|
if (excel) {
|
||||||
auto report = platform::DatasetsExcel(data);
|
auto report = platform::DatasetsExcel();
|
||||||
report.report();
|
report.report(data);
|
||||||
std::cout << "Output saved in " << report.getFileName() << std::endl;
|
std::cout << "Output saved in " << report.getFileName() << std::endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user