kopia lustrzana https://gitlab.com/tomaszg/geostat
Add an option to print out histograms of owners/types/services
rodzic
3218af8d99
commit
25b407f02f
|
@ -10,7 +10,7 @@ static float degtorad(float x) {
|
|||
}
|
||||
|
||||
void Cache::show() const {
|
||||
std::cout << "Cache:\t" << code << ' ' << name << '\n';
|
||||
std::cout << "Cache:\t" << code << ' ' << name << " (type: " << type << ", owned by " << owner << ")\n";
|
||||
std::cout << '\t' << pos.lat << " " << pos.lon << "\t\t D/T: " << diff << '/' << terr << '\n';
|
||||
}
|
||||
|
||||
|
|
24
cache.h
24
cache.h
|
@ -4,16 +4,16 @@
|
|||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
enum Service {
|
||||
gc,
|
||||
ocpl,
|
||||
ocde,
|
||||
ocna,
|
||||
ocro,
|
||||
ocuk,
|
||||
ocnl,
|
||||
gcsu
|
||||
};
|
||||
// enum Service {
|
||||
// gc,
|
||||
// ocpl,
|
||||
// ocde,
|
||||
// ocna,
|
||||
// ocro,
|
||||
// ocuk,
|
||||
// ocnl,
|
||||
// gcsu
|
||||
// };
|
||||
|
||||
// enum Type {
|
||||
// traditional,
|
||||
|
@ -46,7 +46,9 @@ public:
|
|||
float diff;
|
||||
float terr;
|
||||
std::string type;
|
||||
Service origin;
|
||||
std::string origin;
|
||||
std::string owner;
|
||||
std::string owner_uuid;
|
||||
|
||||
static Position home;
|
||||
|
||||
|
|
41
geostat.cpp
41
geostat.cpp
|
@ -8,12 +8,28 @@
|
|||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <unistd.h>
|
||||
#include <map>
|
||||
|
||||
void show_histogram(Caches* cc, std::string Cache::* ptr) {
|
||||
std::map<std::string, int> histogram;
|
||||
std::vector<std::pair<std::string, int>> pairs;
|
||||
for (auto el : *cc)
|
||||
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; });
|
||||
|
||||
for (auto own : pairs)
|
||||
std::cout << own.first << ": " << own.second << '\n';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool show_minmax = 0;
|
||||
bool show_dist = 0;
|
||||
bool show_list = 0;
|
||||
bool show_dt = 0;
|
||||
bool show_owners = 0;
|
||||
bool show_types = 0;
|
||||
std::string heat_file;
|
||||
int heat_stamp_size = 15;
|
||||
std::string heat_map;
|
||||
|
@ -25,7 +41,7 @@ int main(int argc, char** argv) {
|
|||
#include "config_user.h"
|
||||
|
||||
int o;
|
||||
while ((o = getopt(argc, argv, "g:d:pu:MDH:s:m:LTh")) != -1)
|
||||
while ((o = getopt(argc, argv, "g:d:pu:MDOH:s:m:LTYh")) != -1)
|
||||
switch (o) {
|
||||
case 'd':
|
||||
try {
|
||||
|
@ -54,6 +70,12 @@ int main(int argc, char** argv) {
|
|||
case 'D':
|
||||
show_dist = 1;
|
||||
break;
|
||||
case 'O':
|
||||
show_owners = 1;
|
||||
break;
|
||||
case 'Y':
|
||||
show_types = 1;
|
||||
break;
|
||||
case 'H':
|
||||
heat_file = optarg;
|
||||
break;
|
||||
|
@ -80,7 +102,7 @@ int main(int argc, char** argv) {
|
|||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
std::cout << "Usage: [-p] [-g file] [-MDHh]\n";
|
||||
std::cout << "Usage: [-p] [-g file] [-MDHLTOYh] [-s size] [-m map]\n";
|
||||
std::cout << "Generate stats from Opencaching data or GPX files.\n\n";
|
||||
std::cout << " * Data source:\n";
|
||||
std::cout << "\t-p\tuse Opencaching.pl\n";
|
||||
|
@ -94,6 +116,8 @@ int main(int argc, char** argv) {
|
|||
std::cout << "\t-m map\tchosen map: Poland, Poland_relief, Europe (default = Poland)\n";
|
||||
std::cout << "\t-L\tprint all caches\n";
|
||||
std::cout << "\t-T\tprint D/T matrix\n";
|
||||
std::cout << "\t-O\tprint owner count for found caches\n";
|
||||
std::cout << "\t-Y\tprint types count for found caches\n";
|
||||
std::cout << "\t-h\tdisplay this help screen\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -164,6 +188,19 @@ int main(int argc, char** argv) {
|
|||
el.show();
|
||||
}
|
||||
|
||||
if (show_owners) {
|
||||
std::cout << "Owners:\n";
|
||||
show_histogram(&cc, &Cache::owner);
|
||||
}
|
||||
|
||||
if (show_types) {
|
||||
std::cout << "Types:\n";
|
||||
show_histogram(&cc, &Cache::type);
|
||||
|
||||
std::cout << "\nService:\n";
|
||||
show_histogram(&cc, &Cache::origin);
|
||||
}
|
||||
|
||||
if (show_dt) {
|
||||
short dt_table[11][11];
|
||||
|
||||
|
|
15
gpx.cpp
15
gpx.cpp
|
@ -59,13 +59,22 @@ Caches GPX::get_user_caches(std::string uuid, int count) {
|
|||
c.name = el->desc().getValue();
|
||||
c.pos.lat = stof(el->lat().getValue());
|
||||
c.pos.lon = stof(el->lon().getValue());
|
||||
c.type = el->type().getValue();
|
||||
if (c.type.starts_with("Geocache|"))
|
||||
c.type.erase(0,9);
|
||||
if (c.type.ends_with(" Cache"))
|
||||
c.type.erase(c.type.end()-6, c.type.end());
|
||||
if (c.type.ends_with("-cache"))
|
||||
c.type.erase(c.type.end()-6, c.type.end());
|
||||
if (c.type == ("unknown"))
|
||||
c.type = "Unknown";
|
||||
|
||||
if (c.code.starts_with("GC"))
|
||||
c.origin = gc;
|
||||
c.origin = "GC";
|
||||
else if (c.code.starts_with("OP"))
|
||||
c.origin = ocpl;
|
||||
c.origin = "OC.pl";
|
||||
else if (c.code.starts_with("TR") || c.code.starts_with("VI") || c.code.starts_with("MV"))
|
||||
c.origin = gcsu;
|
||||
c.origin = "GC.su";
|
||||
|
||||
list.insert(c);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ std::string Okapi::get_user_caches_json(std::string uuid, int count, int offset)
|
|||
|
||||
std::string Okapi::get_caches_json(std::string codes) {
|
||||
std::string service = url + OKAPI_caches;
|
||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain";
|
||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner";
|
||||
return curl_post(service, query);
|
||||
}
|
||||
|
||||
|
@ -122,12 +122,14 @@ Caches Okapi::get_caches(std::vector<std::string> codes) {
|
|||
c.type = el.value()["type"];
|
||||
c.diff = el.value()["difficulty"];
|
||||
c.terr = el.value()["terrain"];
|
||||
;
|
||||
c.owner = el.value()["owner"]["username"];
|
||||
c.owner_uuid = el.value()["owner"]["uuid"];
|
||||
|
||||
std::string loc = el.value()["location"];
|
||||
int pos = loc.find("|");
|
||||
c.pos.lat = stof(loc.substr(0, pos));
|
||||
c.pos.lon = stof(loc.substr(pos + 1));
|
||||
c.origin = ocpl;
|
||||
c.origin = "OC.pl";
|
||||
cc.insert(c);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue