Begin b_list excel

This commit is contained in:
2024-02-29 12:53:11 +01:00
parent 9a26baec47
commit c69dc08134
58 changed files with 148 additions and 39 deletions

View File

@@ -5,7 +5,7 @@ diagrams:
type: class
glob:
- src/*.cc
- src/Command/*.cc
- src/modules/*.cc
using_namespace: platform
include:
namespaces:
@@ -17,7 +17,7 @@ diagrams:
sequence:
type: sequence
glob:
- src/Command/b_main.cc
- src/b_main.cc
combine_free_functions_into_file_participants: true
using_namespace:
- std

View File

@@ -78,7 +78,6 @@ message("XLSXWRITER_LIB=${XLSXWRITER_LIB}")
# Subdirectories
# --------------
set(Platform_MODULES ${Platform_SOURCE_DIR}/src/modules/)
add_subdirectory(config)
add_subdirectory(src)
add_subdirectory(sample)

View File

@@ -1,5 +1,6 @@
include_directories(
${Platform_SOURCE_DIR}/src/modules
${Platform_SOURCE_DIR}/src/common
${Platform_SOURCE_DIR}/src/main
${Platform_SOURCE_DIR}/lib/PyClassifiers/src
${Python3_INCLUDE_DIRS}
${Platform_SOURCE_DIR}/lib/Files
@@ -10,5 +11,5 @@ include_directories(
${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/json/include
${CMAKE_BINARY_DIR}/configured_files/include
)
add_executable(PlatformSample sample.cc ${Platform_MODULES}/Models.cc)
add_executable(PlatformSample sample.cc ${Platform_SOURCE_DIR}/src/main/Models.cc)
target_link_libraries(PlatformSample PyClassifiers ArffFiles mdlp "${TORCH_LIBRARIES}")

View File

@@ -1,10 +1,10 @@
include_directories(
## Libs
${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/src
${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/folding
${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/mdlp
${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/json/include
${Platform_SOURCE_DIR}/lib/PyClassifiers/src
${Platform_MODULES}
${Platform_SOURCE_DIR}/lib/Files
${Platform_SOURCE_DIR}/lib/mdlp
${Platform_SOURCE_DIR}/lib/argparse/include
@@ -13,24 +13,41 @@ include_directories(
${Python3_INCLUDE_DIRS}
${MPI_CXX_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/configured_files/include
## Platform
${Platform_SOURCE_DIR}/src/common
${Platform_SOURCE_DIR}/src/best
${Platform_SOURCE_DIR}/src/grid
${Platform_SOURCE_DIR}/src/main
${Platform_SOURCE_DIR}/src/manage
${Platform_SOURCE_DIR}/src/reports
)
set(best_sources BestResults.cc Result.cc Statistics.cc BestResultsExcel.cc ReportExcel.cc ReportBase.cc Datasets.cc Dataset.cc ExcelFile.cc)
list(TRANSFORM best_sources PREPEND ${Platform_MODULES})
add_executable(b_best b_best.cc ${best_sources})
set(grid_sources GridSearch.cc GridData.cc HyperParameters.cc Datasets.cc Dataset.cc Models.cc)
list(TRANSFORM grid_sources PREPEND ${Platform_MODULES})
add_executable(b_grid b_grid.cc ${grid_sources})
add_executable(b_list b_list.cc ${Platform_MODULES}Datasets.cc ${Platform_MODULES}Dataset.cc)
set(main_sources Experiment.cc Datasets.cc Dataset.cc Models.cc HyperParameters.cc ReportConsole.cc ReportBase.cc Result.cc)
list(TRANSFORM main_sources PREPEND ${Platform_MODULES})
add_executable(b_main b_main.cc ${main_sources})
set(manage_sources Results.cc ManageResults.cc CommandParser.cc Result.cc ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc Dataset.cc ExcelFile.cc)
list(TRANSFORM manage_sources PREPEND ${Platform_MODULES})
add_executable(b_manage b_manage.cc ${manage_sources})
# b_best
set(best_sources b_best.cc BestResults.cc Statistics.cc BestResultsExcel.cc)
list(TRANSFORM best_sources PREPEND best/)
add_executable(b_best ${best_sources} main/Result.cc reports/ReportExcel.cc reports/ReportBase.cc reports/ExcelFile.cc common/Datasets.cc common/Dataset.cc)
target_link_libraries(b_best Boost::boost "${XLSXWRITER_LIB}" "${TORCH_LIBRARIES}" ArffFiles mdlp)
# b_grid
set(grid_sources b_grid.cc GridSearch.cc GridData.cc)
list(TRANSFORM grid_sources PREPEND grid/)
add_executable(b_grid ${grid_sources} main/HyperParameters.cc main/Models.cc common/Datasets.cc common/Dataset.cc)
target_link_libraries(b_grid PyClassifiers ${MPI_CXX_LIBRARIES} ArffFiles)
target_link_libraries(b_list ArffFiles mdlp "${TORCH_LIBRARIES}")
# b_list
set(list_sources b_list.cc DatasetsExcel.cc)
list(TRANSFORM list_sources PREPEND list/)
add_executable(b_list ${list_sources} common/Datasets.cc common/Dataset.cc reports/ReportExcel.cc reports/ExcelFile.cc reports/ReportBase.cc)
target_link_libraries(b_list ArffFiles mdlp "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}")
# b_main
set(main_sources b_main.cc Experiment.cc Models.cc HyperParameters.cc)
list(TRANSFORM main_sources PREPEND main/)
add_executable(b_main ${main_sources} common/Datasets.cc common/Dataset.cc reports/ReportConsole.cc reports/ReportBase.cc main/Result.cc)
target_link_libraries(b_main PyClassifiers BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
# b_manage
set(manage_sources b_manage.cc ManageResults.cc CommandParser.cc Results.cc)
list(TRANSFORM manage_sources PREPEND manage/)
add_executable(b_manage ${manage_sources} main/Result.cc reports/ReportConsole.cc reports/ReportExcel.cc reports/ReportBase.cc reports/ExcelFile.cc common/Datasets.cc common/Dataset.cc)
target_link_libraries(b_manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)

View File

@@ -302,9 +302,9 @@ namespace platform {
// Build the table of results
json table = buildTableResults(models);
std::vector<std::string> datasets = getDatasets(table.begin().value());
BestResultsExcel excel(score, datasets);
excel.reportSingle(model, path + bestResultFile());
messageExcelFile(excel.getFileName());
BestResultsExcel excel_report(score, datasets);
excel_report.reportSingle(model, path + bestResultFile());
messageExcelFile(excel_report.getFileName());
}
}
void BestResults::reportAll(bool excel)

View File

@@ -32,11 +32,11 @@ namespace platform {
}
BestResultsExcel::BestResultsExcel(const std::string& score, const std::vector<std::string>& datasets) : score(score), datasets(datasets)
{
workbook = workbook_new((Paths::excel() + fileName).c_str());
file_name = "BestResults.xlsx";
workbook = workbook_new(getFileName().c_str());
setProperties("Best Results");
int maxDatasetName = (*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);
createFormats();
}
void BestResultsExcel::reportAll(const std::vector<std::string>& models, const json& table, const std::map<std::string, std::map<std::string, float>>& ranks, bool friedman, double significance)
{
@@ -170,10 +170,7 @@ namespace platform {
doFriedman();
}
}
std::string BestResultsExcel::getFileName()
{
return Paths::excel() + fileName;
}
void BestResultsExcel::header(bool ranks)
{
row = 0;

View File

@@ -9,13 +9,12 @@ using json = nlohmann::json;
namespace platform {
class BestResultsExcel : ExcelFile {
class BestResultsExcel : public ExcelFile {
public:
BestResultsExcel(const std::string& score, const std::vector<std::string>& datasets);
~BestResultsExcel();
void reportAll(const std::vector<std::string>& models, const json& table, const std::map<std::string, std::map<std::string, float>>& ranks, bool friedman, double significance);
void reportSingle(const std::string& model, const std::string& fileName);
std::string getFileName();
private:
void build();
void header(bool ranks);
@@ -24,7 +23,6 @@ namespace platform {
void formatColumns();
void doFriedman();
void addConditionalFormat(std::string formula);
const std::string fileName = "BestResults.xlsx";
std::string score;
std::vector<std::string> models;
std::vector<std::string> datasets;

View File

@@ -65,5 +65,6 @@ int main(int argc, char** argv)
std::cout << Colors::GREEN() << fileName << " created!" << Colors::RESET() << std::endl;
results.reportSingle(excel);
}
std::cout << Colors::RESET();
return 0;
}

51
src/list/DatasetsExcel.cc Normal file
View File

@@ -0,0 +1,51 @@
#include <sstream>
#include "DatasetsExcel.h"
#include "Paths.h"
namespace platform {
DatasetsExcel::DatasetsExcel()
{
file_name = "datasets.xlsx";
workbook = workbook_new(getFileName().c_str());
setProperties("Datasets");
}
DatasetsExcel::~DatasetsExcel()
{
workbook_close(workbook);
}
void DatasetsExcel::report()
{
worksheet = workbook_add_worksheet(workbook, "Datasets");
formatColumns();
worksheet_merge_range(worksheet, 0, 0, 0, 4, "Datasets", styles["headerFirst"]);
// Body header
row = 3;
int col = 1;
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, "", "bodyHeader");
writeString(row, 1, "Dataset", "bodyHeader");
for (auto const& name : datasets) {
row++;
writeInt(row, 0, i++, "ints");
writeString(row, 1, name.c_str(), "text");
}
row++;
formatColumns();
}
void DatasetsExcel::formatColumns()
{
worksheet_freeze_panes(worksheet, 4, 2);
std::vector<int> columns_sizes = { 5, datasetNameSize };
for (int i = 0; i < columns_sizes.size(); ++i) {
worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL);
}
}
}

22
src/list/DatasetsExcel.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef DATASETS_EXCEL_H
#define DATASETS_EXCEL_H
#include "ExcelFile.h"
#include <vector>
#include <map>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace platform {
class DatasetsExcel : public ExcelFile {
public:
DatasetsExcel();
~DatasetsExcel();
void report();
private:
void formatColumns();
int datasetNameSize = 25; // Min size of the column
};
}
#endif //DATASETS_EXCEL_H

View File

@@ -1,8 +1,11 @@
#include <iostream>
#include <locale>
#include <argparse/argparse.hpp>
#include "Paths.h"
#include "Colors.h"
#include "Datasets.h"
#include "DatasetsExcel.h"
#include "config.h"
const int BALANCE_LENGTH = 75;
@@ -27,6 +30,13 @@ void outputBalance(const std::string& balance)
int main(int argc, char** argv)
{
auto data = 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")
.default_value(false)
.implicit_value(true);
program.parse_args(argc, argv);
auto excel = program.get<bool>("--excel");
locale mylocale(std::cout.getloc(), new separated);
locale::global(mylocale);
std::cout.imbue(mylocale);
@@ -52,5 +62,10 @@ int main(int argc, char** argv)
outputBalance(oss.str());
}
std::cout << Colors::RESET() << std::endl;
if (excel) {
auto report = platform::DatasetsExcel();
report.report();
std::cout << "Output saved in " << report.getFileName() << std::endl;
}
return 0;
}

View File

@@ -164,7 +164,7 @@ namespace platform {
if (indexList) {
std::tie(option, index) = parser.parse(Colors::GREEN(), mainOptions, 'r', numFiles - 1);
} else {
std::tie(option, subIndex) = parser.parse(Colors::MAGENTA(), listOptions, 'r', results.at(index).getJson()["results"].size() - 1);
std::tie(option, subIndex) = parser.parse(Colors::CYAN(), listOptions, 'r', results.at(index).getJson()["results"].size() - 1);
}
switch (option) {
case 'q':

View File

@@ -4,14 +4,17 @@ namespace platform {
ExcelFile::ExcelFile()
{
setDefault();
createFormats();
}
ExcelFile::ExcelFile(lxw_workbook* workbook) : workbook(workbook)
{
setDefault();
createFormats();
}
ExcelFile::ExcelFile(lxw_workbook* workbook, lxw_worksheet* worksheet) : workbook(workbook), worksheet(worksheet)
{
setDefault();
createFormats();
}
void ExcelFile::setDefault()
{
@@ -26,6 +29,10 @@ namespace platform {
{
return workbook;
}
std::string ExcelFile::getFileName()
{
return Paths::excel() + file_name;
}
void ExcelFile::setProperties(std::string title)
{
char line[title.size() + 1];

View File

@@ -3,6 +3,7 @@
#include <locale>
#include <string>
#include <map>
#include "Paths.h"
#include "xlsxwriter.h"
namespace platform {
@@ -19,6 +20,7 @@ namespace platform {
ExcelFile(lxw_workbook* workbook);
ExcelFile(lxw_workbook* workbook, lxw_worksheet* worksheet);
lxw_workbook* getWorkbook();
std::string getFileName();
protected:
void setProperties(std::string title);
void writeString(int row, int col, const std::string& text, const std::string& style = "");
@@ -36,6 +38,7 @@ namespace platform {
uint32_t colorTitle;
uint32_t colorOdd;
uint32_t colorEven;
std::string file_name;
private:
void setDefault();
};

View File

@@ -94,10 +94,10 @@ namespace platform {
std::cout << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12));
std::cout << headerLine(fVector("Train times: ", lastResult["times_train"], 10, 3));
std::cout << headerLine(fVector("Test times: ", lastResult["times_test"], 10, 3));
std::cout << std::string(MAXL, '*') << std::endl;
} else {
footer(totalScore);
}
std::cout << std::string(MAXL, '*') << Colors::RESET() << std::endl;
}
void ReportConsole::showSummary()
{
@@ -124,6 +124,5 @@ namespace platform {
if (!getExistBestFile() && compare) {
std::cout << headerLine("*** Best Results File not found. Couldn't compare any result!");
}
std::cout << std::string(MAXL, '*') << std::endl << Colors::RESET();
}
}

View File

@@ -49,7 +49,6 @@ namespace platform {
createWorksheet();
}
setProperties(data["title"].get<std::string>());
createFormats();
formatColumns();
}