Complete Datasets in b_manage
This commit is contained in:
@@ -20,7 +20,7 @@ void list_datasets(argparse::ArgumentParser& program)
|
|||||||
{
|
{
|
||||||
auto excel = program.get<bool>("excel");
|
auto excel = program.get<bool>("excel");
|
||||||
auto report = platform::DatasetsConsole();
|
auto report = platform::DatasetsConsole();
|
||||||
report.list_datasets();
|
report.report();
|
||||||
std::cout << report.getOutput();
|
std::cout << report.getOutput();
|
||||||
if (excel) {
|
if (excel) {
|
||||||
auto data = report.getData();
|
auto data = report.getData();
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <string>
|
||||||
#include "common/Colors.h"
|
#include "common/Colors.h"
|
||||||
#include "common/CLocale.h"
|
#include "common/CLocale.h"
|
||||||
#include "common/Paths.h"
|
#include "common/Paths.h"
|
||||||
@@ -66,12 +67,13 @@ namespace platform {
|
|||||||
auto pages = paginator[static_cast<int>(output_type)].getPages();
|
auto pages = paginator[static_cast<int>(output_type)].getPages();
|
||||||
auto lines = paginator[static_cast<int>(output_type)].getLines();
|
auto lines = paginator[static_cast<int>(output_type)].getLines();
|
||||||
auto total = paginator[static_cast<int>(output_type)].getTotal();
|
auto total = paginator[static_cast<int>(output_type)].getTotal();
|
||||||
std::string header = " Lines " + std::to_string(lines) + " "
|
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 prefix = std::string(max_status_line - suffix.size() - header.size(), ' ');
|
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 << std::endl;
|
std::cout << Colors::CLRSCR() << Colors::REVERSE() << Colors::WHITE() << header << prefix
|
||||||
|
<< Colors::MAGENTA() << suffix << Colors::RESET() << std::endl;
|
||||||
}
|
}
|
||||||
void ManageResults::footer(const std::string& status, const std::string& status_color)
|
void ManageResults::footer(const std::string& status, const std::string& status_color)
|
||||||
{
|
{
|
||||||
@@ -102,6 +104,7 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void ManageResults::list_result(const std::string& status_message, const std::string& status_color)
|
void ManageResults::list_result(const std::string& status_message, const std::string& status_color)
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
//
|
||||||
// header
|
// header
|
||||||
//
|
//
|
||||||
@@ -115,14 +118,21 @@ namespace platform {
|
|||||||
void ManageResults::list_datasets(const std::string& status_message, const std::string& status_color)
|
void ManageResults::list_datasets(const std::string& status_message, const std::string& status_color)
|
||||||
{
|
{
|
||||||
auto report = DatasetsConsole();
|
auto report = DatasetsConsole();
|
||||||
report.list_datasets();
|
report.report();
|
||||||
auto output = report.getOutput();
|
|
||||||
paginator[static_cast<int>(output_type)].setTotal(report.getNumLines());
|
paginator[static_cast<int>(output_type)].setTotal(report.getNumLines());
|
||||||
//
|
//
|
||||||
// header
|
// header
|
||||||
//
|
//
|
||||||
header();
|
header();
|
||||||
|
//
|
||||||
|
// Results
|
||||||
|
//
|
||||||
|
auto data = report.getBody();
|
||||||
|
std::cout << report.getHeader();
|
||||||
|
auto [index_from, index_to] = paginator[static_cast<int>(output_type)].getOffset();
|
||||||
|
for (int i = index_from; i <= index_to; i++) {
|
||||||
|
std::cout << data[i];
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// Status Area
|
// Status Area
|
||||||
//
|
//
|
||||||
@@ -268,7 +278,7 @@ namespace platform {
|
|||||||
std::vector<std::tuple<std::string, char, bool>> mainOptions = {
|
std::vector<std::tuple<std::string, char, bool>> mainOptions = {
|
||||||
{"quit", 'q', false},
|
{"quit", 'q', false},
|
||||||
{"list", 'l', false},
|
{"list", 'l', false},
|
||||||
{"delete", 'x', true},
|
{"delete", 'D', true},
|
||||||
{"datasets", 'd', false},
|
{"datasets", 'd', false},
|
||||||
{"hide", 'h', true},
|
{"hide", 'h', true},
|
||||||
{"sort", 's', false},
|
{"sort", 's', false},
|
||||||
@@ -289,6 +299,7 @@ namespace platform {
|
|||||||
{"back", 'b', false},
|
{"back", 'b', false},
|
||||||
{"quit", 'q', false}
|
{"quit", 'q', false}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parser = CommandParser();
|
auto parser = CommandParser();
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
bool parserError = true; // force the first iteration
|
bool parserError = true; // force the first iteration
|
||||||
@@ -368,7 +379,7 @@ namespace platform {
|
|||||||
list(STATUS_OK, STATUS_COLOR);
|
list(STATUS_OK, STATUS_COLOR);
|
||||||
indexList = true;
|
indexList = true;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'D':
|
||||||
filename = results.at(index).getFilename();
|
filename = results.at(index).getFilename();
|
||||||
if (!confirmAction("delete", filename)) {
|
if (!confirmAction("delete", filename)) {
|
||||||
list(filename + " not deleted!", Colors::YELLOW());
|
list(filename + " not deleted!", Colors::YELLOW());
|
||||||
@@ -401,6 +412,10 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
if (output_type == OutputType::DATASETS) {
|
||||||
|
list_datasets(STATUS_OK, STATUS_COLOR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (indexList) {
|
if (indexList) {
|
||||||
report(index, false);
|
report(index, false);
|
||||||
indexList = false;
|
indexList = false;
|
||||||
|
@@ -5,44 +5,73 @@
|
|||||||
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
const int DatasetsConsole::BALANCE_LENGTH = 75;
|
const int DatasetsConsole::BALANCE_LENGTH = 75;
|
||||||
std::string DatasetsConsole::outputBalance(const std::string& balance)
|
void DatasetsConsole::split_lines(std::string line, const std::string& balance)
|
||||||
{
|
{
|
||||||
auto temp = std::string(balance);
|
auto temp = std::string(balance);
|
||||||
while (temp.size() > DatasetsConsole::BALANCE_LENGTH - 1) {
|
while (temp.size() > DatasetsConsole::BALANCE_LENGTH - 1) {
|
||||||
auto part = temp.substr(0, DatasetsConsole::BALANCE_LENGTH);
|
auto part = temp.substr(0, DatasetsConsole::BALANCE_LENGTH);
|
||||||
output << part << std::endl;
|
line += part + "\n";
|
||||||
output << setw(52) << " ";
|
body.push_back(line);
|
||||||
|
line = string(52, ' ');
|
||||||
temp = temp.substr(DatasetsConsole::BALANCE_LENGTH);
|
temp = temp.substr(DatasetsConsole::BALANCE_LENGTH);
|
||||||
}
|
}
|
||||||
return temp;
|
line += temp + "\n";
|
||||||
|
body.push_back(line);
|
||||||
}
|
}
|
||||||
void DatasetsConsole::list_datasets()
|
std::string DatasetsConsole::getOutput() const
|
||||||
{
|
{
|
||||||
output.str("");
|
std::string s;
|
||||||
|
for (const auto& piece : header) s += piece;
|
||||||
|
for (const auto& piece : body) s += piece;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
std::string DatasetsConsole::getHeader() const
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
for (const auto& piece : header) s += piece;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
void DatasetsConsole::report()
|
||||||
|
{
|
||||||
|
header.clear();
|
||||||
|
body.clear();
|
||||||
auto datasets = platform::Datasets(false, platform::Paths::datasets());
|
auto datasets = platform::Datasets(false, platform::Paths::datasets());
|
||||||
auto loc = std::locale("es_ES");
|
auto loc = std::locale("es_ES");
|
||||||
output.imbue(loc);
|
std::stringstream sheader;
|
||||||
output << Colors::GREEN() << " # Dataset Sampl. Feat. Cls Balance" << std::endl;
|
std::vector<std::string> header_labels = { " #", "Dataset", "Sampl.", "Feat.", "Cls", "Balance" };
|
||||||
std::string balanceBars = std::string(DatasetsConsole::BALANCE_LENGTH, '=');
|
std::vector<int> header_lengths = { 3, 30, 6, 5, 3, DatasetsConsole::BALANCE_LENGTH };
|
||||||
output << "=== ============================== ====== ===== === " << balanceBars << std::endl;
|
sheader << Colors::GREEN();
|
||||||
|
for (int i = 0; i < header_labels.size(); i++) {
|
||||||
|
sheader << setw(header_lengths[i]) << left << header_labels[i] << " ";
|
||||||
|
}
|
||||||
|
sheader << std::endl;
|
||||||
|
header.push_back(sheader.str());
|
||||||
|
std::string sline;
|
||||||
|
for (int i = 0; i < header_labels.size(); i++) {
|
||||||
|
sline += std::string(header_lengths[i], '=') + " ";
|
||||||
|
}
|
||||||
|
sline += "\n";
|
||||||
|
header.push_back(sline);
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (const auto& dataset : datasets.getNames()) {
|
for (const auto& dataset : datasets.getNames()) {
|
||||||
|
std::stringstream line;
|
||||||
|
line.imbue(loc);
|
||||||
auto color = num % 2 ? Colors::CYAN() : Colors::BLUE();
|
auto color = num % 2 ? Colors::CYAN() : Colors::BLUE();
|
||||||
output << color << setw(3) << right << num++ << " ";
|
line << color << setw(3) << right << num++ << " ";
|
||||||
output << setw(30) << left << dataset << " ";
|
line << setw(30) << left << dataset << " ";
|
||||||
datasets.loadDataset(dataset);
|
datasets.loadDataset(dataset);
|
||||||
auto nSamples = datasets.getNSamples(dataset);
|
auto nSamples = datasets.getNSamples(dataset);
|
||||||
output << setw(6) << right << nSamples << " ";
|
line << setw(6) << right << nSamples << " ";
|
||||||
output << setw(5) << right << datasets.getFeatures(dataset).size() << " ";
|
line << setw(5) << right << datasets.getFeatures(dataset).size() << " ";
|
||||||
output << setw(3) << right << datasets.getNClasses(dataset) << " ";
|
line << setw(3) << right << datasets.getNClasses(dataset) << " ";
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
|
oss.imbue(loc);
|
||||||
std::string sep = "";
|
std::string sep = "";
|
||||||
for (auto number : datasets.getClassesCounts(dataset)) {
|
for (auto number : datasets.getClassesCounts(dataset)) {
|
||||||
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
|
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
|
||||||
sep = " / ";
|
sep = " / ";
|
||||||
}
|
}
|
||||||
auto balance = outputBalance(oss.str());
|
split_lines(line.str(), oss.str());
|
||||||
output << balance << std::endl;
|
|
||||||
// Store data for Excel report
|
// Store data for Excel report
|
||||||
data[dataset] = json::object();
|
data[dataset] = json::object();
|
||||||
data[dataset]["samples"] = nSamples;
|
data[dataset]["samples"] = nSamples;
|
||||||
@@ -50,7 +79,6 @@ namespace platform {
|
|||||||
data[dataset]["classes"] = datasets.getNClasses(dataset);
|
data[dataset]["classes"] = datasets.getNClasses(dataset);
|
||||||
data[dataset]["balance"] = oss.str();
|
data[dataset]["balance"] = oss.str();
|
||||||
}
|
}
|
||||||
numLines = num + 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,15 +13,16 @@ namespace platform {
|
|||||||
static const int BALANCE_LENGTH;
|
static const int BALANCE_LENGTH;
|
||||||
DatasetsConsole() = default;
|
DatasetsConsole() = default;
|
||||||
~DatasetsConsole() = default;
|
~DatasetsConsole() = default;
|
||||||
std::string getOutput() const { return output.str(); }
|
std::string getOutput() const;
|
||||||
int getNumLines() const { return numLines; }
|
std::string getHeader() const;
|
||||||
|
std::vector<std::string>& getBody() { return body; }
|
||||||
|
int getNumLines() const { return body.size(); }
|
||||||
json& getData() { return data; }
|
json& getData() { return data; }
|
||||||
std::string outputBalance(const std::string& balance);
|
void report();
|
||||||
void list_datasets();
|
|
||||||
private:
|
private:
|
||||||
std::stringstream output;
|
void split_lines(std::string line, const std::string& balance);
|
||||||
|
std::vector<std::string> header, body;
|
||||||
json data;
|
json data;
|
||||||
int numLines = 0;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user