Make more stats use only filtered list of caches in a consistent way

sql-rework
Tomasz Golinski 2020-01-25 11:40:56 +01:00
rodzic 7777103ed8
commit a5abf529bb
3 zmienionych plików z 25 dodań i 19 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <ctime>
@ -79,5 +80,6 @@ public:
};
typedef std::set<Cache, CacheCmp> Caches;
typedef std::multimap<std::time_t, const Cache*> Date_Caches;
float cache_distance(const Cache& a, const Cache& b);

Wyświetl plik

@ -9,7 +9,6 @@
#include <iomanip>
#include <algorithm>
#include <unistd.h>
#include <map>
const int HIST_MAX = 20;
@ -345,6 +344,21 @@ int main(int argc, char** argv) {
std::exit(EXIT_FAILURE);
}
// Prepare sorted list of caches, excluding moving caches
std::map<std::string, int> dates;
Date_Caches sorted_caches;
Caches fcc;
std::tm tmp;
for (auto& i : cc) {
dates[i.date]++;
if (i.type != "Moving" && i.type != "Own") {
tmp = i.date_tm;
sorted_caches.insert({ std::mktime(&tmp), &i });
fcc.insert(i);
}
}
if (show_html) {
std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
std::cout << "<html>\n";
@ -365,7 +379,7 @@ int main(int argc, char** argv) {
std::cout << "Map " << heat_map << " not found.\n";
std::exit(EXIT_FAILURE);
}
Heat hmap(&cc, chosen_map);
Heat hmap(&fcc, chosen_map);
hmap.generate(heat_file, heat_stamp_size, (heat_exp == 1 ? "exp" : "soft"));
if (show_html)
std::cout << "<img class=\"heatmap\" src=\"" << heat_file << "\" alt=\"heat map\">\n";
@ -374,17 +388,7 @@ int main(int argc, char** argv) {
if (show_html && !get_not_found) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Number of caches found: <span class=\"value\">" << cc.size() << "</span><br>\n";
std::map<std::string, int> dates;
std::multimap<std::time_t, const Cache*> sorted_caches;
std::tm tmp;
for (auto& i : cc) {
dates[i.date]++;
if (i.type != "Moving" && i.type != "Own") {
tmp = i.date_tm;
sorted_caches.insert({ std::mktime(&tmp), &i });
}
}
auto best_day = std::max_element(dates.begin(), dates.end(), [&](auto& a, auto& b) { return a.second < b.second; });
std::cout << "Number of caching days: <span class=\"value\">" << dates.size() << "</span><br>\n";
std::cout << "Average caches per caching day: <span class=\"value\">" << std::setprecision(3) << (1.0 * cc.size()) / dates.size() << "</span><br>\n";
@ -417,10 +421,10 @@ int main(int argc, char** argv) {
}
if ((show_minmax || show_html) && !get_not_found) {
auto N = std::max_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lat < b.pos.lat; });
auto S = std::min_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lat < b.pos.lat; });
auto E = std::max_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lon < b.pos.lon; });
auto W = std::min_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lon < b.pos.lon; });
auto N = std::max_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lat < b.pos.lat; });
auto S = std::min_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lat < b.pos.lat; });
auto E = std::max_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lon < b.pos.lon; });
auto W = std::min_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lon < b.pos.lon; });
if (show_minmax) {
std::cout << "Most N:\n";
@ -448,8 +452,8 @@ int main(int argc, char** argv) {
}
if (show_dist && !get_not_found) {
auto far = std::max_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.distance() < b.distance(); });
auto near = std::min_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.distance() < b.distance(); });
auto far = std::max_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.distance() < b.distance(); });
auto near = std::min_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.distance() < b.distance(); });
std::cout << "Nearest cache: " << near->distance() << " km\n";
near->show();

Wyświetl plik

@ -21,7 +21,7 @@ void Heat::generate(std::string filename, int size, std::string theme) {
std::vector<unsigned char> image(mp->size_x * mp->size_y * 4);
for (auto el : *points) {
if (mp->contains(Position(el.pos.lat, el.pos.lon)) && el.type != "Moving" && el.type != "Own") {
if (mp->contains(Position(el.pos.lat, el.pos.lon))) {
heatmap_add_point_with_stamp(hm, mp->coordinate_x(Position(el.pos.lat, el.pos.lon)), mp->coordinate_y(Position(el.pos.lat, el.pos.lon)), stamp);
// std::cout << mp->coordinate_x(Position(el.pos.lon, el.pos.lat)) << '\t' << mp->coordinate_y(Position(el.pos.lon, el.pos.lat)) << '\n';
}