Skip to content

Commit

Permalink
Statistics table: removed the horizontal lines between two iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanaret committed Oct 28, 2024
1 parent 9a8d4ed commit 75cbcb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
59 changes: 26 additions & 33 deletions uno/tools/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace uno {
this->columns[order] = name;
this->widths[name] = width;
}

void Statistics::start_new_line() {
//this->current_line.clear();
for (const auto& column: this->columns) {
this->current_line[column.second] = "-";
}
}

void Statistics::set(std::string_view name, std::string value) {
this->current_line[name] = std::move(value);
Expand All @@ -39,25 +46,30 @@ namespace uno {
stream << std::defaultfloat << std::setprecision(Statistics::numerical_format_size) << value;
this->set(name, stream.str());
}

void Statistics::print_header(bool first_occurrence) {
/* line above */
std::cout << (first_occurrence ? Statistics::symbol("top-left") : Statistics::symbol("left-mid"));
int k = 0;

void Statistics::print_horizontal_line(bool top) {
std::cout << (top ? Statistics::symbol("top-left") : Statistics::symbol("left-mid"));
size_t k = 0;
for (const auto& element: this->columns) {
if (0 < k) {
std::cout << (first_occurrence ? Statistics::symbol("top-mid") : Statistics::symbol("mid-mid"));
std::cout << (top ? Statistics::symbol("top-mid") : Statistics::symbol("mid-mid"));
}
const std::string& header = element.second;
std::string header = element.second;
for (int j = 0; j < this->widths[header]; j++) {
//std::cout << Statistics::symbol("bottom");
std::cout << Statistics::symbol("top");
}
k++;
}
std::cout << (first_occurrence ? Statistics::symbol("top-right") : Statistics::symbol("right-mid")) << '\n';
std::cout << (top ? Statistics::symbol("top-right") : Statistics::symbol("right-mid")) << '\n';
}

void Statistics::print_header() {
/* line above */
this->print_horizontal_line(this->iteration == 0);
/* headers */
std::cout << Statistics::symbol("left");
k = 0;
size_t k = 0;
for (const auto& element: this->columns) {
if (0 < k) {
std::cout << Statistics::symbol("middle");
Expand All @@ -70,28 +82,16 @@ namespace uno {
k++;
}
std::cout << Statistics::symbol("right") << '\n';
/* line below */
this->print_horizontal_line(false);
}

void Statistics::print_current_line() {
if (this->iteration % this->print_header_every_iterations == 0) {
this->print_header(this->iteration == 0);
this->print_header();
}
std::cout << Statistics::symbol("left-mid");
int k = 0;
for (const auto& element: this->columns) {
if (0 < k) {
std::cout << Statistics::symbol("mid-mid");
}
std::string header = element.second;
for (int j = 0; j < this->widths[header]; j++) {
std::cout << Statistics::symbol("bottom");
}
k++;
}
std::cout << Statistics::symbol("right-mid") << '\n';
/* headers */
std::cout << Statistics::symbol("left");
k = 0;
size_t k = 0;
for (const auto& element: this->columns) {
if (0 < k) {
std::cout << Statistics::symbol("middle");
Expand Down Expand Up @@ -132,14 +132,7 @@ namespace uno {
}
std::cout << Statistics::symbol("bottom-right") << '\n';
}

void Statistics::start_new_line() {
//this->current_line.clear();
for (const auto& column: this->columns) {
this->current_line[column.second] = "-";
}
}


std::string_view Statistics::symbol(std::string_view value) {
static std::map<std::string_view, std::string_view> symbols = {
{"top", ""},
Expand Down
7 changes: 5 additions & 2 deletions uno/tools/Statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ namespace uno {
static int numerical_format_size;

void add_column(std::string_view name, int width, int order);
void start_new_line();
void set(std::string_view name, std::string value);
void set(std::string_view name, int value);
void set(std::string_view name, size_t value);
void set(std::string_view name, double value);
void print_header(bool first_occurrence);

void print_horizontal_line(bool top);
void print_header();
void print_current_line();
void print_footer();
void start_new_line();


private:
size_t iteration{0};
Expand Down

0 comments on commit 75cbcb9

Please sign in to comment.