Complete Datasets in b_manage

This commit is contained in:
2024-03-16 22:39:25 +01:00
parent 58ae2c7690
commit 9c11dee019
4 changed files with 76 additions and 32 deletions

View File

@@ -5,44 +5,73 @@
namespace platform {
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);
while (temp.size() > DatasetsConsole::BALANCE_LENGTH - 1) {
auto part = temp.substr(0, DatasetsConsole::BALANCE_LENGTH);
output << part << std::endl;
output << setw(52) << " ";
line += part + "\n";
body.push_back(line);
line = string(52, ' ');
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 loc = std::locale("es_ES");
output.imbue(loc);
output << Colors::GREEN() << " # Dataset Sampl. Feat. Cls Balance" << std::endl;
std::string balanceBars = std::string(DatasetsConsole::BALANCE_LENGTH, '=');
output << "=== ============================== ====== ===== === " << balanceBars << std::endl;
std::stringstream sheader;
std::vector<std::string> header_labels = { " #", "Dataset", "Sampl.", "Feat.", "Cls", "Balance" };
std::vector<int> header_lengths = { 3, 30, 6, 5, 3, DatasetsConsole::BALANCE_LENGTH };
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;
for (const auto& dataset : datasets.getNames()) {
std::stringstream line;
line.imbue(loc);
auto color = num % 2 ? Colors::CYAN() : Colors::BLUE();
output << color << setw(3) << right << num++ << " ";
output << setw(30) << left << dataset << " ";
line << color << setw(3) << right << num++ << " ";
line << setw(30) << left << dataset << " ";
datasets.loadDataset(dataset);
auto nSamples = datasets.getNSamples(dataset);
output << setw(6) << right << nSamples << " ";
output << setw(5) << right << datasets.getFeatures(dataset).size() << " ";
output << setw(3) << right << datasets.getNClasses(dataset) << " ";
line << setw(6) << right << nSamples << " ";
line << setw(5) << right << datasets.getFeatures(dataset).size() << " ";
line << setw(3) << right << datasets.getNClasses(dataset) << " ";
std::stringstream oss;
oss.imbue(loc);
std::string sep = "";
for (auto number : datasets.getClassesCounts(dataset)) {
oss << sep << std::setprecision(2) << fixed << (float)number / nSamples * 100.0 << "% (" << number << ")";
sep = " / ";
}
auto balance = outputBalance(oss.str());
output << balance << std::endl;
split_lines(line.str(), oss.str());
// Store data for Excel report
data[dataset] = json::object();
data[dataset]["samples"] = nSamples;
@@ -50,7 +79,6 @@ namespace platform {
data[dataset]["classes"] = datasets.getNClasses(dataset);
data[dataset]["balance"] = oss.str();
}
numLines = num + 2;
}
}

View File

@@ -13,15 +13,16 @@ namespace platform {
static const int BALANCE_LENGTH;
DatasetsConsole() = default;
~DatasetsConsole() = default;
std::string getOutput() const { return output.str(); }
int getNumLines() const { return numLines; }
std::string getOutput() const;
std::string getHeader() const;
std::vector<std::string>& getBody() { return body; }
int getNumLines() const { return body.size(); }
json& getData() { return data; }
std::string outputBalance(const std::string& balance);
void list_datasets();
void report();
private:
std::stringstream output;
void split_lines(std::string line, const std::string& balance);
std::vector<std::string> header, body;
json data;
int numLines = 0;
};
}