kopia lustrzana https://gitlab.com/tomaszg/geostat
Merge branch 'master' of gitlab.com:tomaszg/geostat
commit
dcaa8fbf71
1
cache.h
1
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;
|
||||
|
|
35
geostat.cpp
35
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 << "<th>" << j << "</th>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
std::cout << "<th></th></tr>\n";
|
||||
|
||||
for (int i = 1; i <= 12; i++) { // i -> months in rows
|
||||
int m = 0;
|
||||
std::cout << "<tr><th>" << i << "</th> ";
|
||||
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 << "<td codes=\"" << codes << "\">" << count << "</td>";
|
||||
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 << "<th>" << perc << "%</th>";
|
||||
std::cout << "</tr>\n";
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
@ -820,9 +838,13 @@ int main(int argc, char** argv) {
|
|||
for (int j = 1; j <= 12; j++) { // print table month headers
|
||||
std::cout << "<th>" << j << "</th>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
std::cout << "<th></th></tr>\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 << "<tr><th>" << i + 1900 << "</th> ";
|
||||
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 << "<td codes=\"" << codes << "\">" << count << "</td>";
|
||||
n++;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
if (now_tm) {
|
||||
if (i == now_tm->tm_year)
|
||||
std::cout << "<th>" << m * 100.0 / (now_tm->tm_mon + 1) << "%</th>";
|
||||
else
|
||||
std::cout << "<th>" << m * 100.0 / 12 << "%</th>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
}
|
||||
std::cout << "</table>\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
|
||||
|
|
5
ocdb.cpp
5
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<Status>(sqlite3_column_int(stmt, 9));
|
||||
else c.status = unknown;
|
||||
if (sqlite3_column_text(stmt, 10)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 10));
|
||||
if (sqlite3_column_text(stmt, 11)) c.country = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 11));
|
||||
|
||||
cc.push_back(c);
|
||||
res = sqlite3_step(stmt);
|
||||
|
|
|
@ -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<std::string>& 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"];
|
||||
|
|
Ładowanie…
Reference in New Issue