kopia lustrzana https://gitlab.com/tomaszg/geostat
Add a way to show histogram from data prepared beforehand
rodzic
942c52b998
commit
38c3fc56ef
14
common.cpp
14
common.cpp
|
@ -47,16 +47,22 @@ static std::string string_mangle(const std::string& str) {
|
|||
}
|
||||
|
||||
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html, bool sort_by_val) {
|
||||
std::map<std::string, int> histogram;
|
||||
|
||||
for (auto el : cc)
|
||||
histogram[el.*ptr]++;
|
||||
|
||||
show_histogram(histogram, caption, html, sort_by_val);
|
||||
}
|
||||
|
||||
void show_histogram(const std::map<std::string, int>& data, const std::string& caption, bool html, bool sort_by_val) {
|
||||
int HIST_MAX = 20;
|
||||
|
||||
std::map<std::string, int> histogram;
|
||||
std::vector<std::pair<std::string, int>> pairs;
|
||||
|
||||
if (!sort_by_val) HIST_MAX = 1000;
|
||||
|
||||
for (auto el : cc)
|
||||
histogram[el.*ptr]++;
|
||||
std::copy(histogram.begin(), histogram.end(), std::back_inserter(pairs));
|
||||
std::copy(data.begin(), data.end(), std::back_inserter(pairs));
|
||||
|
||||
if (sort_by_val)
|
||||
sort(pairs.begin(), pairs.end(), [&](std::pair<std::string, int>& a, std::pair<std::string, int>& b) { return a.second > b.second; });
|
||||
|
|
1
common.h
1
common.h
|
@ -5,6 +5,7 @@
|
|||
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 std::map<std::string, int>& 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);
|
||||
|
||||
int find_streak(const std::multimap<std::time_t, const Cache*>& cc, std::tm& start);
|
||||
|
|
Ładowanie…
Reference in New Issue