kopia lustrzana https://gitlab.com/tomaszg/geostat
Compute more statistics for owned caches thanks to Okapi update call
rodzic
9215f6ace9
commit
2ef585d4a0
251
geostat.cpp
251
geostat.cpp
|
@ -242,6 +242,8 @@ int main(int argc, char** argv) {
|
|||
region_count = db.get_region_stats();
|
||||
} else if (get_owned) {
|
||||
Caches tmp = db.get_user_caches_owned(ocpl_user_uuid);
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
OCpl.update_caches(tmp);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
} else {
|
||||
Caches tmp = db.get_user_caches(ocpl_user_uuid, 0);
|
||||
|
@ -766,31 +768,32 @@ int main(int argc, char** argv) {
|
|||
std::cout << "Number of caches that are archived: <span class=\"value\">" << std::count_if(cc.begin(), cc.end(), [&](auto& a) { return a.status == archived; }) << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
|
||||
// std::cout << "<h2>Cache creation timeline</h2>\n";
|
||||
// std::cout << "<table class=\"calendar_tab\">\n";
|
||||
// std::cout << "<tr><th></th>";
|
||||
// for (int j = 1; j <= 12; j++) { // print table month headers
|
||||
// std::cout << "<th>" << j << "</th>";
|
||||
// }
|
||||
// std::cout << "</tr>\n";
|
||||
//
|
||||
// short y_min = std::min_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.date_tm.tm_year < b.date_tm.tm_year; })->date_tm.tm_year;
|
||||
// short y_max = std::max_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.date_tm.tm_year < b.date_tm.tm_year; })->date_tm.tm_year;
|
||||
//
|
||||
// long max = 0; // maximal value for histogram
|
||||
// for (int i = y_min; i <= y_max; i++)
|
||||
// for (int j = 1; j <= 12; j++)
|
||||
// max = std::max(max, std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); }));
|
||||
//
|
||||
// for (int i = y_min; i <= y_max; i++) { // i -> years in rows
|
||||
// std::cout << "<tr><th>" << i + 1900 << "</th> ";
|
||||
// for (int j = 1; j <= 12; j++) { // j -> months in cols
|
||||
// count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); });
|
||||
// std::cout << "<td style=\"--percent: " << count * 100 / max << "%\"><span>" << count << "</span></td>";
|
||||
// }
|
||||
// std::cout << "</tr>\n";
|
||||
// }
|
||||
// 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;
|
||||
|
||||
long max = 0; // maximal value for histogram
|
||||
for (int i = y_min; i <= y_max; i++)
|
||||
for (int j = 1; j <= 12; j++)
|
||||
max = std::max(max, std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); }));
|
||||
|
||||
if (max > 0) {
|
||||
std::cout << "<h2>Cache creation timeline</h2>\n";
|
||||
std::cout << "<table class=\"calendar_tab\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
for (int j = 1; j <= 12; j++) { // print table month headers
|
||||
std::cout << "<th>" << j << "</th>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
for (int i = y_min; i <= y_max; i++) { // i -> years in rows
|
||||
std::cout << "<tr><th>" << i + 1900 << "</th> ";
|
||||
for (int j = 1; j <= 12; j++) { // j -> months in cols
|
||||
count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); });
|
||||
std::cout << "<td style=\"--percent: " << count * 100 / max << "%\"><span>" << count << "</span></td>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
}
|
||||
|
||||
// auto far = std::max_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.distance() < b.distance(); });
|
||||
// auto near = std::min_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.distance() < b.distance(); });
|
||||
|
@ -822,106 +825,106 @@ int main(int argc, char** argv) {
|
|||
std::cout << "</tr>\n";
|
||||
std::cout << "</table>\n";
|
||||
|
||||
// const int LIST_MAX = 15;
|
||||
// n = 1;
|
||||
const int LIST_MAX = 15;
|
||||
n = 1;
|
||||
|
||||
// std::cout << "<h2>Caches with most recommendations</h2>\n";
|
||||
// std::cout << "<table class=\"list\">\n";
|
||||
// std::cout << "<tr><th></th>";
|
||||
// std::cout << "<th>Cache</th>";
|
||||
// std::cout << "<th>Type</th>";
|
||||
// std::cout << "<th>Rec.</th>";
|
||||
// std::cout << "<th>Finds</th>";
|
||||
// std::cout << "<th>%</th>";
|
||||
// std::cout << "</tr>\n";
|
||||
//
|
||||
// for (auto i : caches_by_fav) {
|
||||
// std::cout << "<tr><th>" << n << "</th> ";
|
||||
// std::cout << "<td>" << i->link_name() << "</td>";
|
||||
// std::cout << "<td>" << i->type << "</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";
|
||||
//
|
||||
// average_html(cc, &Cache::fav, "number of recommendations");
|
||||
//
|
||||
// n = 1;
|
||||
//
|
||||
// std::cout << "<h2>Caches with most recommendations (percentage)</h2>\n";
|
||||
// std::cout << "<table class=\"list\">\n";
|
||||
// std::cout << "<tr><th></th>";
|
||||
// std::cout << "<th>Cache</th>";
|
||||
// std::cout << "<th>Type</th>";
|
||||
// std::cout << "<th>Rec.</th>";
|
||||
// std::cout << "<th>Finds</th>";
|
||||
// std::cout << "<th>%</th>";
|
||||
// std::cout << "</tr>\n";
|
||||
//
|
||||
// for (auto i : caches_by_fav_perc) {
|
||||
// std::cout << "<tr><th>" << n << "</th> ";
|
||||
// std::cout << "<td>" << i->link_name() << "</td>";
|
||||
// std::cout << "<td>" << i->type << "</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 finds</h2>\n";
|
||||
// std::cout << "<table class=\"list\">\n";
|
||||
// std::cout << "<tr><th></th>";
|
||||
// std::cout << "<th>Cache</th>";
|
||||
// std::cout << "<th>Type</th>";
|
||||
// std::cout << "<th>Date hidden</th>";
|
||||
// std::cout << "<th>Finds</th>";
|
||||
// std::cout << "</tr>\n";
|
||||
//
|
||||
// for (auto i : caches_by_finds) {
|
||||
// std::cout << "<tr><th>" << n << "</th> ";
|
||||
// std::cout << "<td>" << i->link_name() << "</td>";
|
||||
// std::cout << "<td>" << i->type << "</td>";
|
||||
// std::cout << "<td>" << i->date_hidden << "</td>";
|
||||
// std::cout << "<td>" << i->founds << "</td>";
|
||||
// std::cout << "</tr>\n";
|
||||
// n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
// }
|
||||
// std::cout << "</table>\n";
|
||||
//
|
||||
// average_html(cc, &Cache::founds, "number of finds");
|
||||
//
|
||||
// n = 1;
|
||||
//
|
||||
// std::cout << "<h2>Caches with least finds</h2>\n";
|
||||
// std::cout << "<table class=\"list\">\n";
|
||||
// std::cout << "<tr><th></th>";
|
||||
// std::cout << "<th>Cache</th>";
|
||||
// std::cout << "<th>Type</th>";
|
||||
// std::cout << "<th>Date hidden</th>";
|
||||
// std::cout << "<th>Finds</th>";
|
||||
// std::cout << "</tr>\n";
|
||||
//
|
||||
// for (auto i = caches_by_finds.rbegin(); i != caches_by_finds.rend(); i++) {
|
||||
// std::cout << "<tr><th>" << n << "</th> ";
|
||||
// std::cout << "<td>" << (*i)->link_name() << "</td>";
|
||||
// std::cout << "<td>" << (*i)->type << "</td>";
|
||||
// std::cout << "<td>" << (*i)->date_hidden << "</td>";
|
||||
// std::cout << "<td>" << (*i)->founds << "</td>";
|
||||
// std::cout << "</tr>\n";
|
||||
// n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
// }
|
||||
// std::cout << "</table>\n";
|
||||
std::cout << "<h2>Caches with most recommendations</h2>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Rec.</th>";
|
||||
std::cout << "<th>Finds</th>";
|
||||
std::cout << "<th>%</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto i : caches_by_fav) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</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";
|
||||
|
||||
average_html(cc, &Cache::fav, "number of recommendations");
|
||||
|
||||
n = 1;
|
||||
|
||||
std::cout << "<h2>Caches with most recommendations (percentage)</h2>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Rec.</th>";
|
||||
std::cout << "<th>Finds</th>";
|
||||
std::cout << "<th>%</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto i : caches_by_fav_perc) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</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 finds</h2>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Finds</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto i : caches_by_finds) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</td>";
|
||||
std::cout << "<td>" << i->date_hidden << "</td>";
|
||||
std::cout << "<td>" << i->founds << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
if (n > LIST_MAX) break;
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
average_html(cc, &Cache::founds, "number of finds");
|
||||
|
||||
n = 1;
|
||||
|
||||
std::cout << "<h2>Caches with least finds</h2>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Finds</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto i = caches_by_finds.rbegin(); i != caches_by_finds.rend(); i++) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << (*i)->link_name() << "</td>";
|
||||
std::cout << "<td>" << (*i)->type << "</td>";
|
||||
std::cout << "<td>" << (*i)->date_hidden << "</td>";
|
||||
std::cout << "<td>" << (*i)->founds << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
if (n > LIST_MAX) break;
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
// D/T matrix
|
||||
n = 0;
|
||||
|
|
Ładowanie…
Reference in New Issue