diff --git a/cache.h b/cache.h
index f97fa83..73c9283 100644
--- a/cache.h
+++ b/cache.h
@@ -65,6 +65,7 @@ public:
float rating = 0;
bool recommended = 0; // was the cache recommended by that user?
std::string type;
+ std::string country;
std::string region;
std::string subregion;
std::string origin;
diff --git a/geostat.cpp b/geostat.cpp
index 5c9e002..e7da620 100644
--- a/geostat.cpp
+++ b/geostat.cpp
@@ -522,6 +522,7 @@ int main(int argc, char** argv) {
show_histogram(cc, &Cache::size, "Cache sizes", 1);
// show_histogram(fcc, &Cache::region, "Regions", 1);
// show_histogram(fcc, &Cache::subregion, "Subregions", 1);
+ show_histogram(fcc, &Cache::country, "Countries", 1);
show_nested_histogram(fcc, &Cache::region, &Cache::subregion, "Regions", 1);
show_histogram(cc, &Cache::day_of_week, "Days of the week", 1, 0);
show_histogram(cc, &Cache::mon, "Months", 1, 0);
@@ -784,9 +785,10 @@ int main(int argc, char** argv) {
for (int j = 1; j <= 31; j++) { // print table day headers
std::cout << "
" << j << " | ";
}
- std::cout << "\n";
+ std::cout << " | \n";
for (int i = 1; i <= 12; i++) { // i -> months in rows
+ int m = 0;
std::cout << "" << i << " | ";
for (int j = 1; j <= 31; j++) { // j -> days in cols
count = count_caches(cc, codes, [i, j](const Cache& c) -> bool { return (c.date_tm.tm_mon == i - 1 && c.date_tm.tm_mday == j); });
@@ -798,8 +800,24 @@ int main(int argc, char** argv) {
} else {
std::cout << "" << count << " | ";
n++;
+ m++;
}
}
+ float perc;
+ switch(i) {
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ perc = m * 100.0 / 30;
+ break;
+ case 2:
+ perc = m * 100.0 / 29;
+ break;
+ default:
+ perc = m * 100.0 / 31;
+ }
+ std::cout << "" << perc << "% | ";
std::cout << "
\n";
}
std::cout << "\n";
@@ -820,9 +838,13 @@ int main(int argc, char** argv) {
for (int j = 1; j <= 12; j++) { // print table month headers
std::cout << "" << j << " | ";
}
- std::cout << "\n";
+ std::cout << " | \n";
+
+ std::time_t now = std::time(nullptr);
+ std::tm* now_tm = std::localtime(&now);
for (int i = y_min; i <= y_max; i++) { // i -> years in rows
+ int m = 0;
std::cout << "" << i + 1900 << " | ";
for (int j = 1; j <= 12; j++) { // j -> months in cols
count = count_caches(cc, codes, [i, j](const Cache& c) -> bool { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); });
@@ -836,14 +858,19 @@ int main(int argc, char** argv) {
else {
std::cout << "" << count << " | ";
n++;
+ m++;
}
}
+ if (now_tm) {
+ if (i == now_tm->tm_year)
+ std::cout << "" << m * 100.0 / (now_tm->tm_mon + 1) << "% | ";
+ else
+ std::cout << "" << m * 100.0 / 12 << "% | ";
+ }
std::cout << "
\n";
}
std::cout << "\n";
- std::time_t now = std::time(nullptr);
- std::tm* now_tm = std::localtime(&now);
if (now_tm) {
if (!ocpl_user_uuid.empty() && ocde_user_uuid.empty()) {
int m_count = (now_tm->tm_year - 106 - 1) * 12 + 8 + now_tm->tm_mon + 1; // 106 corresponds to 2006, 8 is no. of months since may till dec, +1 since tm_mon starts at 0
diff --git a/ocdb.cpp b/ocdb.cpp
index b82daf7..7f9a1fa 100644
--- a/ocdb.cpp
+++ b/ocdb.cpp
@@ -360,7 +360,7 @@ Caches OCdb::get_user_caches(const std::string& uuid, __attribute__((unused)) in
int res;
//code TEXT PRIMARY KEY, name TEXT, location TEXT, type TEXT, status INTEGER, size TEXT, difficulty INTEGER, terrain INTEGER, country TEXT, region TEXT, owner TEXT)
- sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name FROM caches WHERE EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = ";
+ sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name, country FROM caches WHERE EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = ";
sql += std::to_string(found);
sql += " and user = ?);";
@@ -378,7 +378,7 @@ Caches OCdb::get_user_caches_owned(const std::string& uuid) const {
int res;
//code TEXT PRIMARY KEY, name TEXT, location TEXT, type TEXT, status TEXT, size TEXT, difficulty INTEGER, terrain INTEGER, country TEXT, region TEXT, owner TEXT)
- sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name FROM caches WHERE owner = ?;";
+ sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name, country FROM caches WHERE owner = ?;";
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
if (res != SQLITE_OK) {
@@ -409,6 +409,7 @@ Caches OCdb::parse_sql_caches() const {
if (sqlite3_column_text(stmt, 9)) c.status = static_cast(sqlite3_column_int(stmt, 9));
else c.status = unknown;
if (sqlite3_column_text(stmt, 10)) c.name = reinterpret_cast(sqlite3_column_text(stmt, 10));
+ if (sqlite3_column_text(stmt, 11)) c.country = reinterpret_cast(sqlite3_column_text(stmt, 11));
cc.push_back(c);
res = sqlite3_step(stmt);
diff --git a/okapi.cpp b/okapi.cpp
index 585efd2..1f2e8ce 100644
--- a/okapi.cpp
+++ b/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 {
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|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";
curl_post(service, query);
}
@@ -157,6 +157,7 @@ Caches Okapi::get_caches(const std::set& codes) const {
c.type = el.value()["type"];
c.size = el.value()["size2"];
c.region = el.value()["region"];
+ c.country = el.value()["country2"];
c.diff = el.value()["difficulty"];
c.terr = el.value()["terrain"];
c.owner = el.value()["owner"]["username"];