Complete sheet with totals
This commit is contained in:
@@ -189,6 +189,10 @@ namespace platform {
|
||||
std::cout << Colors::RED() << "A and B cannot be the same!" << Colors::RESET() << std::endl;
|
||||
break;
|
||||
}
|
||||
if (!results.at(index).isComplete()) {
|
||||
std::cout << Colors::RED() << "A must be a complete result!" << Colors::RESET() << std::endl;
|
||||
break;
|
||||
}
|
||||
index_A = index;
|
||||
break;
|
||||
case 'b':
|
||||
@@ -197,6 +201,10 @@ namespace platform {
|
||||
std::cout << Colors::RED() << "A and B cannot be the same!" << Colors::RESET() << std::endl;
|
||||
break;
|
||||
}
|
||||
if (!results.at(index).isComplete()) {
|
||||
std::cout << Colors::RED() << "B must be a complete result!" << Colors::RESET() << std::endl;
|
||||
break;
|
||||
}
|
||||
index_B = index;
|
||||
} else {
|
||||
// back to show the report
|
||||
|
@@ -121,12 +121,17 @@ namespace platform {
|
||||
format_set_align(style, LXW_ALIGN_VERTICAL_CENTER);
|
||||
format_set_font_size(style, normalSize);
|
||||
format_set_num_format(style, "#,##0.00");
|
||||
} else if (name == "percentage") {
|
||||
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%");
|
||||
}
|
||||
}
|
||||
|
||||
void ExcelFile::createFormats()
|
||||
{
|
||||
auto styleNames = { "text", "textCentered", "bodyHeader", "result", "time", "ints", "floats" };
|
||||
auto styleNames = { "text", "textCentered", "bodyHeader", "result", "time", "ints", "floats", "percentage" };
|
||||
lxw_format* style;
|
||||
for (std::string name : styleNames) {
|
||||
lxw_format* style = workbook_add_format(workbook);
|
||||
|
@@ -2,20 +2,136 @@
|
||||
|
||||
namespace platform {
|
||||
|
||||
ReportExcelCompared::ReportExcelCompared(json& data_A, json& data_B) : data_A(data_A), data_B(data_B), workbook(NULL)
|
||||
ReportExcelCompared::ReportExcelCompared(json& data_A, json& data_B) : data_A(data_A), data_B(data_B), ExcelFile(NULL, NULL)
|
||||
{
|
||||
ReportExcel report(data_A, false, workbook);
|
||||
workbook = report.getWorkbook();
|
||||
report.show();
|
||||
report = ReportExcel(data_B, false, workbook);
|
||||
report.show();
|
||||
}
|
||||
ReportExcelCompared::~ReportExcelCompared()
|
||||
{
|
||||
workbook_close(workbook);
|
||||
if (workbook)
|
||||
workbook_close(workbook);
|
||||
}
|
||||
void ReportExcelCompared::report()
|
||||
{
|
||||
|
||||
// Create a new workbook and add the two worksheets A & B
|
||||
workbook = workbook_new((Paths::excel() + Paths::excelResults()).c_str());
|
||||
worksheet = workbook_add_worksheet(workbook, "A");
|
||||
createFormats();
|
||||
ReportExcel report(data_A, false, workbook, worksheet);
|
||||
workbook = report.getWorkbook();
|
||||
report.show();
|
||||
worksheet = workbook_add_worksheet(workbook, "B");
|
||||
report = ReportExcel(data_B, false, workbook, worksheet);
|
||||
report.show();
|
||||
// Add the comparison worksheet
|
||||
worksheet = workbook_add_worksheet(workbook, "Comparison");
|
||||
header();
|
||||
body();
|
||||
}
|
||||
void ReportExcelCompared::header()
|
||||
{
|
||||
worksheet_merge_range(worksheet, 0, 0, 0, 20, "Compare Results A & B", styles["headerFirst"]);
|
||||
}
|
||||
double diff(double a, double b)
|
||||
{
|
||||
return (a - b) / b;
|
||||
}
|
||||
void ReportExcelCompared::body()
|
||||
{
|
||||
// Body Header
|
||||
auto sizes = std::vector<int>({ 22, 10, 9, 7, 12, 12, 9, 12, 12, 9, 12, 12, 9, 12, 12, 9, 15, 15, 9, 15, 15 });
|
||||
auto head_a = std::vector<std::string>({ "Dataset", "Samples", "Features", "Classes" });
|
||||
auto head_b = std::vector<std::string>({ "Nodes", "Edges", "States", "Score", "Time" });
|
||||
int headerRow = 3;
|
||||
int col = 0;
|
||||
for (const auto& item : head_a) {
|
||||
worksheet_merge_range(worksheet, headerRow, col, headerRow + 1, col, item.c_str(), styles["bodyHeader_even"]);
|
||||
col++;
|
||||
}
|
||||
for (const auto& item : head_b) {
|
||||
worksheet_merge_range(worksheet, headerRow, col, headerRow, col + 2, item.c_str(), styles["bodyHeader_even"]);
|
||||
writeString(headerRow + 1, col, "A", "bodyHeader");
|
||||
writeString(headerRow + 1, col + 1, "B", "bodyHeader");
|
||||
writeString(headerRow + 1, col + 2, "Δ", "bodyHeader");
|
||||
col += 3;
|
||||
}
|
||||
worksheet_merge_range(worksheet, headerRow, col, headerRow, col + 1, "Hyperparameters", styles["bodyHeader_even"]);
|
||||
int hypCol = col;
|
||||
writeString(headerRow + 1, hypCol, "A", "bodyHeader");
|
||||
writeString(headerRow + 1, hypCol + 1, "B", "bodyHeader");
|
||||
col = 0;
|
||||
for (const auto size : sizes) {
|
||||
worksheet_set_column(worksheet, col, col, size, NULL);
|
||||
col++;
|
||||
}
|
||||
// Body Data
|
||||
row = headerRow + 2;
|
||||
col = 0;
|
||||
int hypSize_A = 15;
|
||||
int hypSize_B = 15;
|
||||
auto compared = std::vector<std::string>({ "nodes", "leaves", "depth", "score", "time" });
|
||||
auto compared_data = std::vector<double>(compared.size(), 0.0);
|
||||
auto totals_A = std::vector<double>(compared.size(), 0.0);
|
||||
auto totals_B = std::vector<double>(compared.size(), 0.0);
|
||||
std::string hyperparameters;
|
||||
for (int i = 0; i < data_A["results"].size(); i++) {
|
||||
const auto& r_A = data_A["results"][i];
|
||||
const auto& r_B = data_B["results"][i];
|
||||
for (int j = 0; j < compared.size(); j++) {
|
||||
auto key = compared[j];
|
||||
compared_data[j] = diff(r_A[key].get<double>(), r_B[key].get<double>());
|
||||
totals_A[j] += r_A[key].get<double>();
|
||||
totals_B[j] += r_B[key].get<double>();
|
||||
}
|
||||
// transform(compared.begin(), compared.end(), compared_data.begin(), [&](const std::string& key) {
|
||||
// return diff(r_A[key].get<double>(), r_B[key].get<double>());
|
||||
// });
|
||||
writeString(row, col, r_A["dataset"].get<std::string>(), "text");
|
||||
writeInt(row, col + 1, r_A["samples"].get<int>(), "ints");
|
||||
writeInt(row, col + 2, r_A["features"].get<int>(), "ints");
|
||||
writeInt(row, col + 3, r_A["classes"].get<int>(), "ints");
|
||||
writeDouble(row, col + 4, r_A["nodes"].get<float>(), "floats");
|
||||
writeDouble(row, col + 5, r_B["nodes"].get<float>(), "floats");
|
||||
writeDouble(row, col + 6, compared_data[0], "percentage");
|
||||
writeDouble(row, col + 7, r_A["leaves"].get<float>(), "floats");
|
||||
writeDouble(row, col + 8, r_B["leaves"].get<float>(), "floats");
|
||||
writeDouble(row, col + 9, compared_data[1], "percentage");
|
||||
writeDouble(row, col + 10, r_A["depth"].get<double>(), "floats");
|
||||
writeDouble(row, col + 11, r_B["depth"].get<double>(), "floats");
|
||||
writeDouble(row, col + 12, compared_data[2], "percentage");
|
||||
writeDouble(row, col + 13, r_A["score"].get<double>(), "result");
|
||||
writeDouble(row, col + 14, r_B["score"].get<double>(), "result");
|
||||
writeDouble(row, col + 15, compared_data[3], "percentage");
|
||||
writeDouble(row, col + 16, r_A["time"].get<double>(), "time");
|
||||
writeDouble(row, col + 17, r_B["time"].get<double>(), "time");
|
||||
writeDouble(row, col + 18, compared_data[4], "percentage");
|
||||
hyperparameters = r_A["hyperparameters"].dump();
|
||||
if (hyperparameters.size() > hypSize_A) {
|
||||
hypSize_A = hyperparameters.size();
|
||||
}
|
||||
writeString(row, hypCol, hyperparameters, "text");
|
||||
hyperparameters = r_B["hyperparameters"].dump();
|
||||
if (hyperparameters.size() > hypSize_B) {
|
||||
hypSize_B = hyperparameters.size();
|
||||
}
|
||||
writeString(row, hypCol + 1, hyperparameters, "text");
|
||||
row++;
|
||||
}
|
||||
// Set the right column width of hyperparameters with the maximum length
|
||||
worksheet_set_column(worksheet, hypCol, hypCol, hypSize_A + 5, NULL);
|
||||
worksheet_set_column(worksheet, hypCol + 1, hypCol + 1, hypSize_B + 5, NULL);
|
||||
// Show totals if only one dataset is present in the result
|
||||
footer(totals_A, totals_B, row);
|
||||
}
|
||||
void ReportExcelCompared::footer(std::vector<double>& totals_A, std::vector<double>& totals_B, int row)
|
||||
{
|
||||
worksheet_merge_range(worksheet, row, 0, row, 3, "Total", styles["bodyHeader_even"]);
|
||||
auto formats = std::vector<std::string>({ "floats", "floats", "floats", "result", "result" });
|
||||
int col = 4;
|
||||
for (int i = 0; i < totals_A.size(); i++) {
|
||||
writeDouble(row, col, totals_A[i], formats[i]);
|
||||
writeDouble(row, col + 1, totals_B[i], formats[i]);
|
||||
writeDouble(row, col + 2, diff(totals_A[i], totals_B[i]), "percentage");
|
||||
col += 3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,14 +1,16 @@
|
||||
#pragma once
|
||||
#include "ReportExcel.h"
|
||||
namespace platform {
|
||||
class ReportExcelCompared {
|
||||
class ReportExcelCompared : public ExcelFile {
|
||||
public:
|
||||
explicit ReportExcelCompared(json& data_A, json& data_B);
|
||||
~ReportExcelCompared();
|
||||
void report();
|
||||
private:
|
||||
void header();
|
||||
void body();
|
||||
void footer(std::vector<double>& totals_A, std::vector<double>& totals_B, int row);
|
||||
json& data_A;
|
||||
json& data_B;
|
||||
lxw_workbook* workbook;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user