kopia lustrzana https://gitlab.com/tomaszg/geostat
Add support from histograms sorted by first key and apply it to get month histogram
rodzic
7aa45dc1cb
commit
53dc1f1c57
18
geostat.cpp
18
geostat.cpp
|
@ -38,7 +38,7 @@ void show_usage() {
|
|||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void show_histogram(Caches* cc, std::string Cache::*ptr, std::string caption, bool html = 0) {
|
||||
void show_histogram(Caches* cc, std::string Cache::*ptr, std::string caption, bool html = 0, bool sort_by_val = 1) {
|
||||
std::map<std::string, int> histogram;
|
||||
std::vector<std::pair<std::string, int>> pairs;
|
||||
|
||||
|
@ -46,10 +46,17 @@ void show_histogram(Caches* cc, std::string Cache::*ptr, std::string caption, bo
|
|||
histogram[el.*ptr]++;
|
||||
for (auto el : histogram)
|
||||
pairs.push_back(el);
|
||||
sort(pairs.begin(), pairs.end(), [=](std::pair<std::string, int>& a, std::pair<std::string, int>& b) { return a.second > b.second; });
|
||||
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; });
|
||||
else
|
||||
sort(pairs.begin(), pairs.end(), [=](std::pair<std::string, int>& a, std::pair<std::string, int>& b) { return a.first < b.first; });
|
||||
|
||||
if (html) {
|
||||
int max = pairs[0].second;
|
||||
int max;
|
||||
if (sort_by_val)
|
||||
max = pairs[0].second;
|
||||
else
|
||||
max = std::max_element(pairs.begin(), pairs.end(), [=](std::pair<std::string, int>& a, std::pair<std::string, int>& b) { return a.second < b.second; })->second;
|
||||
int i = 0;
|
||||
std::cout << "<h2>" << caption << "</h2>\n";
|
||||
std::cout << "<dl class=\"histogram\">\n";
|
||||
|
@ -83,6 +90,7 @@ int main(int argc, char** argv) {
|
|||
bool show_dt = 0;
|
||||
bool show_owners = 0;
|
||||
bool show_types = 0;
|
||||
bool show_calendar = 0;
|
||||
bool show_html = 0;
|
||||
std::string heat_file;
|
||||
int heat_stamp_size = 15;
|
||||
|
@ -303,6 +311,10 @@ int main(int argc, char** argv) {
|
|||
show_histogram(&cc, &Cache::region, "Regions", show_html);
|
||||
}
|
||||
|
||||
if ((show_calendar || show_html) && !get_not_found) {
|
||||
show_histogram(&cc, &Cache::mon, "Month", show_html, 0);
|
||||
}
|
||||
|
||||
if (show_dt && !get_not_found) {
|
||||
short dt_table[11][11];
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
|
|||
if (el2.first == c.code) {
|
||||
c.date_found = el2.second;
|
||||
c.year = std::to_string(el2.second.tm_year);
|
||||
std::strftime(month, 20, "%B", &el2.second);
|
||||
std::strftime(month, 20, "(%m) %B", &el2.second);
|
||||
c.mon = month;
|
||||
c.day = std::to_string(el2.second.tm_mday);
|
||||
c.hour = std::to_string(el2.second.tm_hour);
|
||||
|
|
Ładowanie…
Reference in New Issue