kopia lustrzana https://gitlab.com/tomaszg/geostat
Porównaj commity
3 Commity
868b62bb2e
...
48f92e64d8
Autor | SHA1 | Data |
---|---|---|
Tomasz Golinski | 48f92e64d8 | |
Tomasz Golinski | 2e08a99d20 | |
Tomasz Golinski | 2a2a77caf3 |
|
@ -172,11 +172,11 @@ void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::str
|
|||
if (own.first.empty()) own.first = "[unknown]";
|
||||
if (i < HIST_MAX) {
|
||||
std::map<std::string, int> subhistogram;
|
||||
std::vector<std::pair<std::string, int>> subpairs;
|
||||
for (auto el : fcc)
|
||||
if (el->*ptr == own.first && !(el->*ptr2).empty()) //TODO problem with [unknown]
|
||||
subhistogram[el->*ptr2]++;
|
||||
if (!subhistogram.empty()) {
|
||||
std::vector<std::pair<std::string, int>> subpairs;
|
||||
std::cout << "<details class=\"nested\"><summary class=\"bar\" style=\"--percent: " << 100 * own.second / max << "%;\"><span class=\"text\">" << own.first << ": " << own.second << "</span></summary>\n";
|
||||
std::copy(subhistogram.begin(), subhistogram.end(), std::back_inserter(subpairs));
|
||||
if (sort_by_val)
|
||||
|
|
|
@ -722,7 +722,7 @@ int main(int argc, char** argv) {
|
|||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Date found</th>";
|
||||
std::cout << "<th>Finds</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
|
@ -733,7 +733,7 @@ int main(int argc, char** argv) {
|
|||
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->date << "</td>";
|
||||
std::cout << "<td>" << i->founds << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
|
|
16
ocdb.cpp
16
ocdb.cpp
|
@ -12,7 +12,7 @@ using json = nlohmann::json;
|
|||
// using namespace std::literals::string_literals;
|
||||
|
||||
OCdb::OCdb(const Service service) {
|
||||
int res = 0;
|
||||
int res;
|
||||
|
||||
switch (service) {
|
||||
case ocpl:
|
||||
|
@ -271,19 +271,19 @@ bool OCdb::update_log(const json& j) {
|
|||
return 1;
|
||||
|
||||
sql = "INSERT INTO logs (uuid,";
|
||||
for (auto& i : fields)
|
||||
for (const auto& i : fields)
|
||||
sql += i.first + ',';
|
||||
for (auto& i : fields2)
|
||||
for (const auto& i : fields2)
|
||||
sql += i.first + ',';
|
||||
sql.pop_back();
|
||||
sql += ") VALUES ('" + uuid + "',";
|
||||
for (__attribute__((unused)) auto& i : fields)
|
||||
for (__attribute__((unused)) const auto& i : fields)
|
||||
sql += "?,";
|
||||
for (__attribute__((unused)) auto& i : fields2)
|
||||
for (__attribute__((unused)) const auto& i : fields2)
|
||||
sql += "?,";
|
||||
sql.pop_back();
|
||||
sql += ") ON CONFLICT(uuid) DO UPDATE SET ";
|
||||
for (auto& i : fields)
|
||||
for (const auto& i : fields)
|
||||
sql += i.first + "=excluded." + i.first + ',';
|
||||
sql.pop_back();
|
||||
sql += ';';
|
||||
|
@ -295,10 +295,10 @@ bool OCdb::update_log(const json& j) {
|
|||
return 0;
|
||||
}
|
||||
int n = 1;
|
||||
for (auto& i : fields) {
|
||||
for (const auto& i : fields) {
|
||||
sqlite3_bind_text(stmt, n++, i.second.c_str(), -1, nullptr);
|
||||
}
|
||||
for (auto& i : fields2) {
|
||||
for (const auto& i : fields2) {
|
||||
sqlite3_bind_int(stmt, n++, i.second);
|
||||
}
|
||||
res = sqlite3_step(stmt);
|
||||
|
|
22
okapi.cpp
22
okapi.cpp
|
@ -104,15 +104,15 @@ void Okapi::get_user_caches_json(const std::string& uuid, int count, int offset)
|
|||
|
||||
void Okapi::get_caches_json(const std::string& codes) const {
|
||||
std::string api_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|internal_id";
|
||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|country2|size2|date_hidden|date_created|recommendations|rating|founds|status|internal_id";
|
||||
curl_post(api_service, query);
|
||||
}
|
||||
|
||||
void Okapi::get_caches_ratings_json(const std::string& codes) const {
|
||||
std::string api_service = url + OKAPI_caches;
|
||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|recommendations|rating|status";
|
||||
curl_post(api_service, query);
|
||||
}
|
||||
// void Okapi::get_caches_ratings_json(const std::string& codes) const {
|
||||
// std::string api_service = url + OKAPI_caches;
|
||||
// std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|recommendations|rating|status";
|
||||
// curl_post(api_service, query);
|
||||
// }
|
||||
|
||||
// Cache Okapi::get_cache(std::string code) {
|
||||
// std::string output = get_cache_json(code);
|
||||
|
@ -193,7 +193,7 @@ Caches Okapi::get_caches(const std::set<std::string>& codes) const {
|
|||
c.status = unknown;
|
||||
|
||||
std::tm tmp;
|
||||
std::stringstream ss(el.value()["date_created"].get<std::string>());
|
||||
std::stringstream ss(std::max(el.value()["date_hidden"].get<std::string>(), el.value()["date_created"].get<std::string>()));
|
||||
ss >> std::get_time(&tmp, "%Y-%m-%dT%H:%M:%S+");
|
||||
tmp.tm_isdst = -1;
|
||||
c.set_date_hidden(tmp);
|
||||
|
@ -224,7 +224,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
|
|||
j = json::parse(curl_output);
|
||||
|
||||
for (auto& el : j.items()) {
|
||||
if (el.value()["type"] == "Found it") {
|
||||
if (el.value()["type"] == "Found it" || el.value()["type"] == "Attended") {
|
||||
std::stringstream ss(el.value()["date"].get<std::string>());
|
||||
// TODO need to take care of the time zone :/
|
||||
ss >> std::get_time(&date, "%Y-%m-%dT%H:%M:%S+");
|
||||
|
@ -242,7 +242,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
|
|||
j = json::parse(curl_output);
|
||||
|
||||
for (auto& el : j.items()) {
|
||||
if (el.value()["type"] == "Found it") {
|
||||
if (el.value()["type"] == "Found it" || el.value()["type"] == "Attended") {
|
||||
std::stringstream ss(el.value()["date"].get<std::string>());
|
||||
ss >> std::get_time(&date, "%Y-%m-%dT%H-%M-%S");
|
||||
date.tm_isdst = -1;
|
||||
|
@ -355,10 +355,10 @@ std::string Okapi::get_changelog_json(int revision) const {
|
|||
}
|
||||
|
||||
void Okapi::get_ftf(uint uid, Caches& cc) const {
|
||||
std::string url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(uid);
|
||||
std::string ftf_url = "https://opencaching.pl/UserProfile/getUserFtfsAjax/" + std::to_string(uid);
|
||||
CURLcode res;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_URL, ftf_url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
|
||||
curl_output.clear();
|
||||
|
||||
|
|
4
okapi.h
4
okapi.h
|
@ -23,7 +23,7 @@ private:
|
|||
void get_user_caches_json(const std::string& uuid, int count = 0, int offset = 0) const;
|
||||
// std::string get_cache_json(std::string code) const;
|
||||
void get_caches_json(const std::string& codes) const;
|
||||
void get_caches_ratings_json(const std::string& codes) const;
|
||||
// void get_caches_ratings_json(const std::string& codes) const;
|
||||
|
||||
const static int MAX_LOGS = 1000;
|
||||
const static int MAX_CACHES = 500;
|
||||
|
@ -43,7 +43,7 @@ private:
|
|||
constexpr static auto ocuk_url = "https://opencache.uk/okapi/";
|
||||
|
||||
public:
|
||||
Okapi(const Service serv);
|
||||
explicit Okapi(const Service serv);
|
||||
~Okapi();
|
||||
|
||||
// Cache get_cache(std::string code);
|
||||
|
|
|
@ -69,7 +69,7 @@ class Caches_in_Powertrails {
|
|||
public:
|
||||
std::unordered_map<std::string, int> data;
|
||||
|
||||
Caches_in_Powertrails(const PowertrailDB& db);
|
||||
explicit Caches_in_Powertrails(const PowertrailDB& db);
|
||||
Caches_in_Powertrails(){};
|
||||
|
||||
void read_from_json(std::string file);
|
||||
|
|
3
user.cpp
3
user.cpp
|
@ -188,6 +188,7 @@ void User::prepare_lists_of_caches() {
|
|||
std::sort(caches_by_fav_perc.begin(), caches_by_fav_perc.end(), [&](const Cache* a, const Cache* b) { return 1.0 * a->fav / a->founds > 1.0 * b->fav / b->founds; });
|
||||
std::sort(caches_by_finds.begin(), caches_by_finds.end(), [&](const Cache* a, const Cache* b) { return a->founds > b->founds; });
|
||||
// std::sort(caches_by_rating.begin(), caches_by_rating.end(), [&](const Cache* a, const Cache* b) { return a->rating > b->rating; });
|
||||
std::sort(caches_ftf.begin(), caches_ftf.end(), [&](const Cache* a, const Cache* b) { return a->date_t < b->date_t; });
|
||||
} else {
|
||||
for (auto& i : cc) {
|
||||
if (i.type != "Moving" && i.type != "Own" && (!exclude_quiz || i.type != "Quiz")) {
|
||||
|
@ -198,7 +199,7 @@ void User::prepare_lists_of_caches() {
|
|||
}
|
||||
}
|
||||
|
||||
void User::header() {
|
||||
void User::header() const {
|
||||
if (!ocpl_user.empty())
|
||||
std::cout << "<img alt=\"OCpl\" src=\"" << flag_pl << "\"> <a href=\"" << ocpl_user_profile << "\">" << ocpl_user << "</a><br>\n";
|
||||
if (!ocde_user.empty())
|
||||
|
|
2
user.h
2
user.h
|
@ -64,5 +64,5 @@ public:
|
|||
void get_caches();
|
||||
void prepare_lists_of_caches(); // Prepare sorted list of caches, excluding moving caches
|
||||
|
||||
void header();
|
||||
void header() const;
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue