Add pagination to detail result
Add version of libraries info to header
This commit is contained in:
@@ -64,4 +64,4 @@ add_executable(
|
|||||||
reports/ReportConsole.cpp reports/ReportExcel.cpp reports/ReportExcelCompared.cpp reports/ReportBase.cpp reports/ExcelFile.cpp reports/DatasetsConsole.cpp reports/ResultsDatasetConsole.cpp reports/ReportsPaged.cpp
|
reports/ReportConsole.cpp reports/ReportExcel.cpp reports/ReportExcelCompared.cpp reports/ReportBase.cpp reports/ExcelFile.cpp reports/DatasetsConsole.cpp reports/ResultsDatasetConsole.cpp reports/ReportsPaged.cpp
|
||||||
results/Result.cpp results/ResultsDataset.cpp
|
results/Result.cpp results/ResultsDataset.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(b_manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)
|
target_link_libraries(b_manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp "${BayesNet}")
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <utility>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <argparse/argparse.hpp>
|
#include <argparse/argparse.hpp>
|
||||||
#include "manage/ManageScreen.h"
|
#include "manage/ManageScreen.h"
|
||||||
@@ -7,7 +8,6 @@
|
|||||||
|
|
||||||
void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
|
void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
|
||||||
{
|
{
|
||||||
program.add_argument("-n", "--number").default_value(0).help("Number of results to show (0 = all)").scan<'i', int>();
|
|
||||||
program.add_argument("-m", "--model").default_value("any").help("Filter results of the selected model)");
|
program.add_argument("-m", "--model").default_value("any").help("Filter results of the selected model)");
|
||||||
program.add_argument("-s", "--score").default_value("any").help("Filter results of the score name supplied");
|
program.add_argument("-s", "--score").default_value("any").help("Filter results of the score name supplied");
|
||||||
program.add_argument("--complete").help("Show only results with all datasets").default_value(false).implicit_value(true);
|
program.add_argument("--complete").help("Show only results with all datasets").default_value(false).implicit_value(true);
|
||||||
@@ -15,10 +15,6 @@ void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
|
|||||||
program.add_argument("--compare").help("Compare with best results").default_value(false).implicit_value(true);
|
program.add_argument("--compare").help("Compare with best results").default_value(false).implicit_value(true);
|
||||||
try {
|
try {
|
||||||
program.parse_args(argc, argv);
|
program.parse_args(argc, argv);
|
||||||
auto number = program.get<int>("number");
|
|
||||||
if (number < 0) {
|
|
||||||
throw std::runtime_error("Number of results must be greater than or equal to 0");
|
|
||||||
}
|
|
||||||
auto model = program.get<std::string>("model");
|
auto model = program.get<std::string>("model");
|
||||||
auto score = program.get<std::string>("score");
|
auto score = program.get<std::string>("score");
|
||||||
auto complete = program.get<bool>("complete");
|
auto complete = program.get<bool>("complete");
|
||||||
@@ -32,18 +28,16 @@ void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int numRows()
|
std::pair<int, int> numRowsCols()
|
||||||
{
|
{
|
||||||
#ifdef TIOCGSIZE
|
#ifdef TIOCGSIZE
|
||||||
struct ttysize ts;
|
struct ttysize ts;
|
||||||
ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
|
ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
|
||||||
// cols = ts.ts_cols;
|
return { ts.ts_lines, ts.ts_cols };
|
||||||
return ts.ts_lines;
|
|
||||||
#elif defined(TIOCGWINSZ)
|
#elif defined(TIOCGWINSZ)
|
||||||
struct winsize ts;
|
struct winsize ts;
|
||||||
ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
|
ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
|
||||||
// cols = ts.ws_col;
|
return { ts.ws_row, ts.ws_col };
|
||||||
return ts.ws_row;
|
|
||||||
#endif /* TIOCGSIZE */
|
#endif /* TIOCGSIZE */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,18 +45,15 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
auto program = argparse::ArgumentParser("b_manage", { platform_project_version.begin(), platform_project_version.end() });
|
auto program = argparse::ArgumentParser("b_manage", { platform_project_version.begin(), platform_project_version.end() });
|
||||||
manageArguments(program, argc, argv);
|
manageArguments(program, argc, argv);
|
||||||
int number = program.get<int>("number");
|
|
||||||
std::string model = program.get<std::string>("model");
|
std::string model = program.get<std::string>("model");
|
||||||
std::string score = program.get<std::string>("score");
|
std::string score = program.get<std::string>("score");
|
||||||
auto complete = program.get<bool>("complete");
|
auto complete = program.get<bool>("complete");
|
||||||
auto partial = program.get<bool>("partial");
|
auto partial = program.get<bool>("partial");
|
||||||
auto compare = program.get<bool>("compare");
|
auto compare = program.get<bool>("compare");
|
||||||
if (number == 0) {
|
auto [rows, cols] = numRowsCols();
|
||||||
number = std::max(0, numRows() - 6); // 6 is the number of lines used by the menu & header
|
|
||||||
}
|
|
||||||
if (complete)
|
if (complete)
|
||||||
partial = false;
|
partial = false;
|
||||||
auto manager = platform::ManageScreen(number, model, score, complete, partial, compare);
|
auto manager = platform::ManageScreen(rows, cols, model, score, complete, partial, compare);
|
||||||
manager.doMenu();
|
manager.doMenu();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "folding.hpp"
|
||||||
#include "common/Colors.h"
|
#include "common/Colors.h"
|
||||||
#include "common/CLocale.h"
|
#include "common/CLocale.h"
|
||||||
#include "common/Paths.h"
|
#include "common/Paths.h"
|
||||||
@@ -10,29 +12,30 @@
|
|||||||
#include "reports/ReportConsole.h"
|
#include "reports/ReportConsole.h"
|
||||||
#include "reports/ReportExcel.h"
|
#include "reports/ReportExcel.h"
|
||||||
#include "reports/ReportExcelCompared.h"
|
#include "reports/ReportExcelCompared.h"
|
||||||
|
#include <bayesnet/classifiers/TAN.h>
|
||||||
|
#include "CPPFImdlp.h"
|
||||||
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
const std::string STATUS_OK = "Ok.";
|
const std::string STATUS_OK = "Ok.";
|
||||||
const std::string STATUS_COLOR = Colors::GREEN();
|
const std::string STATUS_COLOR = Colors::GREEN();
|
||||||
ManageScreen::ManageScreen(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
|
ManageScreen::ManageScreen(int rows, int cols, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
|
||||||
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, didExcel(false), results(ResultsManager(model, score, complete, partial))
|
rows{ rows }, cols{ cols }, complete{ complete }, partial{ partial }, compare{ compare }, didExcel(false), results(ResultsManager(model, score, complete, partial))
|
||||||
{
|
{
|
||||||
results.load();
|
results.load();
|
||||||
results.sortDate();
|
results.sortDate();
|
||||||
sort_field = "Date";
|
sort_field = "Date";
|
||||||
openExcel = false;
|
openExcel = false;
|
||||||
workbook = NULL;
|
workbook = NULL;
|
||||||
if (numFiles == 0 or numFiles > results.size()) {
|
this->rows = std::max(0, rows - 6); // 6 is the number of lines used by the menu & header
|
||||||
this->numFiles = results.size();
|
cols = std::max(cols, 140);
|
||||||
}
|
|
||||||
// Initializes the paginator for each output type (experiments, datasets, result)
|
// Initializes the paginator for each output type (experiments, datasets, result)
|
||||||
for (int i = 0; i < static_cast<int>(OutputType::Count); i++) {
|
for (int i = 0; i < static_cast<int>(OutputType::Count); i++) {
|
||||||
paginator.push_back(Paginator(numFiles, results.size()));
|
paginator.push_back(Paginator(this->rows, results.size()));
|
||||||
}
|
}
|
||||||
index_A = -1;
|
index_A = -1;
|
||||||
index_B = -1;
|
index_B = -1;
|
||||||
max_status_line = 140;
|
index = -1;
|
||||||
|
subIndex = -1;
|
||||||
output_type = OutputType::EXPERIMENTS;
|
output_type = OutputType::EXPERIMENTS;
|
||||||
}
|
}
|
||||||
void ManageScreen::doMenu()
|
void ManageScreen::doMenu()
|
||||||
@@ -52,6 +55,13 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
std::cout << Colors::RESET() << "Done!" << std::endl;
|
std::cout << Colors::RESET() << "Done!" << std::endl;
|
||||||
}
|
}
|
||||||
|
std::string ManageScreen::getVersions()
|
||||||
|
{
|
||||||
|
std::string kfold_version = folding::KFold(5, 100).version();
|
||||||
|
std::string bayesnet_version = bayesnet::TAN().getVersion();
|
||||||
|
std::string mdlp_version = mdlp::CPPFImdlp::version();
|
||||||
|
return " BayesNet: " + bayesnet_version + " Folding: " + kfold_version + " MDLP: " + mdlp_version + " ";
|
||||||
|
}
|
||||||
void ManageScreen::header()
|
void ManageScreen::header()
|
||||||
{
|
{
|
||||||
auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset();
|
auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset();
|
||||||
@@ -69,17 +79,18 @@ namespace platform {
|
|||||||
std::string header = " Lines " + std::to_string(lines) + " of "
|
std::string header = " Lines " + std::to_string(lines) + " of "
|
||||||
+ std::to_string(total) + " - Page " + std::to_string(page) + " of "
|
+ std::to_string(total) + " - Page " + std::to_string(page) + " of "
|
||||||
+ std::to_string(pages) + " ";
|
+ std::to_string(pages) + " ";
|
||||||
|
std::string versions = getVersions();
|
||||||
std::string prefix = std::string(max_status_line - suffix.size() - header.size(), ' ');
|
int filler = std::max(cols - versions.size() - suffix.size() - header.size(), size_t(0));
|
||||||
std::cout << Colors::CLRSCR() << Colors::REVERSE() << Colors::WHITE() << header << prefix
|
std::string prefix = std::string(filler, ' ');
|
||||||
<< Colors::MAGENTA() << suffix << Colors::RESET() << std::endl;
|
std::cout << Colors::CLRSCR() << Colors::REVERSE() << Colors::WHITE() << header
|
||||||
|
<< prefix << Colors::GREEN() << versions << Colors::MAGENTA() << suffix << Colors::RESET() << std::endl;
|
||||||
}
|
}
|
||||||
void ManageScreen::footer(const std::string& status, const std::string& status_color)
|
void ManageScreen::footer(const std::string& status, const std::string& status_color)
|
||||||
{
|
{
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
oss << " A: " << (index_A == -1 ? "<notset>" : std::to_string(index_A)) <<
|
oss << " A: " << (index_A == -1 ? "<notset>" : std::to_string(index_A)) <<
|
||||||
" B: " << (index_B == -1 ? "<notset>" : std::to_string(index_B)) << " ";
|
" B: " << (index_B == -1 ? "<notset>" : std::to_string(index_B)) << " ";
|
||||||
int status_length = std::max(oss.str().size(), max_status_line - oss.str().size());
|
int status_length = std::max(oss.str().size(), cols - oss.str().size());
|
||||||
auto status_message = status.substr(0, status_length - 1);
|
auto status_message = status.substr(0, status_length - 1);
|
||||||
std::string status_line = status_message + std::string(std::max(size_t(0), status_length - status_message.size() - 1), ' ');
|
std::string status_line = status_message + std::string(std::max(size_t(0), status_length - status_message.size() - 1), ' ');
|
||||||
auto color = (index_A != -1 && index_B != -1) ? Colors::IGREEN() : Colors::IYELLOW();
|
auto color = (index_A != -1 && index_B != -1) ? Colors::IGREEN() : Colors::IYELLOW();
|
||||||
@@ -93,6 +104,9 @@ namespace platform {
|
|||||||
case static_cast<int>(OutputType::RESULT):
|
case static_cast<int>(OutputType::RESULT):
|
||||||
list_result(status_message, status_color);
|
list_result(status_message, status_color);
|
||||||
break;
|
break;
|
||||||
|
case static_cast<int>(OutputType::DETAIL):
|
||||||
|
list_detail(status_message, status_color);
|
||||||
|
break;
|
||||||
case static_cast<int>(OutputType::DATASETS):
|
case static_cast<int>(OutputType::DATASETS):
|
||||||
list_datasets(status_message, status_color);
|
list_datasets(status_message, status_color);
|
||||||
break;
|
break;
|
||||||
@@ -129,6 +143,35 @@ namespace platform {
|
|||||||
//
|
//
|
||||||
footer(status_message, status_color);
|
footer(status_message, status_color);
|
||||||
|
|
||||||
|
}
|
||||||
|
void ManageScreen::list_detail(const std::string& status_message, const std::string& status_color)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto data = results.at(index).getJson();
|
||||||
|
ReportConsole report(data, compare, subIndex);
|
||||||
|
auto header_text = report.getHeader();
|
||||||
|
auto body = report.getBody();
|
||||||
|
paginator[static_cast<int>(output_type)].setTotal(body.size());
|
||||||
|
// We need to subtract 8 from the page size to make room for the extra header in report
|
||||||
|
auto page_size = paginator[static_cast<int>(OutputType::EXPERIMENTS)].getPageSize();
|
||||||
|
paginator[static_cast<int>(output_type)].setPageSize(page_size - 8);
|
||||||
|
//
|
||||||
|
// header
|
||||||
|
//
|
||||||
|
header();
|
||||||
|
//
|
||||||
|
// Results
|
||||||
|
//
|
||||||
|
std::cout << header_text;
|
||||||
|
auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset();
|
||||||
|
for (int i = index_from; i <= index_to; i++) {
|
||||||
|
std::cout << body[i];
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Status Area
|
||||||
|
//
|
||||||
|
footer(status_message, status_color);
|
||||||
|
|
||||||
}
|
}
|
||||||
void ManageScreen::list_datasets(const std::string& status_message, const std::string& status_color)
|
void ManageScreen::list_datasets(const std::string& status_message, const std::string& status_color)
|
||||||
{
|
{
|
||||||
@@ -245,13 +288,6 @@ namespace platform {
|
|||||||
return "Reporting " + results.at(index).getFilename();
|
return "Reporting " + results.at(index).getFilename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ManageScreen::showIndex(const int idx)
|
|
||||||
{
|
|
||||||
// Show a dataset result inside a report
|
|
||||||
auto data = results.at(index).getJson();
|
|
||||||
ReportConsole reporter(data, compare, idx);
|
|
||||||
std::cout << Colors::CLRSCR() << reporter.fileReport();
|
|
||||||
}
|
|
||||||
std::pair<std::string, std::string> ManageScreen::sortList()
|
std::pair<std::string, std::string> ManageScreen::sortList()
|
||||||
{
|
{
|
||||||
std::cout << Colors::YELLOW() << "Choose sorting field (date='d', score='s', time='t', model='m'): ";
|
std::cout << Colors::YELLOW() << "Choose sorting field (date='d', score='s', time='t', model='m'): ";
|
||||||
@@ -286,7 +322,6 @@ namespace platform {
|
|||||||
void ManageScreen::menu()
|
void ManageScreen::menu()
|
||||||
{
|
{
|
||||||
char option;
|
char option;
|
||||||
int subIndex;
|
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
// tuple<Option, digit, requires value>
|
// tuple<Option, digit, requires value>
|
||||||
@@ -383,6 +418,8 @@ namespace platform {
|
|||||||
list("B set to " + std::to_string(index), Colors::GREEN());
|
list("B set to " + std::to_string(index), Colors::GREEN());
|
||||||
} else {
|
} else {
|
||||||
// back to show the report
|
// back to show the report
|
||||||
|
output_type = OutputType::RESULT;
|
||||||
|
paginator[static_cast<int>(OutputType::DETAIL)].setPage(1);
|
||||||
list(STATUS_OK, STATUS_COLOR);
|
list(STATUS_OK, STATUS_COLOR);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -395,6 +432,9 @@ namespace platform {
|
|||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
output_type = OutputType::EXPERIMENTS;
|
output_type = OutputType::EXPERIMENTS;
|
||||||
|
paginator[static_cast<int>(OutputType::DATASETS)].setPage(1);
|
||||||
|
paginator[static_cast<int>(OutputType::RESULT)].setPage(1);
|
||||||
|
paginator[static_cast<int>(OutputType::DETAIL)].setPage(1);
|
||||||
list(STATUS_OK, STATUS_COLOR);
|
list(STATUS_OK, STATUS_COLOR);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
@@ -436,9 +476,11 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
if (output_type == OutputType::EXPERIMENTS) {
|
if (output_type == OutputType::EXPERIMENTS) {
|
||||||
output_type = OutputType::RESULT;
|
output_type = OutputType::RESULT;
|
||||||
|
paginator[static_cast<int>(OutputType::DETAIL)].setPage(1);
|
||||||
list(STATUS_OK, STATUS_COLOR);
|
list(STATUS_OK, STATUS_COLOR);
|
||||||
} else {
|
} else {
|
||||||
showIndex(subIndex);
|
output_type = OutputType::DETAIL;
|
||||||
|
list(STATUS_OK, STATUS_COLOR);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
|
@@ -9,31 +9,34 @@ namespace platform {
|
|||||||
EXPERIMENTS = 0,
|
EXPERIMENTS = 0,
|
||||||
DATASETS = 1,
|
DATASETS = 1,
|
||||||
RESULT = 2,
|
RESULT = 2,
|
||||||
|
DETAIL = 3,
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
class ManageScreen {
|
class ManageScreen {
|
||||||
public:
|
public:
|
||||||
ManageScreen(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare);
|
ManageScreen(int rows, int cols, const std::string& model, const std::string& score, bool complete, bool partial, bool compare);
|
||||||
~ManageScreen() = default;
|
~ManageScreen() = default;
|
||||||
void doMenu();
|
void doMenu();
|
||||||
private:
|
private:
|
||||||
void list(const std::string& status, const std::string& color);
|
void list(const std::string& status, const std::string& color);
|
||||||
void list_experiments(const std::string& status, const std::string& color);
|
void list_experiments(const std::string& status, const std::string& color);
|
||||||
void list_result(const std::string& status, const std::string& color);
|
void list_result(const std::string& status, const std::string& color);
|
||||||
|
void list_detail(const std::string& status, const std::string& color);
|
||||||
void list_datasets(const std::string& status, const std::string& color);
|
void list_datasets(const std::string& status, const std::string& color);
|
||||||
bool confirmAction(const std::string& intent, const std::string& fileName) const;
|
bool confirmAction(const std::string& intent, const std::string& fileName) const;
|
||||||
std::string report(const int index, const bool excelReport);
|
std::string report(const int index, const bool excelReport);
|
||||||
std::string report_compared();
|
std::string report_compared();
|
||||||
void showIndex(const int idx);
|
|
||||||
std::pair<std::string, std::string> sortList();
|
std::pair<std::string, std::string> sortList();
|
||||||
|
std::string getVersions();
|
||||||
void menu();
|
void menu();
|
||||||
void header();
|
void header();
|
||||||
void footer(const std::string& status, const std::string& color);
|
void footer(const std::string& status, const std::string& color);
|
||||||
OutputType output_type;
|
OutputType output_type;
|
||||||
int numFiles;
|
int rows;
|
||||||
|
int cols;
|
||||||
int index;
|
int index;
|
||||||
|
int subIndex;
|
||||||
int index_A, index_B; // used for comparison of experiments
|
int index_A, index_B; // used for comparison of experiments
|
||||||
int max_status_line;
|
|
||||||
bool indexList;
|
bool indexList;
|
||||||
bool openExcel;
|
bool openExcel;
|
||||||
bool didExcel;
|
bool didExcel;
|
||||||
|
@@ -18,8 +18,8 @@ TEST_CASE("Test Platform version", "[Platform]")
|
|||||||
}
|
}
|
||||||
TEST_CASE("Test Folding library version", "[Folding]")
|
TEST_CASE("Test Folding library version", "[Folding]")
|
||||||
{
|
{
|
||||||
auto kfold = folding::KFold(5, 100);
|
std::string version = folding::KFold(5, 100).version();
|
||||||
REQUIRE(kfold.version() == "1.0.1");
|
REQUIRE(version == "1.0.1");
|
||||||
}
|
}
|
||||||
TEST_CASE("Test BayesNet version", "[BayesNet]")
|
TEST_CASE("Test BayesNet version", "[BayesNet]")
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user