Add stats based on recommendations

sql-rework
Tomasz Golinski 2020-01-25 16:12:29 +01:00
rodzic f5f19b3581
commit 5296e11a21
3 zmienionych plików z 59 dodań i 1 usunięć

Wyświetl plik

@ -3,6 +3,7 @@
#include <string>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <ctime>
@ -50,6 +51,8 @@ public:
std::string size;
float diff = 0;
float terr = 0;
int fav = 0;
int founds = 0;
std::string type;
std::string region;
std::string origin;
@ -84,5 +87,6 @@ public:
typedef std::set<Cache, CacheCmp> Caches;
typedef std::multimap<std::time_t, const Cache*> Date_Caches;
typedef std::vector<const Cache*> Sorted_Caches;
float cache_distance(const Cache& a, const Cache& b);

Wyświetl plik

@ -218,6 +218,8 @@ int main(int argc, char** argv) {
Date_Caches sorted_caches;
Date_Caches sorted_fcaches;
Date_Caches sorted_caches_by_hidden;
Sorted_Caches caches_by_fav;
Sorted_Caches caches_by_fav_perc;
Caches fcc;
std::tm tmp;
@ -231,7 +233,11 @@ int main(int argc, char** argv) {
}
tmp = i.date_hidden_tm;
sorted_caches_by_hidden.insert({ std::mktime(&tmp), &i });
caches_by_fav.push_back(&i);
caches_by_fav_perc.push_back(&i);
}
std::sort(caches_by_fav.begin(), caches_by_fav.end(), [&](const Cache* a, const Cache* b) { return a->fav > b->fav; });
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::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
std::cout << "<html>\n";
@ -430,6 +436,52 @@ int main(int argc, char** argv) {
}
std::cout << "</table>\n";
n = 1;
std::cout << "<h2>Caches with most recommendations</h2>\n";
std::cout << "<table class=\"list\">\n";
std::cout << "<tr class=\"list_head\"><td></td>";
std::cout << "<td>Cache</td>";
std::cout << "<td>Rec.</td>";
std::cout << "<td>Finds</td>";
std::cout << "<td>%</td>";
std::cout << "</tr>\n";
for (auto i : caches_by_fav) {
std::cout << "<tr><td class=\"list_head\">" << n << "</td> ";
std::cout << "<td>" << "<a href=\"" << i->link() << "\">" << i->name << " (" << i->code << ")</a>" << "</td>";
std::cout << "<td>" << i->fav << "</td>";
std::cout << "<td>" << i->founds << "</td>";
std::cout << "<td>" << std::setprecision(3) << 100.0 * i->fav / i->founds << "%</td>";
std::cout << "</tr>\n";
n++;
if (n > LIST_MAX) break;
}
std::cout << "</table>\n";
n = 1;
std::cout << "<h2>Caches with most recommendations (percentage)</h2>\n";
std::cout << "<table class=\"list\">\n";
std::cout << "<tr class=\"list_head\"><td></td>";
std::cout << "<td>Cache</td>";
std::cout << "<td>Rec.</td>";
std::cout << "<td>Finds</td>";
std::cout << "<td>%</td>";
std::cout << "</tr>\n";
for (auto i : caches_by_fav_perc) {
std::cout << "<tr><td class=\"list_head\">" << n << "</td> ";
std::cout << "<td>" << "<a href=\"" << i->link() << "\">" << i->name << " (" << i->code << ")</a>" << "</td>";
std::cout << "<td>" << i->fav << "</td>";
std::cout << "<td>" << i->founds << "</td>";
std::cout << "<td>" << std::setprecision(3) << 100.0 * i->fav / i->founds << "%</td>";
std::cout << "</tr>\n";
n++;
if (n > LIST_MAX) break;
}
std::cout << "</table>\n";
short y_min = std::min_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.date_hidden_tm.tm_year < b.date_hidden_tm.tm_year; })->date_hidden_tm.tm_year;
short y_max = std::max_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.date_hidden_tm.tm_year < b.date_hidden_tm.tm_year; })->date_hidden_tm.tm_year;

Wyświetl plik

@ -75,7 +75,7 @@ std::string Okapi::get_user_caches_json(std::string uuid, int count, int offset)
std::string Okapi::get_caches_json(std::string codes) {
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_hidden";
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|size2|date_hidden|recommendations|founds";
return curl_post(service, query);
}
@ -136,6 +136,8 @@ Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
c.owner_uuid = el.value()["owner"]["uuid"];
c.pos = get_lat_lon(el.value()["location"]);
c.origin = "OC.pl";
c.fav = el.value()["recommendations"];
c.founds = el.value()["founds"];
std::tm tmp;
std::stringstream ss(el.value()["date_hidden"].get<std::string>());