kopia lustrzana https://gitlab.com/tomaszg/geostat
Include list of FTFs
rodzic
fc0372a887
commit
54b077de6d
2
cache.h
2
cache.h
|
@ -54,6 +54,7 @@ public:
|
||||||
class Cache {
|
class Cache {
|
||||||
public:
|
public:
|
||||||
std::string code;
|
std::string code;
|
||||||
|
int internal_id;
|
||||||
Position pos;
|
Position pos;
|
||||||
std::string name;
|
std::string name;
|
||||||
Status status;
|
Status status;
|
||||||
|
@ -86,6 +87,7 @@ public:
|
||||||
int age_when_found = -1;
|
int age_when_found = -1;
|
||||||
int age_now = -1;
|
int age_now = -1;
|
||||||
int trail = 0;
|
int trail = 0;
|
||||||
|
bool ftf = 0;
|
||||||
|
|
||||||
void set_date(const std::tm& t);
|
void set_date(const std::tm& t);
|
||||||
void set_date_hidden(const std::tm& t);
|
void set_date_hidden(const std::tm& t);
|
||||||
|
|
37
geostat.cpp
37
geostat.cpp
|
@ -201,7 +201,8 @@ int main(int argc, char** argv) {
|
||||||
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_url, ocpl_key);
|
||||||
if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user);
|
int 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);
|
||||||
|
|
||||||
t.read_from_json("powertrails.json");
|
t.read_from_json("powertrails.json");
|
||||||
|
@ -217,6 +218,8 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OCpl.get_ftf(uid, tmp);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -346,6 +349,7 @@ int main(int argc, char** argv) {
|
||||||
pCaches caches_by_fav;
|
pCaches caches_by_fav;
|
||||||
pCaches caches_by_fav_perc;
|
pCaches caches_by_fav_perc;
|
||||||
pCaches caches_by_finds;
|
pCaches caches_by_finds;
|
||||||
|
pCaches caches_ftf;
|
||||||
// pCaches caches_by_rating;
|
// pCaches caches_by_rating;
|
||||||
pCaches fcc;
|
pCaches fcc;
|
||||||
|
|
||||||
|
@ -369,7 +373,8 @@ int main(int argc, char** argv) {
|
||||||
caches_by_fav_perc.push_back(&*i);
|
caches_by_fav_perc.push_back(&*i);
|
||||||
caches_by_finds.push_back(&*i);
|
caches_by_finds.push_back(&*i);
|
||||||
// caches_by_rating.push_back(&*i);
|
// caches_by_rating.push_back(&*i);
|
||||||
|
if (i->ftf)
|
||||||
|
caches_ftf.push_back(&*i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
std::sort(caches_by_fav.begin(), caches_by_fav.end(), [&](const Cache* a, const Cache* b) { return a->fav > b->fav; });
|
std::sort(caches_by_fav.begin(), caches_by_fav.end(), [&](const Cache* a, const Cache* b) { return a->fav > b->fav; });
|
||||||
|
@ -910,6 +915,34 @@ int main(int argc, char** argv) {
|
||||||
std::cout << "Number of started power trails: <span class=\"value\">" << tt.size() << "</span><br>\n";
|
std::cout << "Number of started power trails: <span class=\"value\">" << tt.size() << "</span><br>\n";
|
||||||
std::cout << "</div>\n";
|
std::cout << "</div>\n";
|
||||||
|
|
||||||
|
std::cout << "<h2>FTF</h2>\n";
|
||||||
|
std::cout << "<table class=\"list\">\n";
|
||||||
|
std::cout << "<tr><th></th>";
|
||||||
|
std::cout << "<th>Cache</th>";
|
||||||
|
std::cout << "<th>Type</th>";
|
||||||
|
std::cout << "<th>Region</th>";
|
||||||
|
std::cout << "<th>Date hidden</th>";
|
||||||
|
std::cout << "<th>Finds</th>";
|
||||||
|
std::cout << "</tr>\n";
|
||||||
|
|
||||||
|
n = 1;
|
||||||
|
|
||||||
|
for (auto i : caches_ftf) {
|
||||||
|
std::cout << "<tr><th>" << n << "</th> ";
|
||||||
|
std::cout << "<td>" << i->link_name() << "</td>";
|
||||||
|
std::cout << "<td>" << i->type << "</td>";
|
||||||
|
std::cout << "<td>" << i->region << "</td>";
|
||||||
|
std::cout << "<td>" << i->date_hidden << "</td>";
|
||||||
|
std::cout << "<td>" << i->founds << "</td>";
|
||||||
|
std::cout << "</tr>\n";
|
||||||
|
n++;
|
||||||
|
// if (n > LIST_MAX) break;
|
||||||
|
}
|
||||||
|
std::cout << "</table>\n";
|
||||||
|
std::cout << "<div class=\"basic_stats\">\n";
|
||||||
|
// std::cout << "Number of FTFs: <span class=\"value\">" << std::count_if(cc.begin(), cc.end(), [&](const auto& a) { return a.ftf; }) << "</span><br>\n";
|
||||||
|
std::cout << "Number of FTFs: <span class=\"value\">" << caches_ftf.size() << "</span><br>\n";
|
||||||
|
std::cout << "</div>\n";
|
||||||
} // end of main if
|
} // end of main if
|
||||||
|
|
||||||
if (get_not_found) {
|
if (get_not_found) {
|
||||||
|
|
34
okapi.cpp
34
okapi.cpp
|
@ -93,7 +93,7 @@ void Okapi::get_user_caches_json(const std::string& uuid, int count, int offset)
|
||||||
|
|
||||||
void Okapi::get_caches_json(const std::string& codes) const {
|
void Okapi::get_caches_json(const std::string& codes) const {
|
||||||
std::string service = url + OKAPI_caches;
|
std::string service = url + OKAPI_caches;
|
||||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|country2|size2|date_created|recommendations|rating|founds|status";
|
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|country2|size2|date_created|recommendations|rating|founds|status|internal_id";
|
||||||
curl_post(service, query);
|
curl_post(service, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ Caches Okapi::get_caches(const std::set<std::string>& codes) const {
|
||||||
for (auto& el : j.items()) {
|
for (auto& el : j.items()) {
|
||||||
if (el.value().is_null()) continue;
|
if (el.value().is_null()) continue;
|
||||||
c.code = el.value()["code"];
|
c.code = el.value()["code"];
|
||||||
|
c.internal_id = el.value()["internal_id"];
|
||||||
c.name = el.value()["name"];
|
c.name = el.value()["name"];
|
||||||
c.type = el.value()["type"];
|
c.type = el.value()["type"];
|
||||||
c.size = el.value()["size2"];
|
c.size = el.value()["size2"];
|
||||||
|
@ -310,13 +311,14 @@ void Okapi::update_caches_ratings(Caches& cc) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Okapi::get_uuid(const std::string& username) const {
|
std::string Okapi::get_uuid(const std::string& username, int* id) const {
|
||||||
std::string service = url + OKAPI_username;
|
std::string service = url + OKAPI_username;
|
||||||
char* user_esc = curl_easy_escape(curl, username.c_str(), username.size());
|
char* user_esc = curl_easy_escape(curl, username.c_str(), username.size());
|
||||||
std::string query = "consumer_key=" + key + "&username=" + user_esc + "&fields=uuid";
|
std::string query = "consumer_key=" + key + "&username=" + user_esc + "&fields=uuid|internal_id";
|
||||||
curl_free(user_esc);
|
curl_free(user_esc);
|
||||||
curl_post(service, query);
|
curl_post(service, query);
|
||||||
json j = json::parse(curl_output);
|
json j = json::parse(curl_output);
|
||||||
|
if (id) *id = j["internal_id"];
|
||||||
return j["uuid"];
|
return j["uuid"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,3 +336,29 @@ std::string Okapi::get_changelog_json(int revision) const {
|
||||||
curl_post(service, query);
|
curl_post(service, query);
|
||||||
return curl_output;
|
return curl_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Okapi::get_ftf(int id, Caches& cc) const {
|
||||||
|
std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(id);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
|
||||||
|
curl_output.clear();
|
||||||
|
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
Debug(1) << "Connection failed: " << curl_easy_strerror(res) << '\n';
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug(5) << "FTF query result: " << curl_output;
|
||||||
|
json j = json::parse(curl_output);
|
||||||
|
for (auto& el : j.items()) {
|
||||||
|
if (el.value().is_null()) continue;
|
||||||
|
int id = std::stoi(el.value()["cache_id"].get<std::string>());
|
||||||
|
auto res = std::find_if(cc.begin(), cc.end(), [&](const auto& a) { return a.internal_id == id; });
|
||||||
|
if (res != std::end(cc))
|
||||||
|
res->ftf = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
3
okapi.h
3
okapi.h
|
@ -40,6 +40,7 @@ public:
|
||||||
|
|
||||||
void update_caches(Caches& cc) const;
|
void update_caches(Caches& cc) const;
|
||||||
void update_caches_ratings(Caches& cc) const;
|
void update_caches_ratings(Caches& cc) const;
|
||||||
std::string get_uuid(const std::string& username) const;
|
std::string get_uuid(const std::string& username, int* id = nullptr) const;
|
||||||
std::string get_profile_url(const std::string& uuid) const;
|
std::string get_profile_url(const std::string& uuid) const;
|
||||||
|
void get_ftf(int id, Caches& cc) const;
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue