Add some total counts to owned caches stats

sql-rework
Tomasz Golinski 2020-08-05 02:37:38 +02:00
rodzic 2ef585d4a0
commit e96a2ded1e
3 zmienionych plików z 27 dodań i 0 usunięć

Wyświetl plik

@ -262,3 +262,23 @@ float average(const Caches& cc, float Cache::*ptr) {
float average(const Caches& cc, int Cache::*ptr) {
return 1.0 * std::accumulate(cc.begin(), cc.end(), 0, [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; }) / cc.size();
}
void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
std::cout << "</div>\n";
}
void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Total " << caption << ": <span class=\"value\">" << sum(cc, ptr) << "</span><br>\n";
std::cout << "</div>\n";
}
float sum(const Caches& cc, float Cache::*ptr) {
return std::accumulate(cc.begin(), cc.end(), 0., [&](const float& a, const Cache& b) { return std::move(a) + b.*ptr; });
}
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; });
}

Wyświetl plik

@ -17,3 +17,8 @@ void average_html(const Caches& cc, float Cache::*ptr, const std::string& captio
void average_html(const Caches& cc, int Cache::*ptr, const std::string& caption);
float average(const Caches& cc, float Cache::*ptr);
float average(const Caches& cc, int Cache::*ptr);
void sum_html(const Caches& cc, float Cache::*ptr, const std::string& caption);
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);

Wyświetl plik

@ -852,6 +852,7 @@ int main(int argc, char** argv) {
std::cout << "</table>\n";
average_html(cc, &Cache::fav, "number of recommendations");
sum_html(cc, &Cache::fav, "number of recommendations");
n = 1;
@ -902,6 +903,7 @@ int main(int argc, char** argv) {
std::cout << "</table>\n";
average_html(cc, &Cache::founds, "number of finds");
sum_html(cc, &Cache::founds, "number of finds");
n = 1;