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
|
||||
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 <sys/ioctl.h>
|
||||
#include <utility>
|
||||
#include <unistd.h>
|
||||
#include <argparse/argparse.hpp>
|
||||
#include "manage/ManageScreen.h"
|
||||
@@ -7,7 +8,6 @@
|
||||
|
||||
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("-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);
|
||||
@@ -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);
|
||||
try {
|
||||
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 score = program.get<std::string>("score");
|
||||
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
|
||||
struct ttysize ts;
|
||||
ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
|
||||
// cols = ts.ts_cols;
|
||||
return ts.ts_lines;
|
||||
return { ts.ts_lines, ts.ts_cols };
|
||||
#elif defined(TIOCGWINSZ)
|
||||
struct winsize ts;
|
||||
ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
|
||||
// cols = ts.ws_col;
|
||||
return ts.ws_row;
|
||||
return { ts.ws_row, ts.ws_col };
|
||||
#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() });
|
||||
manageArguments(program, argc, argv);
|
||||
int number = program.get<int>("number");
|
||||
std::string model = program.get<std::string>("model");
|
||||
std::string score = program.get<std::string>("score");
|
||||
auto complete = program.get<bool>("complete");
|
||||
auto partial = program.get<bool>("partial");
|
||||
auto compare = program.get<bool>("compare");
|
||||
if (number == 0) {
|
||||
number = std::max(0, numRows() - 6); // 6 is the number of lines used by the menu & header
|
||||
}
|
||||
auto [rows, cols] = numRowsCols();
|
||||
if (complete)
|
||||
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();
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#include <filesystem>
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "folding.hpp"
|
||||
#include "common/Colors.h"
|
||||
#include "common/CLocale.h"
|
||||
#include "common/Paths.h"
|
||||
@@ -10,29 +12,30 @@
|
||||
#include "reports/ReportConsole.h"
|
||||
#include "reports/ReportExcel.h"
|
||||
#include "reports/ReportExcelCompared.h"
|
||||
|
||||
#include <bayesnet/classifiers/TAN.h>
|
||||
#include "CPPFImdlp.h"
|
||||
|
||||
namespace platform {
|
||||
const std::string STATUS_OK = "Ok.";
|
||||
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) :
|
||||
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, didExcel(false), results(ResultsManager(model, score, complete, partial))
|
||||
ManageScreen::ManageScreen(int rows, int cols, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
|
||||
rows{ rows }, cols{ cols }, complete{ complete }, partial{ partial }, compare{ compare }, didExcel(false), results(ResultsManager(model, score, complete, partial))
|
||||
{
|
||||
results.load();
|
||||
results.sortDate();
|
||||
sort_field = "Date";
|
||||
openExcel = false;
|
||||
workbook = NULL;
|
||||
if (numFiles == 0 or numFiles > results.size()) {
|
||||
this->numFiles = results.size();
|
||||
}
|
||||
this->rows = std::max(0, rows - 6); // 6 is the number of lines used by the menu & header
|
||||
cols = std::max(cols, 140);
|
||||
// Initializes the paginator for each output type (experiments, datasets, result)
|
||||
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_B = -1;
|
||||
max_status_line = 140;
|
||||
index = -1;
|
||||
subIndex = -1;
|
||||
output_type = OutputType::EXPERIMENTS;
|
||||
}
|
||||
void ManageScreen::doMenu()
|
||||
@@ -52,6 +55,13 @@ namespace platform {
|
||||
}
|
||||
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()
|
||||
{
|
||||
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::to_string(total) + " - Page " + std::to_string(page) + " of "
|
||||
+ std::to_string(pages) + " ";
|
||||
|
||||
std::string prefix = std::string(max_status_line - suffix.size() - header.size(), ' ');
|
||||
std::cout << Colors::CLRSCR() << Colors::REVERSE() << Colors::WHITE() << header << prefix
|
||||
<< Colors::MAGENTA() << suffix << Colors::RESET() << std::endl;
|
||||
std::string versions = getVersions();
|
||||
int filler = std::max(cols - versions.size() - suffix.size() - header.size(), size_t(0));
|
||||
std::string prefix = std::string(filler, ' ');
|
||||
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)
|
||||
{
|
||||
std::stringstream oss;
|
||||
oss << " A: " << (index_A == -1 ? "<notset>" : std::to_string(index_A)) <<
|
||||
" 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);
|
||||
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();
|
||||
@@ -93,6 +104,9 @@ namespace platform {
|
||||
case static_cast<int>(OutputType::RESULT):
|
||||
list_result(status_message, status_color);
|
||||
break;
|
||||
case static_cast<int>(OutputType::DETAIL):
|
||||
list_detail(status_message, status_color);
|
||||
break;
|
||||
case static_cast<int>(OutputType::DATASETS):
|
||||
list_datasets(status_message, status_color);
|
||||
break;
|
||||
@@ -129,6 +143,35 @@ namespace platform {
|
||||
//
|
||||
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)
|
||||
{
|
||||
@@ -245,13 +288,6 @@ namespace platform {
|
||||
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::cout << Colors::YELLOW() << "Choose sorting field (date='d', score='s', time='t', model='m'): ";
|
||||
@@ -286,7 +322,6 @@ namespace platform {
|
||||
void ManageScreen::menu()
|
||||
{
|
||||
char option;
|
||||
int subIndex;
|
||||
bool finished = false;
|
||||
std::string filename;
|
||||
// tuple<Option, digit, requires value>
|
||||
@@ -383,6 +418,8 @@ namespace platform {
|
||||
list("B set to " + std::to_string(index), Colors::GREEN());
|
||||
} else {
|
||||
// back to show the report
|
||||
output_type = OutputType::RESULT;
|
||||
paginator[static_cast<int>(OutputType::DETAIL)].setPage(1);
|
||||
list(STATUS_OK, STATUS_COLOR);
|
||||
}
|
||||
break;
|
||||
@@ -395,6 +432,9 @@ namespace platform {
|
||||
break;
|
||||
case 'l':
|
||||
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);
|
||||
break;
|
||||
case 'D':
|
||||
@@ -436,9 +476,11 @@ namespace platform {
|
||||
}
|
||||
if (output_type == OutputType::EXPERIMENTS) {
|
||||
output_type = OutputType::RESULT;
|
||||
paginator[static_cast<int>(OutputType::DETAIL)].setPage(1);
|
||||
list(STATUS_OK, STATUS_COLOR);
|
||||
} else {
|
||||
showIndex(subIndex);
|
||||
output_type = OutputType::DETAIL;
|
||||
list(STATUS_OK, STATUS_COLOR);
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
|
@@ -9,31 +9,34 @@ namespace platform {
|
||||
EXPERIMENTS = 0,
|
||||
DATASETS = 1,
|
||||
RESULT = 2,
|
||||
DETAIL = 3,
|
||||
Count
|
||||
};
|
||||
class ManageScreen {
|
||||
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;
|
||||
void doMenu();
|
||||
private:
|
||||
void list(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_detail(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;
|
||||
std::string report(const int index, const bool excelReport);
|
||||
std::string report_compared();
|
||||
void showIndex(const int idx);
|
||||
std::pair<std::string, std::string> sortList();
|
||||
std::string getVersions();
|
||||
void menu();
|
||||
void header();
|
||||
void footer(const std::string& status, const std::string& color);
|
||||
OutputType output_type;
|
||||
int numFiles;
|
||||
int rows;
|
||||
int cols;
|
||||
int index;
|
||||
int subIndex;
|
||||
int index_A, index_B; // used for comparison of experiments
|
||||
int max_status_line;
|
||||
bool indexList;
|
||||
bool openExcel;
|
||||
bool didExcel;
|
||||
|
@@ -18,8 +18,8 @@ TEST_CASE("Test Platform version", "[Platform]")
|
||||
}
|
||||
TEST_CASE("Test Folding library version", "[Folding]")
|
||||
{
|
||||
auto kfold = folding::KFold(5, 100);
|
||||
REQUIRE(kfold.version() == "1.0.1");
|
||||
std::string version = folding::KFold(5, 100).version();
|
||||
REQUIRE(version == "1.0.1");
|
||||
}
|
||||
TEST_CASE("Test BayesNet version", "[BayesNet]")
|
||||
{
|
||||
|
Reference in New Issue
Block a user