Compare commits
2 Commits
ad5c3319bd
...
886dde7a06
Author | SHA1 | Date | |
---|---|---|---|
886dde7a06
|
|||
88468434e7
|
Submodule lib/libxlsxwriter updated: 26c4c20bab...284b61ba0b
@@ -22,6 +22,27 @@ namespace platform {
|
||||
colorOdd = 0xDCE6F1;
|
||||
colorEven = 0xFDE9D9;
|
||||
}
|
||||
lxw_worksheet* ExcelFile::createWorksheet(const std::string& name)
|
||||
{
|
||||
lxw_worksheet* sheet;
|
||||
std::string suffix = "";
|
||||
std::string efectiveName;
|
||||
int num = 1;
|
||||
// Create a sheet with the name of the model
|
||||
while (true) {
|
||||
efectiveName = name + suffix;
|
||||
if (workbook_get_worksheet_by_name(workbook, efectiveName.c_str())) {
|
||||
suffix = std::to_string(++num);
|
||||
} else {
|
||||
sheet = workbook_add_worksheet(workbook, efectiveName.c_str());
|
||||
break;
|
||||
}
|
||||
if (num > 100) {
|
||||
throw std::invalid_argument("Couldn't create sheet " + efectiveName);
|
||||
}
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
|
||||
lxw_workbook* ExcelFile::getWorkbook()
|
||||
{
|
||||
@@ -75,7 +96,7 @@ namespace platform {
|
||||
}
|
||||
void ExcelFile::boldGreen()
|
||||
{
|
||||
boldFontColor(0x00FF00);
|
||||
boldFontColor(0x009900);
|
||||
}
|
||||
void ExcelFile::boldRed()
|
||||
{
|
||||
|
@@ -24,6 +24,7 @@ namespace platform {
|
||||
void boldBlue(); //set blue color for the bold styles
|
||||
void boldGreen(); //set green color for the bold styles
|
||||
void createStyle(const std::string& name, lxw_format* style, bool odd);
|
||||
lxw_worksheet* createWorksheet(const std::string& name);
|
||||
void addColor(lxw_format* style, bool odd);
|
||||
lxw_format* efectiveStyle(const std::string& name);
|
||||
lxw_workbook* workbook;
|
||||
|
@@ -17,26 +17,7 @@ namespace platform {
|
||||
worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL);
|
||||
}
|
||||
}
|
||||
void ReportExcel::createWorksheet()
|
||||
{
|
||||
const std::string name = data["model"].get<std::string>();
|
||||
std::string suffix = "";
|
||||
std::string efectiveName;
|
||||
int num = 1;
|
||||
// Create a sheet with the name of the model
|
||||
while (true) {
|
||||
efectiveName = name + suffix;
|
||||
if (workbook_get_worksheet_by_name(workbook, efectiveName.c_str())) {
|
||||
suffix = std::to_string(++num);
|
||||
} else {
|
||||
worksheet = workbook_add_worksheet(workbook, efectiveName.c_str());
|
||||
break;
|
||||
}
|
||||
if (num > 100) {
|
||||
throw std::invalid_argument("Couldn't create sheet " + efectiveName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ReportExcel::createFile()
|
||||
{
|
||||
@@ -44,7 +25,8 @@ namespace platform {
|
||||
workbook = workbook_new((Paths::excel() + Paths::excelResults()).c_str());
|
||||
}
|
||||
if (worksheet == NULL) {
|
||||
createWorksheet();
|
||||
const std::string name = data["model"].get<std::string>();
|
||||
worksheet = createWorksheet(name);
|
||||
}
|
||||
setProperties(data["title"].get<std::string>());
|
||||
formatColumns();
|
||||
@@ -209,14 +191,14 @@ namespace platform {
|
||||
}
|
||||
void ReportExcel::create_classification_report(const json& result)
|
||||
{
|
||||
auto matrix_sheet = workbook_add_worksheet(workbook, "classif_report");
|
||||
|
||||
auto matrix_sheet = createWorksheet("clf_report");
|
||||
lxw_worksheet* tmp = worksheet;
|
||||
worksheet = matrix_sheet;
|
||||
if (matrix_sheet == NULL) {
|
||||
throw std::invalid_argument("Couldn't create sheet classif_report");
|
||||
}
|
||||
worksheet_merge_range(matrix_sheet, 0, 0, 0, 5, "Classification Report", efectiveStyle("bodyHeader"));
|
||||
int row = 2;
|
||||
row = 1;
|
||||
int col = 0;
|
||||
if (result.find("confusion_matrices_train") != result.end()) {
|
||||
// Train classification report
|
||||
@@ -229,11 +211,14 @@ namespace platform {
|
||||
auto item = result["confusion_matrices_train"][i];
|
||||
auto score_item = Scores(item);
|
||||
auto title = "Train Fold " + std::to_string(i);
|
||||
std::tie(new_row, new_col) = write_classification_report(score_item.classification_report_json(title), 2, new_col);
|
||||
std::tie(new_row, new_col) = write_classification_report(score_item.classification_report_json(title), 1, new_col);
|
||||
new_col++;
|
||||
}
|
||||
col = new_col;
|
||||
worksheet_merge_range(matrix_sheet, 0, 0, 0, col - 1, "Train Classification Report", efectiveStyle("headerRest"));
|
||||
}
|
||||
// Test classification report
|
||||
worksheet_merge_range(matrix_sheet, row, 0, row, col - 1, "Test Classification Report", efectiveStyle("headerRest"));
|
||||
auto score = Scores::create_aggregate(result, "confusion_matrices");
|
||||
auto test = score.classification_report_json("Test");
|
||||
int init_row = ++row;
|
||||
@@ -256,9 +241,10 @@ namespace platform {
|
||||
}
|
||||
std::pair<int, int> ReportExcel::write_classification_report(const json& result, int init_row, int init_col)
|
||||
{
|
||||
int row = init_row;
|
||||
row = init_row;
|
||||
auto text = result["title"].get<std::string>();
|
||||
worksheet_merge_range(worksheet, row++, init_col, row, init_col + 5, text.c_str(), efectiveStyle("bodyHeader"));
|
||||
worksheet_merge_range(worksheet, row, init_col, row + 1, init_col + 5, text.c_str(), efectiveStyle("bodyHeader"));
|
||||
row += 2;
|
||||
int col = init_col + 2;
|
||||
// Headers
|
||||
bool first_item = true;
|
||||
@@ -288,8 +274,6 @@ namespace platform {
|
||||
}
|
||||
row++;
|
||||
}
|
||||
worksheet_merge_range(worksheet, row, init_col, row, init_col + 5, "", efectiveStyle("text"));
|
||||
row++;
|
||||
// Accuracy and average f1-score
|
||||
for (const auto& item : { "accuracy", "averages", "weighted" }) {
|
||||
col = init_col + 2;
|
||||
@@ -307,11 +291,10 @@ namespace platform {
|
||||
row++;
|
||||
}
|
||||
// Confusion matrix
|
||||
worksheet_merge_range(worksheet, row, init_col, row, init_col + 5, "", efectiveStyle("bodyHeader"));
|
||||
row++;
|
||||
auto n_items = result["confusion_matrix"].size();
|
||||
worksheet_merge_range(worksheet, row, init_col, row, init_col + n_items + 1, "Confusion Matrix", efectiveStyle("bodyHeader"));
|
||||
row++;
|
||||
boldGreen();
|
||||
for (int i = 0; i < n_items; ++i) {
|
||||
col = init_col + 2;
|
||||
auto label = result["body"][i][0].get<std::string>();
|
||||
@@ -326,7 +309,7 @@ namespace platform {
|
||||
}
|
||||
row++;
|
||||
}
|
||||
int maxcol = std::max(5, int(init_col + n_items + 1));
|
||||
int maxcol = std::max(init_col + 5, int(init_col + n_items + 1));
|
||||
return { row, maxcol };
|
||||
}
|
||||
void ReportExcel::showSummary()
|
||||
|
@@ -15,7 +15,6 @@ namespace platform {
|
||||
private:
|
||||
void formatColumns();
|
||||
void createFile();
|
||||
void createWorksheet();
|
||||
void header() override;
|
||||
void body() override;
|
||||
void showSummary() override;
|
||||
|
Reference in New Issue
Block a user