From 193d6931a880cb296e5f1d0255e54cd28d8c856e Mon Sep 17 00:00:00 2001 From: Tomasz Golinski Date: Fri, 17 Jul 2020 19:57:46 +0200 Subject: [PATCH] Histograms related to region data should use filtered cache list --- common.cpp | 21 +++++++++++++++------ common.h | 3 ++- geostat.cpp | 6 +++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/common.cpp b/common.cpp index a491227..96e2092 100644 --- a/common.cpp +++ b/common.cpp @@ -48,6 +48,15 @@ static std::string string_mangle(const std::string& str) { return tmp; } +void show_histogram(const pCaches& fcc, std::string Cache::*ptr, const std::string& caption, bool html, bool sort_by_val) { + std::map histogram; + + for (auto el : fcc) + histogram[el->*ptr]++; + + show_histogram(histogram, caption, html, sort_by_val); +} + void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html, bool sort_by_val) { std::map histogram; @@ -106,12 +115,12 @@ void show_histogram(const std::map& data, const std::string& c } } -void show_nested_histogram(const Caches& cc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html, bool sort_by_val) { +void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html, bool sort_by_val) { std::map histogram; std::vector> pairs; - for (auto el : cc) - histogram[el.*ptr]++; + for (auto el : fcc) + histogram[el->*ptr]++; std::copy(histogram.begin(), histogram.end(), std::back_inserter(pairs)); if (sort_by_val) @@ -136,9 +145,9 @@ void show_nested_histogram(const Caches& cc, std::string Cache::*ptr, std::strin if (i < HIST_MAX) { std::map subhistogram; std::vector> subpairs; - for (auto el : cc) - if (el.*ptr == own.first && !(el.*ptr2).empty()) //TODO problem with [unknown] - subhistogram[el.*ptr2]++; + for (auto el : fcc) + if (el->*ptr == own.first && !(el->*ptr2).empty()) //TODO problem with [unknown] + subhistogram[el->*ptr2]++; if (!subhistogram.empty()) { std::cout << "
" << own.first << ": " << own.second << "\n"; std::copy(subhistogram.begin(), subhistogram.end(), std::back_inserter(subpairs)); diff --git a/common.h b/common.h index 1216e87..3e52e1e 100644 --- a/common.h +++ b/common.h @@ -5,8 +5,9 @@ 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); +void show_histogram(const pCaches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1); void show_histogram(const std::map& data, const std::string& caption, bool html = 0, bool sort_by_val = 1); -void show_nested_histogram(const Caches& cc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html = 0, bool sort_by_val = 1); +void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html = 0, bool sort_by_val = 1); int find_streak(const std::multimap& cc, std::time_t& start); diff --git a/geostat.cpp b/geostat.cpp index f80dfaf..0b4b09d 100644 --- a/geostat.cpp +++ b/geostat.cpp @@ -457,9 +457,9 @@ int main(int argc, char** argv) { show_histogram(cc, &Cache::owner, "Cache owners", 1); show_histogram(cc, &Cache::type, "Cache types", 1); show_histogram(cc, &Cache::size, "Cache sizes", 1); -// show_histogram(cc, &Cache::region, "Regions", 1); -// show_histogram(cc, &Cache::subregion, "Subregions", 1); - show_nested_histogram(cc, &Cache::region, &Cache::subregion, "Regions", 1); +// show_histogram(fcc, &Cache::region, "Regions", 1); +// show_histogram(fcc, &Cache::subregion, "Subregions", 1); + show_nested_histogram(fcc, &Cache::region, &Cache::subregion, "Regions", 1); show_histogram(cc, &Cache::day_of_week, "Days of the week", 1, 0); show_histogram(cc, &Cache::mon, "Months", 1, 0); show_histogram(cc, &Cache::year, "Years", 1, 0);