Add codes tag to all other matrices

master
Tomasz Golinski 2021-04-20 22:41:20 +02:00
rodzic 0a7383ba64
commit 25ae4af2a8
3 zmienionych plików z 23 dodań i 15 usunięć

Wyświetl plik

@ -292,6 +292,20 @@ int sum(const Caches& cc, int Cache::*ptr) {
return std::accumulate(cc.begin(), cc.end(), 0, [&](const int& a, const Cache& b) { return std::move(a) + b.*ptr; });
}
int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test) {
int count = 0;
codes.clear();
for (auto& c : cc) {
if (test(c)) {
count++;
codes += c.code;
codes += ' ';
}
}
codes.pop_back();
return count;
}
void header_html() {
std::cout << "<!DOCTYPE html>\n";
std::cout << "<html lang=\"en\">\n";

Wyświetl plik

@ -2,6 +2,8 @@
#include "cache.h"
#include <functional>
void htmlencode(std::string& data);
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1);
@ -23,5 +25,7 @@ void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption);
float sum(const Caches& cc, float Cache::*ptr);
int sum(const Caches& cc, int Cache::*ptr);
int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test);
void header_html();
void footer_html();

Wyświetl plik

@ -741,18 +741,7 @@ int main(int argc, char** argv) {
for (int i = 2; i <= 10; i++) { // i -> diff in rows
std::cout << "<tr><th>" << i / 2.0 << "</th> ";
for (int j = 2; j <= 10; j++) { // j -> terr in cols
// count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.diff == i / 2.0 && c.terr == j / 2.0); });
count = 0;
codes.clear();
for (auto& c : cc) {
if (c.diff == i / 2.0 && c.terr == j / 2.0) {
count++;
codes += c.code;
codes += ' ';
}
}
codes.pop_back();
count = count_caches(cc, codes, [i, j](const Cache& c) -> bool { return (c.diff == i / 2.0 && c.terr == j / 2.0); });
if (count == 0)
std::cout << "<td class=\"dt_zero\">" << 0 << "</td>";
else {
@ -784,7 +773,7 @@ int main(int argc, char** argv) {
for (int i = 1; i <= 12; i++) { // i -> months in rows
std::cout << "<tr><th>" << i << "</th> ";
for (int j = 1; j <= 31; j++) { // j -> days in cols
count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_tm.tm_mon == i - 1 && c.date_tm.tm_mday == j); });
count = count_caches(cc, codes, [i, j](const Cache& c) -> bool { return (c.date_tm.tm_mon == i - 1 && c.date_tm.tm_mday == j); });
if (count == 0) {
if ((j == 31 && (i == 2 || i == 4 || i == 6 || i == 9 || i == 11)) || (j == 30 && i == 2))
std::cout << "<td class=\"dt_null\"></td>";
@ -817,7 +806,7 @@ int main(int argc, char** argv) {
for (int i = y_min; i <= y_max; i++) { // i -> years in rows
std::cout << "<tr><th>" << i + 1900 << "</th> ";
for (int j = 1; j <= 12; j++) { // j -> months in cols
count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); });
count = count_caches(cc, codes, [i, j](const Cache& c) -> bool { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); });
if (count == 0)
std::cout << "<td class=\"dt_zero\">" << 0 << "</td>";
else
@ -846,6 +835,7 @@ int main(int argc, char** argv) {
if (get_owned) {
short count;
std::string codes;
int n;
std::cout << "<div class=\"basic_stats\">\n";
@ -1055,7 +1045,7 @@ int main(int argc, char** argv) {
for (int i = 2; i <= 10; i++) { // i -> diff in rows
std::cout << "<tr><th>" << i / 2.0 << "</th> ";
for (int j = 2; j <= 10; j++) { // j -> terr in cols
count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.diff == i / 2.0 && c.terr == j / 2.0); });
count = count_caches(cc, codes, [i, j](const Cache& c) -> bool { return (c.diff == i / 2.0 && c.terr == j / 2.0); });
if (count == 0)
std::cout << "<td class=\"dt_zero\">" << 0 << "</td>";
else {