Further refactor and simplifications

master
Tomasz Golinski 2023-08-30 16:40:12 +02:00
rodzic 3f109a7047
commit 868b62bb2e
12 zmienionych plików z 196 dodań i 166 usunięć

Wyświetl plik

@ -4,7 +4,6 @@
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include <vector>
#include <iterator> #include <iterator>
#include <cmath> #include <cmath>

Wyświetl plik

@ -5,13 +5,22 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include <set>
#include <map> #include <map>
#include <vector> #include <vector>
#include <ctime> #include <ctime>
class Cache; class Cache;
enum Service {
ocpl,
ocde,
ocus,
ocro,
ocuk,
ocnl,
none
};
const uint Earth_radius = 6378; const uint Earth_radius = 6378;
const uint Moon_dist = 384400; const uint Moon_dist = 384400;
@ -19,13 +28,6 @@ typedef std::vector<Cache> Caches;
typedef std::vector<const Cache*> pCaches; typedef std::vector<const Cache*> pCaches;
typedef std::multimap<std::time_t, const Cache*> Date_Caches; typedef std::multimap<std::time_t, const Cache*> Date_Caches;
const std::string ocpl_url = "https://opencaching.pl/okapi/";
const std::string ocde_url = "https://www.opencaching.de/okapi/";
const std::string ocus_url = "http://www.opencaching.us/okapi/";
const std::string ocnl_url = "http://www.opencaching.nl/okapi/";
const std::string ocro_url = "http://www.opencaching.ro/okapi/";
const std::string ocuk_url = "https://opencache.uk/okapi/";
const std::string flag_pl = "https://wiki.opencaching.eu/images/b/b7/Oc-pl.png"; const std::string flag_pl = "https://wiki.opencaching.eu/images/b/b7/Oc-pl.png";
const std::string flag_de = "https://wiki.opencaching.eu/images/c/c1/Oc-de.png"; const std::string flag_de = "https://wiki.opencaching.eu/images/c/c1/Oc-de.png";
const std::string flag_us = "https://wiki.opencaching.eu/images/f/fb/Oc-us.png"; const std::string flag_us = "https://wiki.opencaching.eu/images/f/fb/Oc-us.png";
@ -33,10 +35,6 @@ const std::string flag_nl = "https://wiki.opencaching.eu/images/4/4b/Oc-nl.png";
const std::string flag_ro = "https://wiki.opencaching.eu/images/4/4f/Oc-ro.png"; const std::string flag_ro = "https://wiki.opencaching.eu/images/4/4f/Oc-ro.png";
const std::string flag_uk = "https://wiki.opencaching.eu/images/5/58/Oc-org-uk.png"; const std::string flag_uk = "https://wiki.opencaching.eu/images/5/58/Oc-org-uk.png";
const std::string Database_pl = "ocpl.sqlite";
const std::string Database_de = "ocde.sqlite";
const std::string Database_us = "ocus.sqlite";
void htmlencode(std::string& data); 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 Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1);

Wyświetl plik

@ -15,10 +15,8 @@ using json = nlohmann::json;
int main(int argc, char** argv) { int main(int argc, char** argv) {
std::string Dump_path; std::string Dump_path;
std::string Database;
std::string okapi_url;
std::string okapi_key;
bool update = 0; bool update = 0;
Service service = none;
int o; int o;
while ((o = getopt(argc, argv, "pdui:cD:h?")) != -1) while ((o = getopt(argc, argv, "pdui:cD:h?")) != -1)
@ -43,31 +41,25 @@ int main(int argc, char** argv) {
update = 1; update = 1;
break; break;
case 'd': case 'd':
if (!Database.empty()) { if (service != none) {
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n"; std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
Database = Database_de; service = ocde;
okapi_url = ocde_url;
okapi_key = ocde_key;
break; break;
case 'p': case 'p':
if (!Database.empty()) { if (service != none) {
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n"; std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
Database = Database_pl; service = ocpl;
okapi_url = ocpl_url;
okapi_key = ocpl_key;
break; break;
case 'u': case 'u':
if (!Database.empty()) { if (service != none) {
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n"; std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
Database = Database_us; service = ocus;
okapi_url = ocus_url;
okapi_key = ocus_key;
break; break;
case 'h': case 'h':
case '?': case '?':
@ -84,17 +76,17 @@ int main(int argc, char** argv) {
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
if (Database.empty()) { if (service == none) {
std::cout << "You need to specify one of the options \"-d\", \"-p\", \"-u\".\n"; std::cout << "You need to specify one of the options \"-d\", \"-p\", \"-u\".\n";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
OCdb db(Database); OCdb db(service);
if (!Dump_path.empty()) if (!Dump_path.empty())
db.init(Dump_path); db.init(Dump_path);
if (update) { if (update) {
Okapi OK(okapi_url, okapi_key); Okapi OK(service);
db.update(OK); db.update(OK);
} }
Debug(2) << "Database now at revision: " << db.get_revision(); Debug(2) << "Database now at revision: " << db.get_revision();

Wyświetl plik

@ -1,6 +1,5 @@
#include "okapi.h"
#include "cache.h"
#include "debug.h" #include "debug.h"
#include "user.h"
#include "common.h" #include "common.h"
#include <iostream> #include <iostream>
@ -14,34 +13,28 @@ void show_usage() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
#include "config_user.h"
if (argc < 3) show_usage(); if (argc < 3) show_usage();
std::string ocpl_user1 = argv[1]; User user1, user2;
std::string ocpl_user2 = argv[2]; user1.ocpl_user = argv[1];
user2.ocpl_user = argv[2];
user1.use_oc = true;
user2.use_oc = true;
user1.get_caches();
user2.get_caches();
int cc_no1 = user1.caches_hidden;
int cc_no2 = user2.caches_hidden;
Okapi OCpl(ocpl_url, ocpl_key); pCaches caches_by_user1, caches_by_user2;
std::string ocpl_user_uuid1 = OCpl.get_uuid(ocpl_user1);
std::string ocpl_user_profile1 = OCpl.get_profile_url(ocpl_user_uuid1);
std::string ocpl_user_uuid2 = OCpl.get_uuid(ocpl_user2);
std::string ocpl_user_profile2 = OCpl.get_profile_url(ocpl_user_uuid2);
Caches cc1 = OCpl.get_user_caches(ocpl_user_uuid1, 0);
Caches cc2 = OCpl.get_user_caches(ocpl_user_uuid2, 0);
int cc_no1 = OCpl.get_user_caches_no(ocpl_user_uuid1); for (auto& i : user2.cc) {
int cc_no2 = OCpl.get_user_caches_no(ocpl_user_uuid2); if (i.owner_uuid == user1.ocpl_user_uuid)
pCaches caches_by_user1;
pCaches caches_by_user2;
for (auto& i : cc2) {
if (i.owner_uuid == ocpl_user_uuid1)
caches_by_user1.push_back(&i); caches_by_user1.push_back(&i);
} }
for (auto& i : cc1) { for (auto& i : user1.cc) {
if (i.owner_uuid == ocpl_user_uuid2) if (i.owner_uuid == user2.ocpl_user_uuid)
caches_by_user2.push_back(&i); caches_by_user2.push_back(&i);
} }
@ -49,72 +42,77 @@ int main(int argc, char** argv) {
std::cout << "<header>\n"; std::cout << "<header>\n";
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n"; std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
std::cout << "<img alt=\"OCpl\" src=\"https://wiki.opencaching.eu/images/b/b7/Oc-pl.png\"> <a href=\"" << ocpl_user_profile1 << "\">" << ocpl_user1 << "</a><br>\n"; user1.header();
std::cout << "<img alt=\"OCpl\" src=\"https://wiki.opencaching.eu/images/b/b7/Oc-pl.png\"> <a href=\"" << ocpl_user_profile2 << "\">" << ocpl_user2 << "</a><br>\n"; user2.header();
std::cout << "</header>\n"; std::cout << "</header>\n";
std::cout << "<div class=\"basic_stats\">\n"; std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Number of caches created by " << ocpl_user1 << " found by " << ocpl_user2 << ": <span class=\"value\">" << caches_by_user1.size() << "</span><br>\n";
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(cc2.begin(), cc2.end(), [ocpl_user_uuid1](const auto& c) { return (c.recommended && c.owner_uuid == ocpl_user_uuid1); }) << "</span><br>\n"; std::cout << "Number of caches created by " << user1.ocpl_user << " found by " << user2.ocpl_user << ": <span class=\"value\">" << caches_by_user1.size() << "</span><br>\n";
; std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(user2.cc.begin(), user2.cc.end(), [user1](const auto& c) { return (c.recommended && c.owner_uuid == user1.ocpl_user_uuid); }) << "</span><br>\n";
std::cout << "Number of caches created by " << ocpl_user2 << " found by " << ocpl_user1 << ": <span class=\"value\">" << caches_by_user2.size() << "</span><br>\n";
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(cc1.begin(), cc1.end(), [ocpl_user_uuid2](const auto& c) { return (c.recommended && c.owner_uuid == ocpl_user_uuid2); }) << "</span><br>\n"; std::cout << "Number of caches created by " << user2.ocpl_user << " found by " << user1.ocpl_user << ": <span class=\"value\">" << caches_by_user2.size() << "</span><br>\n";
; std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(user1.cc.begin(), user1.cc.end(), [user2](const auto& c) { return (c.recommended && c.owner_uuid == user2.ocpl_user_uuid); }) << "</span><br>\n";
std::cout << "</div>\n"; std::cout << "</div>\n";
// const int LIST_MAX = 100; // const int LIST_MAX = 100;
short int n = 1; short int n = 1;
std::cout << "<h2>Caches created by " << ocpl_user1 << " found by " << ocpl_user2 << "</h2>\n"; if (cc_no1 > 0) {
std::cout << "<div class=\"histogram friendbar\">\n"; std::cout << "<h2>Caches created by " << user1.ocpl_user << " found by " << user2.ocpl_user << "</h2>\n";
std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user1.size() / cc_no1 << "%;\"><span class=\"text\">" << 100 * caches_by_user1.size() / cc_no1 << "%</span></div>\n"; std::cout << "<div class=\"histogram friendbar\">\n";
std::cout << "</div>\n"; std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user1.size() / cc_no1 << "%;\"><span class=\"text\">" << 100 * caches_by_user1.size() / cc_no1 << "%</span></div>\n";
std::cout << "<table class=\"list\">\n"; std::cout << "</div>\n";
std::cout << "<tr><th></th>"; std::cout << "<table class=\"list\">\n";
std::cout << "<th>Cache</th>"; std::cout << "<tr><th></th>";
std::cout << "<th>Type</th>"; std::cout << "<th>Cache</th>";
std::cout << "<th>Date hidden</th>"; std::cout << "<th>Type</th>";
std::cout << "<th>Date found</th>"; std::cout << "<th>Date hidden</th>";
std::cout << "<th>Region</th>"; std::cout << "<th>Date found</th>";
std::cout << "</tr>\n"; std::cout << "<th>Region</th>";
for (auto& i : caches_by_user1) {
std::cout << "<tr><th>" << n << "</th> ";
std::cout << "<td>" << i->link_name() << "</td>";
std::cout << "<td>" << i->type << "</td>";
std::cout << "<td>" << i->date_hidden << "</td>";
std::cout << "<td>" << i->date << "</td>";
std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n"; std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break; for (auto& i : caches_by_user1) {
std::cout << "<tr><th>" << n << "</th> ";
std::cout << "<td>" << i->link_name() << "</td>";
std::cout << "<td>" << i->type << "</td>";
std::cout << "<td>" << i->date_hidden << "</td>";
std::cout << "<td>" << i->date << "</td>";
std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break;
}
std::cout << "</table>\n";
} }
std::cout << "</table>\n";
n = 1; if (cc_no2 > 0) {
std::cout << "<h2>Caches created by " << ocpl_user2 << " found by " << ocpl_user1 << "</h2>\n"; n = 1;
std::cout << "<div class=\"histogram friendbar\">\n"; std::cout << "<h2>Caches created by " << user2.ocpl_user << " found by " << user1.ocpl_user << "</h2>\n";
std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user2.size() / cc_no2 << "%;\"><span class=\"text\">" << 100 * caches_by_user2.size() / cc_no2 << "%</span></div>\n"; std::cout << "<div class=\"histogram friendbar\">\n";
std::cout << "</div>\n"; std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user2.size() / cc_no2 << "%;\"><span class=\"text\">" << 100 * caches_by_user2.size() / cc_no2 << "%</span></div>\n";
std::cout << "<table class=\"list\">\n"; std::cout << "</div>\n";
std::cout << "<tr><th></th>"; std::cout << "<table class=\"list\">\n";
std::cout << "<th>Cache</th>"; std::cout << "<tr><th></th>";
std::cout << "<th>Type</th>"; std::cout << "<th>Cache</th>";
std::cout << "<th>Date hidden</th>"; std::cout << "<th>Type</th>";
std::cout << "<th>Date found</th>"; std::cout << "<th>Date hidden</th>";
std::cout << "<th>Region</th>"; std::cout << "<th>Date found</th>";
std::cout << "</tr>\n"; std::cout << "<th>Region</th>";
for (auto& i : caches_by_user2) {
std::cout << "<tr><th>" << n << "</th> ";
std::cout << "<td>" << i->link_name() << "</td>";
std::cout << "<td>" << i->type << "</td>";
std::cout << "<td>" << i->date_hidden << "</td>";
std::cout << "<td>" << i->date << "</td>";
std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n"; std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break; for (auto& i : caches_by_user2) {
std::cout << "<tr><th>" << n << "</th> ";
std::cout << "<td>" << i->link_name() << "</td>";
std::cout << "<td>" << i->type << "</td>";
std::cout << "<td>" << i->date_hidden << "</td>";
std::cout << "<td>" << i->date << "</td>";
std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break;
}
} }
std::cout << "</table>\n"; std::cout << "</table>\n";

Wyświetl plik

@ -46,32 +46,32 @@ int main(int argc, char** argv) {
} }
if (!code_pl.empty()) { if (!code_pl.empty()) {
Okapi OCpl(ocpl_url, ocpl_key); Okapi OCpl(ocpl);
Caches tmp = OCpl.get_caches(code_pl); Caches tmp = OCpl.get_caches(code_pl);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} }
if (!code_de.empty()) { if (!code_de.empty()) {
Okapi OCde(ocde_url, ocde_key); Okapi OCde(ocde);
Caches tmp = OCde.get_caches(code_de); Caches tmp = OCde.get_caches(code_de);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} }
if (!code_us.empty()) { if (!code_us.empty()) {
Okapi OCus(ocus_url, ocus_key); Okapi OCus(ocus);
Caches tmp = OCus.get_caches(code_us); Caches tmp = OCus.get_caches(code_us);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} }
if (!code_nl.empty()) { if (!code_nl.empty()) {
Okapi OCnl(ocnl_url, ocnl_key); Okapi OCnl(ocnl);
Caches tmp = OCnl.get_caches(code_nl); Caches tmp = OCnl.get_caches(code_nl);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} }
if (!code_ro.empty()) { if (!code_ro.empty()) {
Okapi OCro(ocro_url, ocro_key); Okapi OCro(ocro);
Caches tmp = OCro.get_caches(code_ro); Caches tmp = OCro.get_caches(code_ro);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} }
if (!code_uk.empty()) { if (!code_uk.empty()) {
Okapi OCuk(ocuk_url, ocuk_key); Okapi OCuk(ocuk);
Caches tmp = OCuk.get_caches(code_uk); Caches tmp = OCuk.get_caches(code_uk);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} }

Wyświetl plik

@ -161,6 +161,9 @@ int main(int argc, char** argv) {
user.prepare_lists_of_caches(); user.prepare_lists_of_caches();
header_html(); header_html();
std::cout << "<header>\n";
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
user.header(); user.header();
if (user.time_filter) { if (user.time_filter) {

Wyświetl plik

@ -11,10 +11,22 @@
using json = nlohmann::json; using json = nlohmann::json;
// using namespace std::literals::string_literals; // using namespace std::literals::string_literals;
OCdb::OCdb(const std::string& db_file) { OCdb::OCdb(const Service service) {
int res = 0; int res = 0;
res = sqlite3_open(db_file.c_str(), &db); switch (service) {
case ocpl:
res = sqlite3_open(Database_pl, &db);
break;
case ocde:
res = sqlite3_open(Database_de, &db);
break;
case ocus:
res = sqlite3_open(Database_us, &db);
default:
throw 1;
}
if (res != SQLITE_OK) { if (res != SQLITE_OK) {
Debug(1) << sqlite3_errmsg(db); Debug(1) << sqlite3_errmsg(db);
throw 1; throw 1;

6
ocdb.h
Wyświetl plik

@ -34,8 +34,12 @@ private:
other = -1 other = -1
}; };
constexpr static auto Database_pl = "ocpl.sqlite";
constexpr static auto Database_de = "ocde.sqlite";
constexpr static auto Database_us = "ocus.sqlite";
public: public:
explicit OCdb(const std::string& db_file); explicit OCdb(const Service service);
~OCdb(); ~OCdb();
bool init(const std::string& dump_path); // read db dump bool init(const std::string& dump_path); // read db dump

Wyświetl plik

@ -11,19 +11,37 @@
using json = nlohmann::json; using json = nlohmann::json;
Okapi::Okapi(const std::string& server_url, const std::string& consumer_key) : url(server_url), key(consumer_key) { Okapi::Okapi(const Service serv) : service(serv) {
if (url.find(".pl/") != std::string::npos) #include "config_user.h"
service = "OC.pl";
if (url.find(".de/") != std::string::npos) switch (serv) {
service = "OC.de"; case ocpl:
if (url.find(".us/") != std::string::npos) url = ocpl_url;
service = "OC.us"; key = ocpl_key;
if (url.find(".nl/") != std::string::npos) break;
service = "OC.nl"; case ocde:
if (url.find(".ro/") != std::string::npos) url = ocde_url;
service = "OC.ro"; key = ocde_key;
if (url.find(".uk/") != std::string::npos) break;
service = "OC.uk"; case ocus:
url = ocus_url;
key = ocus_key;
break;
case ocnl:
url = ocnl_url;
key = ocnl_key;
break;
case ocro:
url = ocro_url;
key = ocro_key;
break;
case ocuk:
url = ocuk_url;
key = ocuk_key;
break;
case none:
throw 1;
}
curl = curl_easy_init(); curl = curl_easy_init();
if (!curl) { if (!curl) {
@ -253,7 +271,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
return cc; return cc;
} }
int Okapi::get_user_caches_no(const std::string& uuid) const { int Okapi::get_user_hidden_caches_no(const std::string& uuid) const {
std::string api_service = url + OKAPI_user; std::string api_service = url + OKAPI_user;
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=caches_hidden"; std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=caches_hidden";
curl_post(api_service, query); curl_post(api_service, query);

15
okapi.h
Wyświetl plik

@ -3,7 +3,7 @@
#include "api.h" #include "api.h"
#include <string> #include <string>
#include <map> #include <set>
#include <utility> #include <utility>
typedef void CURL; typedef void CURL;
@ -13,7 +13,7 @@ private:
std::string url; std::string url;
std::string key; std::string key;
std::string service; Service service;
CURL* curl; CURL* curl;
mutable std::string curl_output; mutable std::string curl_output;
@ -35,14 +35,21 @@ private:
constexpr static auto OKAPI_user = "services/users/user"; constexpr static auto OKAPI_user = "services/users/user";
constexpr static auto OKAPI_changelog = "services/replicate/changelog"; constexpr static auto OKAPI_changelog = "services/replicate/changelog";
constexpr static auto ocpl_url = "https://opencaching.pl/okapi/";
constexpr static auto ocde_url = "https://www.opencaching.de/okapi/";
constexpr static auto ocus_url = "http://www.opencaching.us/okapi/";
constexpr static auto ocnl_url = "http://www.opencaching.nl/okapi/";
constexpr static auto ocro_url = "http://www.opencaching.ro/okapi/";
constexpr static auto ocuk_url = "https://opencache.uk/okapi/";
public: public:
Okapi(const std::string& server_url, const std::string& consumer_key); Okapi(const Service serv);
~Okapi(); ~Okapi();
// Cache get_cache(std::string code); // Cache get_cache(std::string code);
Caches get_caches(const std::set<std::string>& codes) const; Caches get_caches(const std::set<std::string>& codes) const;
Caches get_user_caches(const std::string& uuid, int count = 0) const override; Caches get_user_caches(const std::string& uuid, int count = 0) const override;
int get_user_caches_no(const std::string& uuid) const; int get_user_hidden_caches_no(const std::string& uuid) const;
std::string get_changelog_json(int revision) const; std::string get_changelog_json(int revision) const;
void update_caches(Caches& cc) const; void update_caches(Caches& cc) const;

Wyświetl plik

@ -5,11 +5,10 @@
#include "debug.h" #include "debug.h"
void User::get_caches() { void User::get_caches() {
#include "config_user.h"
if (use_oc) { if (use_oc) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) { if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
Okapi OCpl(ocpl_url, ocpl_key); Okapi OCpl(ocpl);
uint uid; uint uid;
if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user, &uid); if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user, &uid);
Caches tmp = OCpl.get_user_caches(ocpl_user_uuid, 0); Caches tmp = OCpl.get_user_caches(ocpl_user_uuid, 0);
@ -39,40 +38,41 @@ void User::get_caches() {
std::sort(tt.begin(), tt.end(), [&](const auto& a, const auto& b) { return a->completed_perc > b->completed_perc; }); std::sort(tt.begin(), tt.end(), [&](const auto& a, const auto& b) { return a->completed_perc > b->completed_perc; });
OCpl.get_ftf(uid, tmp); OCpl.get_ftf(uid, tmp);
caches_hidden = OCpl.get_user_hidden_caches_no(ocpl_user_uuid);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
ocpl_user_profile = OCpl.get_profile_url(ocpl_user_uuid); ocpl_user_profile = OCpl.get_profile_url(ocpl_user_uuid);
} }
if (!ocde_user_uuid.empty() || !ocde_user.empty()) { if (!ocde_user_uuid.empty() || !ocde_user.empty()) {
Okapi OCde(ocde_url, ocde_key); Okapi OCde(ocde);
if (!ocde_user.empty()) ocde_user_uuid = OCde.get_uuid(ocde_user); if (!ocde_user.empty()) ocde_user_uuid = OCde.get_uuid(ocde_user);
Caches tmp = OCde.get_user_caches(ocde_user_uuid, 0); Caches tmp = OCde.get_user_caches(ocde_user_uuid, 0);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
ocde_user_profile = OCde.get_profile_url(ocde_user_uuid); ocde_user_profile = OCde.get_profile_url(ocde_user_uuid);
} }
if (!ocus_user_uuid.empty() || !ocus_user.empty()) { if (!ocus_user_uuid.empty() || !ocus_user.empty()) {
Okapi OCus(ocus_url, ocus_key); Okapi OCus(ocus);
if (!ocus_user.empty()) ocus_user_uuid = OCus.get_uuid(ocus_user); if (!ocus_user.empty()) ocus_user_uuid = OCus.get_uuid(ocus_user);
Caches tmp = OCus.get_user_caches(ocus_user_uuid, 0); Caches tmp = OCus.get_user_caches(ocus_user_uuid, 0);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
ocus_user_profile = OCus.get_profile_url(ocus_user_uuid); ocus_user_profile = OCus.get_profile_url(ocus_user_uuid);
} }
if (!ocnl_user_uuid.empty() || !ocnl_user.empty()) { if (!ocnl_user_uuid.empty() || !ocnl_user.empty()) {
Okapi OCnl(ocnl_url, ocnl_key); Okapi OCnl(ocnl);
if (!ocnl_user.empty()) ocnl_user_uuid = OCnl.get_uuid(ocnl_user); if (!ocnl_user.empty()) ocnl_user_uuid = OCnl.get_uuid(ocnl_user);
Caches tmp = OCnl.get_user_caches(ocnl_user_uuid, 0); Caches tmp = OCnl.get_user_caches(ocnl_user_uuid, 0);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
ocnl_user_profile = OCnl.get_profile_url(ocnl_user_uuid); ocnl_user_profile = OCnl.get_profile_url(ocnl_user_uuid);
} }
if (!ocro_user_uuid.empty() || !ocro_user.empty()) { if (!ocro_user_uuid.empty() || !ocro_user.empty()) {
Okapi OCro(ocro_url, ocro_key); Okapi OCro(ocro);
if (!ocro_user.empty()) ocro_user_uuid = OCro.get_uuid(ocro_user); if (!ocro_user.empty()) ocro_user_uuid = OCro.get_uuid(ocro_user);
Caches tmp = OCro.get_user_caches(ocro_user_uuid, 0); Caches tmp = OCro.get_user_caches(ocro_user_uuid, 0);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
ocro_user_profile = OCro.get_profile_url(ocro_user_uuid); ocro_user_profile = OCro.get_profile_url(ocro_user_uuid);
} }
if (!ocuk_user_uuid.empty() || !ocuk_user.empty()) { if (!ocuk_user_uuid.empty() || !ocuk_user.empty()) {
Okapi OCuk(ocuk_url, ocuk_key); Okapi OCuk(ocuk);
if (!ocuk_user.empty()) ocuk_user_uuid = OCuk.get_uuid(ocuk_user); if (!ocuk_user.empty()) ocuk_user_uuid = OCuk.get_uuid(ocuk_user);
Caches tmp = OCuk.get_user_caches(ocuk_user_uuid, 0); Caches tmp = OCuk.get_user_caches(ocuk_user_uuid, 0);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
@ -88,21 +88,21 @@ void User::get_caches() {
if (use_ocdb) { if (use_ocdb) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) { if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
OCdb db(Database_pl); OCdb db(ocpl);
if (!ocpl_user.empty()) { if (!ocpl_user.empty()) {
Okapi OCpl(ocpl_url, ocpl_key); Okapi OCpl(ocpl);
ocpl_user_uuid = OCpl.get_uuid(ocpl_user); ocpl_user_uuid = OCpl.get_uuid(ocpl_user);
ocpl_user_profile = OCpl.get_profile_url(ocpl_user_uuid); ocpl_user_profile = OCpl.get_profile_url(ocpl_user_uuid);
} }
if (get_not_found) { if (get_not_found) {
Caches tmp = db.get_user_caches_not_found(ocpl_user_uuid); Caches tmp = db.get_user_caches_not_found(ocpl_user_uuid);
Okapi OCpl(ocpl_url, ocpl_key); Okapi OCpl(ocpl);
OCpl.update_caches(tmp); OCpl.update_caches(tmp);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
region_count = db.get_region_stats(); region_count = db.get_region_stats();
} else if (get_owned) { } else if (get_owned) {
Caches tmp = db.get_user_caches_owned(ocpl_user_uuid); Caches tmp = db.get_user_caches_owned(ocpl_user_uuid);
Okapi OCpl(ocpl_url, ocpl_key); Okapi OCpl(ocpl);
OCpl.update_caches(tmp); OCpl.update_caches(tmp);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} else { } else {
@ -111,21 +111,21 @@ void User::get_caches() {
} }
} }
if (!ocde_user_uuid.empty() || !ocde_user.empty()) { if (!ocde_user_uuid.empty() || !ocde_user.empty()) {
OCdb db(Database_de); OCdb db(ocde);
if (!ocde_user.empty()) { if (!ocde_user.empty()) {
Okapi OCde(ocde_url, ocde_key); Okapi OCde(ocde);
ocde_user_uuid = OCde.get_uuid(ocde_user); ocde_user_uuid = OCde.get_uuid(ocde_user);
ocde_user_profile = OCde.get_profile_url(ocde_user_uuid); ocde_user_profile = OCde.get_profile_url(ocde_user_uuid);
} }
if (get_not_found) { if (get_not_found) {
Caches tmp = db.get_user_caches_not_found(ocde_user_uuid); Caches tmp = db.get_user_caches_not_found(ocde_user_uuid);
Okapi OCde(ocde_url, ocde_key); Okapi OCde(ocde);
OCde.update_caches(tmp); OCde.update_caches(tmp);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
// region_count = db.get_region_stats(); // region_count = db.get_region_stats();
} else if (get_owned) { } else if (get_owned) {
Caches tmp = db.get_user_caches_owned(ocde_user_uuid); Caches tmp = db.get_user_caches_owned(ocde_user_uuid);
Okapi OCde(ocde_url, ocde_key); Okapi OCde(ocde);
OCde.update_caches(tmp); OCde.update_caches(tmp);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
} else { } else {
@ -199,8 +199,6 @@ void User::prepare_lists_of_caches() {
} }
void User::header() { void User::header() {
std::cout << "<header>\n";
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
if (!ocpl_user.empty()) if (!ocpl_user.empty())
std::cout << "<img alt=\"OCpl\" src=\"" << flag_pl << "\"> <a href=\"" << ocpl_user_profile << "\">" << ocpl_user << "</a><br>\n"; std::cout << "<img alt=\"OCpl\" src=\"" << flag_pl << "\"> <a href=\"" << ocpl_user_profile << "\">" << ocpl_user << "</a><br>\n";
if (!ocde_user.empty()) if (!ocde_user.empty())

29
user.h
Wyświetl plik

@ -12,14 +12,21 @@ private:
PowertrailDB traildb; PowertrailDB traildb;
Caches_in_Powertrails tc; Caches_in_Powertrails tc;
std::string ocpl_user_profile;
std::string ocde_user_profile;
std::string ocus_user_profile;
std::string ocnl_user_profile;
std::string ocro_user_profile;
std::string ocuk_user_profile;
public: public:
// Position home; // Position home;
std::string ocpl_user_uuid = ""; std::string ocpl_user_uuid;
std::string ocde_user_uuid = ""; std::string ocde_user_uuid;
std::string ocus_user_uuid = ""; std::string ocus_user_uuid;
std::string ocnl_user_uuid = ""; std::string ocnl_user_uuid;
std::string ocro_user_uuid = ""; std::string ocro_user_uuid;
std::string ocuk_user_uuid = ""; std::string ocuk_user_uuid;
bool use_oc = 0; bool use_oc = 0;
bool use_ocdb = 0; bool use_ocdb = 0;
@ -31,13 +38,6 @@ public:
std::string ocuk_user; std::string ocuk_user;
// std::string gpx_file; // std::string gpx_file;
std::string ocpl_user_profile;
std::string ocde_user_profile;
std::string ocus_user_profile;
std::string ocnl_user_profile;
std::string ocro_user_profile;
std::string ocuk_user_profile;
bool get_not_found = 0; bool get_not_found = 0;
bool get_owned = 0; bool get_owned = 0;
bool exclude_quiz = 0; bool exclude_quiz = 0;
@ -46,7 +46,8 @@ public:
bool time_filter = 0; bool time_filter = 0;
Caches cc; Caches cc;
int caches_count; int caches_count = 0;
int caches_hidden = 0;
std::map<std::string, int> dates; std::map<std::string, int> dates;
Date_Caches sorted_caches; Date_Caches sorted_caches;
Date_Caches sorted_fcaches; Date_Caches sorted_fcaches;