diff --git a/common.cpp b/common.cpp index 96e2092..7ffb3da 100644 --- a/common.cpp +++ b/common.cpp @@ -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 << "
\n"; + std::cout << "Total " << caption << ": " << sum(cc, ptr) << "
\n"; + std::cout << "
\n"; +} + +void sum_html(const Caches& cc, int Cache::*ptr, const std::string& caption) { + std::cout << "
\n"; + std::cout << "Total " << caption << ": " << sum(cc, ptr) << "
\n"; + std::cout << "
\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; }); +} diff --git a/common.h b/common.h index 3e52e1e..28564d5 100644 --- a/common.h +++ b/common.h @@ -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); diff --git a/geostat.cpp b/geostat.cpp index b0157c4..ba8103d 100644 --- a/geostat.cpp +++ b/geostat.cpp @@ -852,6 +852,7 @@ int main(int argc, char** argv) { std::cout << "\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 << "\n"; average_html(cc, &Cache::founds, "number of finds"); + sum_html(cc, &Cache::founds, "number of finds"); n = 1;