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