kopia lustrzana https://gitlab.com/tomaszg/geostat
Fix a problem when a cache had two "found" logs by the same user
Okapi produces an error if a cache code appers twice in a request. Simply replace a std::vector by std::map.sql-rework
rodzic
274138058f
commit
c59e01b556
27
okapi.cpp
27
okapi.cpp
|
@ -2,7 +2,6 @@
|
|||
#include "debug.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -118,27 +117,29 @@ std::string Okapi::get_caches_json(std::string codes) {
|
|||
// return c;
|
||||
// }
|
||||
|
||||
Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
|
||||
Caches Okapi::get_caches(std::map<std::string, std::tm> codes) {
|
||||
Cache c;
|
||||
Caches cc;
|
||||
|
||||
uint n = 0;
|
||||
uint k = 0;
|
||||
while (n < codes.size()) {
|
||||
std::string codes_list;
|
||||
codes_list.reserve(500 * 7);
|
||||
std::string codes_list;
|
||||
codes_list.reserve(500 * 7); // maximum of 500 codes, 6 chars per code plus a separator
|
||||
|
||||
auto it = codes.begin();
|
||||
while (it != codes.end()) {
|
||||
k = 0;
|
||||
|
||||
while (n < codes.size() && k < 500) {
|
||||
codes_list += codes.at(n).first;
|
||||
while (it != codes.end() && k < 500) {
|
||||
codes_list += it->first;
|
||||
codes_list += '|';
|
||||
n++;
|
||||
it++;
|
||||
k++;
|
||||
}
|
||||
codes_list.pop_back(); // remove trailing '|'
|
||||
|
||||
std::string output = get_caches_json(codes_list);
|
||||
json j = json::parse(output);
|
||||
codes_list.clear();
|
||||
|
||||
for (auto& el : j.items()) {
|
||||
c.code = el.value()["code"];
|
||||
|
@ -160,7 +161,7 @@ Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
|
|||
ss >> std::get_time(&tmp, "%Y-%m-%dT%H:%M:%S+");
|
||||
c.set_date_hidden(tmp);
|
||||
|
||||
//ugly way to handle date...
|
||||
//ugly way to handle date... might produce bad results if a cache appears twice in the list
|
||||
for (auto& el2 : codes) {
|
||||
if (el2.first == c.code) {
|
||||
c.set_date(el2.second);
|
||||
|
@ -175,7 +176,7 @@ Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
|
|||
|
||||
Caches Okapi::get_user_caches(std::string uuid, int count) {
|
||||
Caches cc;
|
||||
std::vector<std::pair<std::string, std::tm>> codes;
|
||||
std::map<std::string, std::tm> codes;
|
||||
json j;
|
||||
std::tm date;
|
||||
int off = 0;
|
||||
|
@ -190,7 +191,7 @@ Caches Okapi::get_user_caches(std::string uuid, int count) {
|
|||
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+");
|
||||
codes.push_back(std::pair(el.value()["cache_code"].get<std::string>(), date));
|
||||
codes[el.value()["cache_code"].get<std::string>()] = date;
|
||||
}
|
||||
}
|
||||
off += j.size();
|
||||
|
@ -205,7 +206,7 @@ Caches Okapi::get_user_caches(std::string uuid, int count) {
|
|||
if (el.value()["type"] == "Found it") {
|
||||
std::stringstream ss(el.value()["date"].get<std::string>());
|
||||
ss >> std::get_time(&date, "%Y-%m-%dT%H-%M-%S");
|
||||
codes.push_back(std::pair(el.value()["cache_code"].get<std::string>(), date));
|
||||
codes[el.value()["cache_code"].get<std::string>()] = date;
|
||||
}
|
||||
}
|
||||
off += j.size();
|
||||
|
|
4
okapi.h
4
okapi.h
|
@ -3,7 +3,7 @@
|
|||
#include "api.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
class Okapi : public Api {
|
||||
|
@ -23,7 +23,7 @@ public:
|
|||
Okapi(std::string server_url, std::string consumer_key);
|
||||
|
||||
// Cache get_cache(std::string code);
|
||||
Caches get_caches(std::vector<std::pair<std::string, std::tm>> codes);
|
||||
Caches get_caches(std::map<std::string, std::tm> codes);
|
||||
Caches get_user_caches(std::string uuid, int count = 0);
|
||||
std::string get_changelog_json(int revision);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue