Compare commits
2 Commits
fe24aa0b3e
...
38978aa7b7
Author | SHA1 | Date | |
---|---|---|---|
38978aa7b7
|
|||
3691363b8e
|
@@ -6,11 +6,8 @@
|
|||||||
#include "common/Utils.h"
|
#include "common/Utils.h"
|
||||||
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
void CommandParser::messageError(const std::string& message)
|
|
||||||
{
|
std::tuple<char, int, bool> CommandParser::parse(const std::string& color, const std::vector<std::tuple<std::string, char, bool>>& options, const char defaultCommand, const int minIndex, const int maxIndex)
|
||||||
std::cout << Colors::RED() << message << Colors::RESET() << std::endl;
|
|
||||||
}
|
|
||||||
std::pair<char, int> CommandParser::parse(const std::string& color, const std::vector<std::tuple<std::string, char, bool>>& options, const char defaultCommand, const int minIndex, const int maxIndex)
|
|
||||||
{
|
{
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
@@ -29,16 +26,17 @@ namespace platform {
|
|||||||
oss << "): ";
|
oss << "): ";
|
||||||
std::cout << oss.str();
|
std::cout << oss.str();
|
||||||
getline(std::cin, line);
|
getline(std::cin, line);
|
||||||
std::cout << Colors::RESET();
|
|
||||||
line = trim(line);
|
line = trim(line);
|
||||||
if (line.size() == 0)
|
if (line.size() == 0) {
|
||||||
continue;
|
errorMessage = "No command";
|
||||||
|
return { defaultCommand, 0, true };
|
||||||
|
}
|
||||||
if (all_of(line.begin(), line.end(), ::isdigit)) {
|
if (all_of(line.begin(), line.end(), ::isdigit)) {
|
||||||
command = defaultCommand;
|
command = defaultCommand;
|
||||||
index = stoi(line);
|
index = stoi(line);
|
||||||
if (index > maxIndex || index < minIndex) {
|
if (index > maxIndex || index < minIndex) {
|
||||||
messageError("Index out of range");
|
errorMessage = "Index out of range";
|
||||||
continue;
|
return { command, index, true };
|
||||||
}
|
}
|
||||||
finished = true;
|
finished = true;
|
||||||
break;
|
break;
|
||||||
@@ -53,24 +51,24 @@ namespace platform {
|
|||||||
if (std::get<bool>(option)) {
|
if (std::get<bool>(option)) {
|
||||||
// The option requires a value
|
// The option requires a value
|
||||||
if (line.size() == 0) {
|
if (line.size() == 0) {
|
||||||
messageError("Option " + std::get<std::string>(option) + " requires a value");
|
errorMessage = "Option " + std::get<std::string>(option) + " requires a value";
|
||||||
break;
|
return { command, index, true };
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
index = stoi(line);
|
index = stoi(line);
|
||||||
if (index > maxIndex || index < 0) {
|
if (index > maxIndex || index < 0) {
|
||||||
messageError("Index out of range");
|
errorMessage = "Index out of range";
|
||||||
break;
|
return { command, index, true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::invalid_argument& ia) {
|
catch (const std::invalid_argument& ia) {
|
||||||
messageError("Invalid value: " + line);
|
errorMessage = "Invalid value: " + line;
|
||||||
break;
|
return { command, index, true };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (line.size() > 0) {
|
if (line.size() > 0) {
|
||||||
messageError("option " + std::get<std::string>(option) + " doesn't accept values");
|
errorMessage = "option " + std::get<std::string>(option) + " doesn't accept values";
|
||||||
break;
|
return { command, index, true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command = std::get<char>(option);
|
command = std::get<char>(option);
|
||||||
@@ -79,9 +77,10 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
messageError("I don't know " + line);
|
errorMessage = "I don't know " + line;
|
||||||
|
return { command, index, true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { command, index };
|
return { command, index, false };
|
||||||
}
|
}
|
||||||
} /* namespace platform */
|
} /* namespace platform */
|
@@ -8,11 +8,12 @@ namespace platform {
|
|||||||
class CommandParser {
|
class CommandParser {
|
||||||
public:
|
public:
|
||||||
CommandParser() = default;
|
CommandParser() = default;
|
||||||
std::pair<char, int> parse(const std::string& color, const std::vector<std::tuple<std::string, char, bool>>& options, const char defaultCommand, const int minIndex, const int maxIndex);
|
std::tuple<char, int, bool> parse(const std::string& color, const std::vector<std::tuple<std::string, char, bool>>& options, const char defaultCommand, const int minIndex, const int maxIndex);
|
||||||
char getCommand() const { return command; };
|
char getCommand() const { return command; };
|
||||||
int getIndex() const { return index; };
|
int getIndex() const { return index; };
|
||||||
|
std::string getErrorMessage() const { return errorMessage; };
|
||||||
private:
|
private:
|
||||||
void messageError(const std::string& message);
|
std::string errorMessage;
|
||||||
char command;
|
char command;
|
||||||
int index;
|
int index;
|
||||||
};
|
};
|
||||||
|
@@ -13,21 +13,19 @@ 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();
|
||||||
ManageResults::ManageResults(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
|
ManageResults::ManageResults(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
|
||||||
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(ResultsManager(model, score, complete, partial))
|
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, didExcel(false), results(ResultsManager(model, score, complete, partial))
|
||||||
{
|
{
|
||||||
results.load();
|
results.load();
|
||||||
if (!results.empty()) {
|
results.sortDate();
|
||||||
results.sortDate();
|
sort_field = "Date";
|
||||||
indexList = true;
|
indexList = true;
|
||||||
openExcel = false;
|
openExcel = false;
|
||||||
workbook = NULL;
|
workbook = NULL;
|
||||||
if (numFiles == 0 or numFiles > results.size()) {
|
if (numFiles == 0 or numFiles > results.size()) {
|
||||||
this->numFiles = results.size();
|
this->numFiles = results.size();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
paginator = Paginator(numFiles, results.size());
|
paginator = Paginator(numFiles, results.size());
|
||||||
page = 1;
|
page = 1;
|
||||||
sort_field = "Date";
|
|
||||||
}
|
}
|
||||||
void ManageResults::doMenu()
|
void ManageResults::doMenu()
|
||||||
{
|
{
|
||||||
@@ -41,6 +39,9 @@ namespace platform {
|
|||||||
if (openExcel) {
|
if (openExcel) {
|
||||||
workbook_close(workbook);
|
workbook_close(workbook);
|
||||||
}
|
}
|
||||||
|
if (didExcel) {
|
||||||
|
std::cout << Colors::MAGENTA() << "Excel file created: " << Paths::excel() + Paths::excelResults() << std::endl;
|
||||||
|
}
|
||||||
std::cout << Colors::RESET() << "Done!" << std::endl;
|
std::cout << Colors::RESET() << "Done!" << std::endl;
|
||||||
}
|
}
|
||||||
void ManageResults::list(const std::string& status_message_init, const std::string& status_color, int index_A, int index_B)
|
void ManageResults::list(const std::string& status_message_init, const std::string& status_color, int index_A, int index_B)
|
||||||
@@ -51,7 +52,7 @@ namespace platform {
|
|||||||
int maxModel = results.maxModelSize();
|
int maxModel = results.maxModelSize();
|
||||||
int maxTitle = results.maxTitleSize();
|
int maxTitle = results.maxTitleSize();
|
||||||
std::vector<int> header_lengths = { 3, 10, maxModel, 10, 9, 3, 7, maxTitle };
|
std::vector<int> header_lengths = { 3, 10, maxModel, 10, 9, 3, 7, maxTitle };
|
||||||
int maxLine = std::accumulate(header_lengths.begin(), header_lengths.end(), 0) + header_lengths.size() - 1;
|
int maxLine = std::max(size_t(140), std::accumulate(header_lengths.begin(), header_lengths.end(), 0) + header_lengths.size() - 1);
|
||||||
auto temp = ConfigLocale();
|
auto temp = ConfigLocale();
|
||||||
auto [index_from, index_to] = paginator.getOffset(page);
|
auto [index_from, index_to] = paginator.getOffset(page);
|
||||||
std::string suffix = "";
|
std::string suffix = "";
|
||||||
@@ -61,8 +62,9 @@ namespace platform {
|
|||||||
if (partial) {
|
if (partial) {
|
||||||
suffix = " Only listing partial results ";
|
suffix = " Only listing partial results ";
|
||||||
}
|
}
|
||||||
std::string header = " " + std::to_string(index_to - index_from + 1) + " Results on screen - Page "
|
std::string header = " " + std::to_string(index_to - index_from + 1) + " Results on screen of "
|
||||||
+ std::to_string(page) + " of " + std::to_string(paginator.getPages()) + " ";
|
+ std::to_string(results.size()) + " - Page " + std::to_string(page) + " of "
|
||||||
|
+ std::to_string(paginator.getPages()) + " ";
|
||||||
|
|
||||||
std::string prefix = std::string(maxLine - suffix.size() - header.size(), ' ');
|
std::string prefix = std::string(maxLine - 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 << std::endl;
|
||||||
@@ -136,12 +138,14 @@ namespace platform {
|
|||||||
auto data_B = results.at(index_B).getJson();
|
auto data_B = results.at(index_B).getJson();
|
||||||
ReportExcelCompared reporter(data_A, data_B);
|
ReportExcelCompared reporter(data_A, data_B);
|
||||||
reporter.report();
|
reporter.report();
|
||||||
|
didExcel = true;
|
||||||
return results.at(index_A).getFilename() + " Vs " + results.at(index_B).getFilename();
|
return results.at(index_A).getFilename() + " Vs " + results.at(index_B).getFilename();
|
||||||
}
|
}
|
||||||
std::string ManageResults::report(const int index, const bool excelReport)
|
std::string ManageResults::report(const int index, const bool excelReport)
|
||||||
{
|
{
|
||||||
auto data = results.at(index).getJson();
|
auto data = results.at(index).getJson();
|
||||||
if (excelReport) {
|
if (excelReport) {
|
||||||
|
didExcel = true;
|
||||||
ReportExcel reporter(data, compare, workbook);
|
ReportExcel reporter(data, compare, workbook);
|
||||||
reporter.show();
|
reporter.show();
|
||||||
openExcel = true;
|
openExcel = true;
|
||||||
@@ -224,13 +228,21 @@ namespace platform {
|
|||||||
};
|
};
|
||||||
auto parser = CommandParser();
|
auto parser = CommandParser();
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
if (indexList) {
|
bool parserError = true; // force the first iteration
|
||||||
auto [min_index, max_index] = paginator.getOffset(page);
|
while (parserError) {
|
||||||
std::tie(option, index) = parser.parse(Colors::IGREEN(), mainOptions, 'r', min_index, max_index);
|
if (indexList) {
|
||||||
} else {
|
auto [min_index, max_index] = paginator.getOffset(page);
|
||||||
std::tie(option, subIndex) = parser.parse(Colors::IBLUE(), listOptions, 'r', 0, results.at(index).getJson()["results"].size() - 1);
|
std::tie(option, index, parserError) = parser.parse(Colors::IGREEN(), mainOptions, 'r', min_index, max_index);
|
||||||
|
} else {
|
||||||
|
std::tie(option, subIndex, parserError) = parser.parse(Colors::IBLUE(), listOptions, 'r', 0, results.at(index).getJson()["results"].size() - 1);
|
||||||
|
}
|
||||||
|
if (parserError) {
|
||||||
|
if (indexList)
|
||||||
|
list(parser.getErrorMessage(), Colors::RED(), index_A, index_B);
|
||||||
|
else
|
||||||
|
showIndex(index, subIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'p':
|
case 'p':
|
||||||
if (paginator.valid(index)) {
|
if (paginator.valid(index)) {
|
||||||
|
@@ -21,6 +21,7 @@ namespace platform {
|
|||||||
int numFiles;
|
int numFiles;
|
||||||
bool indexList;
|
bool indexList;
|
||||||
bool openExcel;
|
bool openExcel;
|
||||||
|
bool didExcel;
|
||||||
bool complete;
|
bool complete;
|
||||||
bool partial;
|
bool partial;
|
||||||
bool compare;
|
bool compare;
|
||||||
|
@@ -7,7 +7,7 @@ public:
|
|||||||
Paginator() = default;
|
Paginator() = default;
|
||||||
Paginator(int pageSize, int total) : pageSize(pageSize), total(total)
|
Paginator(int pageSize, int total) : pageSize(pageSize), total(total)
|
||||||
{
|
{
|
||||||
numPages = (total + pageSize - 1) / pageSize;
|
numPages = pageSize > 0 ? (total + pageSize - 1) / pageSize : 0;
|
||||||
};
|
};
|
||||||
~Paginator() = default;
|
~Paginator() = default;
|
||||||
int getPageSize() const { return pageSize; }
|
int getPageSize() const { return pageSize; }
|
||||||
|
@@ -48,6 +48,8 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void ResultsManager::sortDate()
|
void ResultsManager::sortDate()
|
||||||
{
|
{
|
||||||
|
if (empty())
|
||||||
|
return;
|
||||||
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
||||||
if (a.getDate() == b.getDate()) {
|
if (a.getDate() == b.getDate()) {
|
||||||
return a.getModel() < b.getModel();
|
return a.getModel() < b.getModel();
|
||||||
@@ -57,6 +59,8 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void ResultsManager::sortModel()
|
void ResultsManager::sortModel()
|
||||||
{
|
{
|
||||||
|
if (empty())
|
||||||
|
return;
|
||||||
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
||||||
if (a.getModel() == b.getModel()) {
|
if (a.getModel() == b.getModel()) {
|
||||||
return a.getDate() > b.getDate();
|
return a.getDate() > b.getDate();
|
||||||
@@ -66,12 +70,16 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
void ResultsManager::sortDuration()
|
void ResultsManager::sortDuration()
|
||||||
{
|
{
|
||||||
|
if (empty())
|
||||||
|
return;
|
||||||
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
||||||
return a.getDuration() > b.getDuration();
|
return a.getDuration() > b.getDuration();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void ResultsManager::sortScore()
|
void ResultsManager::sortScore()
|
||||||
{
|
{
|
||||||
|
if (files.empty())
|
||||||
|
return;
|
||||||
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
sort(files.begin(), files.end(), [](const Result& a, const Result& b) {
|
||||||
if (a.getScore() == b.getScore()) {
|
if (a.getScore() == b.getScore()) {
|
||||||
return a.getDate() > b.getDate();
|
return a.getDate() > b.getDate();
|
||||||
|
@@ -58,7 +58,7 @@ int main(int argc, char** argv)
|
|||||||
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) {
|
if (number == 0) {
|
||||||
number = std::max(0, numRows() - 5); // 5 is the number of lines used by the menu & header
|
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;
|
||||||
|
Reference in New Issue
Block a user