Add a way to show histogram from data prepared beforehand

sql-rework
Tomasz Golinski 2020-06-03 00:26:45 +02:00
rodzic 942c52b998
commit 38c3fc56ef
2 zmienionych plików z 11 dodań i 4 usunięć

Wyświetl plik

@ -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; });

Wyświetl plik

@ -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);