kopia lustrzana https://gitlab.com/tomaszg/geostat
Add some extra stats to web output
rodzic
83273c8af4
commit
86de83a74c
|
@ -3,8 +3,6 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
const static int Earth_radius = 6378;
|
|
||||||
|
|
||||||
Position Cache::home;
|
Position Cache::home;
|
||||||
|
|
||||||
static float degtorad(float x) {
|
static float degtorad(float x) {
|
||||||
|
@ -35,6 +33,11 @@ void Cache::set_date(std::tm* t) {
|
||||||
day = std::to_string(date_tm.tm_mday);
|
day = std::to_string(date_tm.tm_mday);
|
||||||
hour = std::to_string(date_tm.tm_hour);
|
hour = std::to_string(date_tm.tm_hour);
|
||||||
|
|
||||||
std::strftime(tmp, 20, "%x", &date_tm);
|
std::strftime(tmp, 20, "%F", &date_tm);
|
||||||
date = tmp;
|
date = tmp;
|
||||||
|
// date += std::to_string(date_tm.tm_hour) + ":" + std::to_string(date_tm.tm_min) + ":" + std::to_string(date_tm.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
float cache_distance(const Cache& a, const Cache& b) {
|
||||||
|
return 2 * Earth_radius * asin(sqrt(pow(sin(degtorad((a.pos.lat - b.pos.lat) / 2)), 2) + cos(degtorad(a.pos.lat)) * cos(degtorad(b.pos.lat)) * pow(sin(degtorad((a.pos.lon - b.pos.lon) / 2)), 2)));
|
||||||
}
|
}
|
||||||
|
|
5
cache.h
5
cache.h
|
@ -29,6 +29,9 @@
|
||||||
// podcast //a geocache with attached MP3 file(s). The MP3 data is not accessible via OKAPI. This type is only in use at Opencaching.US
|
// podcast //a geocache with attached MP3 file(s). The MP3 data is not accessible via OKAPI. This type is only in use at Opencaching.US
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
const int Earth_radius = 6378;
|
||||||
|
const double Pi = 3.14159265358979323846264338327950288;
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
public:
|
public:
|
||||||
float lat = 0;
|
float lat = 0;
|
||||||
|
@ -75,3 +78,5 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::set<Cache, CacheCmp> Caches;
|
typedef std::set<Cache, CacheCmp> Caches;
|
||||||
|
|
||||||
|
float cache_distance(const Cache& a, const Cache& b);
|
||||||
|
|
4
geo.css
4
geo.css
|
@ -25,6 +25,10 @@ h2 {
|
||||||
color: #48B;
|
color: #48B;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.basic_stats {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
table, dl, .histogram_others, .heatmap {
|
table, dl, .histogram_others, .heatmap {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
|
|
27
geostat.cpp
27
geostat.cpp
|
@ -239,6 +239,33 @@ int main(int argc, char** argv) {
|
||||||
std::cout << "</head>\n";
|
std::cout << "</head>\n";
|
||||||
std::cout << "<body>\n";
|
std::cout << "<body>\n";
|
||||||
std::cout << "<h1>Geocaching stats for user " << ocpl_user << "<br>Powered by <a href=\"https://gitlab.com/tomaszg/geostat\">GeoStat</a></h1>\n";
|
std::cout << "<h1>Geocaching stats for user " << ocpl_user << "<br>Powered by <a href=\"https://gitlab.com/tomaszg/geostat\">GeoStat</a></h1>\n";
|
||||||
|
std::cout << "<div class=\"basic_stats\">\n";
|
||||||
|
std::cout << "Number of caches found: " << cc.size() << "<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: " << dates.size() << "<br>\n";
|
||||||
|
std::cout << "Average caches per caching day: " << std::setprecision(3) << (1.0 * cc.size()) / dates.size() << "<br>\n";
|
||||||
|
std::cout << "Best caching day: " << best_day->first << ", found " << best_day->second << " caches<br>\n";
|
||||||
|
// for (auto& i : dates)
|
||||||
|
// std::cout << i.first << ", found " << i.second << " caches<br>\n";
|
||||||
|
|
||||||
|
int tot_dist = 0;
|
||||||
|
for (auto i = sorted_caches.begin(); i != std::prev(sorted_caches.end()); i++) {
|
||||||
|
// std::cout << "Distance between " << i->second->name << " and " << std::next(i)->second->name << " is " << cache_distance(*i->second, *std::next(i)->second) << "<br>";
|
||||||
|
tot_dist += cache_distance(*i->second, *std::next(i)->second);
|
||||||
|
}
|
||||||
|
std::cout << "Total distance between caches: " << tot_dist << " km (equivalent to " << tot_dist/(2 * Pi * Earth_radius) << "x trips around Earth)<br>\n";
|
||||||
|
std::cout << "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!heat_file.empty()) {
|
if (!heat_file.empty()) {
|
||||||
|
|
Ładowanie…
Reference in New Issue