kopia lustrzana https://gitlab.com/tomaszg/geostat
cppcheck partial cleanup
rodzic
89e9b4d8c6
commit
d673bdd7b9
|
@ -309,7 +309,7 @@ int main(int argc, char** argv) {
|
|||
"zachodniopomorskie" });
|
||||
|
||||
// Prepare sorted list of caches, excluding moving caches
|
||||
std::map<std::string, int> dates;
|
||||
// std::map<std::string, int> dates;
|
||||
Date_Caches sorted_caches;
|
||||
pCaches fcc;
|
||||
|
||||
|
@ -317,7 +317,7 @@ int main(int argc, char** argv) {
|
|||
for (auto& i : cc) {
|
||||
poland.locate(i);
|
||||
|
||||
dates[i.date]++;
|
||||
// dates[i.date]++;
|
||||
if (i.type != "Moving" && i.type != "Own") {
|
||||
sorted_caches.insert({ i.date_t, &i });
|
||||
fcc.push_back(&i);
|
||||
|
|
116
okapi.cpp
116
okapi.cpp
|
@ -80,9 +80,9 @@ void Okapi::curl_post(const std::string& url, const std::string& post) const {
|
|||
}
|
||||
|
||||
void Okapi::get_user_caches_json(const std::string& uuid, int count, int offset) const {
|
||||
std::string service = url + OKAPI_logs;
|
||||
std::string api_service = url + OKAPI_logs;
|
||||
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=cache_code|type|date|was_recommended&limit=" + std::to_string(count) + "&offset=" + std::to_string(offset);
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
}
|
||||
|
||||
// std::string Okapi::get_cache_json(std::string code) {
|
||||
|
@ -92,15 +92,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 service = url + OKAPI_caches;
|
||||
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";
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
}
|
||||
|
||||
void Okapi::get_caches_ratings_json(const std::string& codes) const {
|
||||
std::string service = url + OKAPI_caches;
|
||||
std::string api_service = url + OKAPI_caches;
|
||||
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|recommendations|rating|status";
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
}
|
||||
|
||||
// Cache Okapi::get_cache(std::string code) {
|
||||
|
@ -255,9 +255,9 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
|
|||
}
|
||||
|
||||
int Okapi::get_user_caches_no(const std::string& uuid) const {
|
||||
std::string service = url + OKAPI_user;
|
||||
std::string api_service = url + OKAPI_user;
|
||||
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=caches_hidden";
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
json j = json::parse(curl_output);
|
||||
return j["caches_hidden"];
|
||||
}
|
||||
|
@ -269,71 +269,71 @@ void Okapi::update_caches(Caches& cc) const {
|
|||
cc = get_caches(codes);
|
||||
}
|
||||
|
||||
void Okapi::update_caches_ratings(Caches& cc) const {
|
||||
std::map<std::string, Cache*> pcc;
|
||||
std::string code;
|
||||
|
||||
uint k;
|
||||
std::string codes_list;
|
||||
codes_list.reserve(MAX_CACHES * 8); // maximum of MAX_CACHES codes, 7 chars per code plus a separator
|
||||
|
||||
auto it = cc.begin();
|
||||
while (it != cc.end()) {
|
||||
k = 0;
|
||||
|
||||
while (it != cc.end() && k < MAX_CACHES) {
|
||||
codes_list += it->code;
|
||||
codes_list += '|';
|
||||
pcc[it->code] = &*it;
|
||||
it++;
|
||||
k++;
|
||||
}
|
||||
codes_list.pop_back(); // remove trailing '|'
|
||||
|
||||
get_caches_ratings_json(codes_list);
|
||||
json j = json::parse(curl_output);
|
||||
codes_list.clear();
|
||||
|
||||
for (auto& el : j.items()) {
|
||||
code = el.value()["code"];
|
||||
pcc[code]->fav = el.value()["recommendations"];
|
||||
if (!el.value()["rating"].is_null()) pcc[code]->rating = el.value()["rating"];
|
||||
|
||||
if (el.value()["status"] == "Available")
|
||||
pcc[code]->status = ok;
|
||||
else if (el.value()["status"] == "Temporarily unavailable")
|
||||
pcc[code]->status = disabled;
|
||||
else if (el.value()["status"] == "Archived")
|
||||
pcc[code]->status = archived;
|
||||
else
|
||||
pcc[code]->status = unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
// void Okapi::update_caches_ratings(Caches& cc) const {
|
||||
// std::map<std::string, Cache*> pcc;
|
||||
// std::string code;
|
||||
//
|
||||
// uint k;
|
||||
// std::string codes_list;
|
||||
// codes_list.reserve(MAX_CACHES * 8); // maximum of MAX_CACHES codes, 7 chars per code plus a separator
|
||||
//
|
||||
// auto it = cc.begin();
|
||||
// while (it != cc.end()) {
|
||||
// k = 0;
|
||||
//
|
||||
// while (it != cc.end() && k < MAX_CACHES) {
|
||||
// codes_list += it->code;
|
||||
// codes_list += '|';
|
||||
// pcc[it->code] = &*it;
|
||||
// it++;
|
||||
// k++;
|
||||
// }
|
||||
// codes_list.pop_back(); // remove trailing '|'
|
||||
//
|
||||
// get_caches_ratings_json(codes_list);
|
||||
// json j = json::parse(curl_output);
|
||||
// codes_list.clear();
|
||||
//
|
||||
// for (auto& el : j.items()) {
|
||||
// code = el.value()["code"];
|
||||
// pcc[code]->fav = el.value()["recommendations"];
|
||||
// if (!el.value()["rating"].is_null()) pcc[code]->rating = el.value()["rating"];
|
||||
//
|
||||
// if (el.value()["status"] == "Available")
|
||||
// pcc[code]->status = ok;
|
||||
// else if (el.value()["status"] == "Temporarily unavailable")
|
||||
// pcc[code]->status = disabled;
|
||||
// else if (el.value()["status"] == "Archived")
|
||||
// pcc[code]->status = archived;
|
||||
// else
|
||||
// pcc[code]->status = unknown;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
std::string Okapi::get_uuid(const std::string& username, uint* id) const {
|
||||
std::string service = url + OKAPI_username;
|
||||
std::string api_service = url + OKAPI_username;
|
||||
char* user_esc = curl_easy_escape(curl, username.c_str(), username.size());
|
||||
std::string query = "consumer_key=" + key + "&username=" + user_esc + "&fields=uuid|internal_id";
|
||||
curl_free(user_esc);
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
json j = json::parse(curl_output);
|
||||
if (id) *id = j["internal_id"];
|
||||
return j["uuid"];
|
||||
}
|
||||
|
||||
std::string Okapi::get_profile_url(const std::string& uuid) const {
|
||||
std::string service = url + OKAPI_user;
|
||||
std::string api_service = url + OKAPI_user;
|
||||
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=profile_url";
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
json j = json::parse(curl_output);
|
||||
return j["profile_url"];
|
||||
}
|
||||
|
||||
std::string Okapi::get_changelog_json(int revision) const {
|
||||
std::string service = url + OKAPI_changelog;
|
||||
std::string api_service = url + OKAPI_changelog;
|
||||
std::string query = "consumer_key=" + key + "&since=" + std::to_string(revision);
|
||||
curl_post(service, query);
|
||||
curl_post(api_service, query);
|
||||
return curl_output;
|
||||
}
|
||||
|
||||
|
@ -357,8 +357,8 @@ void Okapi::get_ftf(uint uid, Caches& cc) const {
|
|||
for (auto& el : j.items()) {
|
||||
if (el.value().is_null()) continue;
|
||||
uint 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;
|
||||
auto c = std::find_if(cc.begin(), cc.end(), [&](const auto& a) { return a.internal_id == id; });
|
||||
if (c != std::end(cc))
|
||||
c->ftf = 1;
|
||||
}
|
||||
}
|
||||
|
|
2
okapi.h
2
okapi.h
|
@ -39,7 +39,7 @@ public:
|
|||
std::string get_changelog_json(int revision) 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, uint* id = nullptr) const;
|
||||
std::string get_profile_url(const std::string& uuid) const;
|
||||
void get_ftf(uint uid, Caches& cc) const;
|
||||
|
|
12
region.cpp
12
region.cpp
|
@ -39,17 +39,17 @@ std::map<std::string, ContourData*> Region::parse_geojson(const std::string& jso
|
|||
std::ifstream file(json_file);
|
||||
json j;
|
||||
file >> j;
|
||||
std::string name;
|
||||
std::string reg_name;
|
||||
|
||||
std::map<std::string, ContourData*> rr;
|
||||
|
||||
for (auto& el : j["features"].items()) {
|
||||
if (el.value()["properties"]["alltags"].count("short_name") > 0)
|
||||
name = el.value()["properties"]["alltags"]["short_name"];
|
||||
reg_name = el.value()["properties"]["alltags"]["short_name"];
|
||||
else if (el.value()["properties"].count("localname") > 0)
|
||||
name = el.value()["properties"]["localname"];
|
||||
reg_name = el.value()["properties"]["localname"];
|
||||
else if (el.value()["properties"].count("name") > 0)
|
||||
name = el.value()["properties"]["name"];
|
||||
reg_name = el.value()["properties"]["name"];
|
||||
else {
|
||||
Debug(1) << "Unknown name for an object, skipping";
|
||||
continue;
|
||||
|
@ -58,8 +58,8 @@ std::map<std::string, ContourData*> Region::parse_geojson(const std::string& jso
|
|||
for (auto& el2 : el.value()["geometry"]["coordinates"][0][0].items()) {
|
||||
cont->add_point(Position(el2.value()[1], el2.value()[0]));
|
||||
}
|
||||
Debug(3) << "Parsed region " << name;
|
||||
rr[name] = cont;
|
||||
Debug(3) << "Parsed region " << reg_name;
|
||||
rr[reg_name] = cont;
|
||||
}
|
||||
return rr;
|
||||
}
|
||||
|
|
2
region.h
2
region.h
|
@ -40,7 +40,7 @@ private:
|
|||
std::string name;
|
||||
std::vector<Region*> subregions;
|
||||
|
||||
std::map<std::string, ContourData*> parse_geojson(const std::string& json_file);
|
||||
static std::map<std::string, ContourData*> parse_geojson(const std::string& json_file);
|
||||
|
||||
public:
|
||||
Region(ContourData* contour, const std::string& name) : contour(contour), name(name) {}
|
||||
|
|
Ładowanie…
Reference in New Issue