kopia lustrzana https://gitlab.com/tomaszg/geostat
Add geofriends tool to compute stats related to interaction of two given users
rodzic
6cb9b771f8
commit
ea4be4b4fe
|
@ -0,0 +1,121 @@
|
|||
#include "okapi.h"
|
||||
#include "cache.h"
|
||||
#include "debug.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <unistd.h>
|
||||
|
||||
void show_usage() {
|
||||
std::cout << "Usage: geofriends [options] nick1 nick2\n";
|
||||
std::cout << "Generate HTML stats for user caching intersection from Opencaching data.\n\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string ocpl_url = "https://opencaching.pl/okapi/";
|
||||
|
||||
#include "config_user.h"
|
||||
|
||||
if (argc < 3) show_usage();
|
||||
|
||||
std::string ocpl_user1 = argv[1];
|
||||
std::string ocpl_user2 = argv[2];
|
||||
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
std::string ocpl_user_uuid1 = OCpl.get_uuid(ocpl_user1);
|
||||
std::string ocpl_user_profile1 = OCpl.get_profile_url(ocpl_user_uuid1);
|
||||
std::string ocpl_user_uuid2 = OCpl.get_uuid(ocpl_user2);
|
||||
std::string ocpl_user_profile2 = OCpl.get_profile_url(ocpl_user_uuid2);
|
||||
Caches cc1 = OCpl.get_user_caches(ocpl_user_uuid1, 0);
|
||||
Caches cc2 = OCpl.get_user_caches(ocpl_user_uuid2, 0);
|
||||
|
||||
|
||||
pCaches caches_by_user1;
|
||||
pCaches caches_by_user2;
|
||||
|
||||
for (auto& i : cc2) {
|
||||
if (i.owner_uuid == ocpl_user_uuid1)
|
||||
caches_by_user1.push_back(&i);
|
||||
}
|
||||
|
||||
for (auto& i : cc1) {
|
||||
if (i.owner_uuid == ocpl_user_uuid2)
|
||||
caches_by_user2.push_back(&i);
|
||||
}
|
||||
|
||||
std::cout << "<!DOCTYPE html>\n";
|
||||
std::cout << "<html lang=\"en\">\n";
|
||||
std::cout << " <head>\n";
|
||||
std::cout << " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
|
||||
std::cout << " <link rel=\"stylesheet\" type=\"text/css\" href=\"geo.css?ver=12\">\n";
|
||||
std::cout << " <title>Geocaching stats</title>\n";
|
||||
std::cout << "</head>\n";
|
||||
std::cout << "<body>\n";
|
||||
std::cout << "<header>\n";
|
||||
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
|
||||
std::cout << "<img alt=\"OCpl\" src=\"https://wiki.opencaching.eu/images/b/b7/Oc-pl.png\"> <a href=\"" << ocpl_user_profile1 << "\">" << ocpl_user1 << "</a><br>\n";
|
||||
std::cout << "<img alt=\"OCpl\" src=\"https://wiki.opencaching.eu/images/b/b7/Oc-pl.png\"> <a href=\"" << ocpl_user_profile2 << "\">" << ocpl_user2 << "</a><br>\n";
|
||||
std::cout << "</header>\n";
|
||||
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Number of caches created by " << ocpl_user1 << " found by " << ocpl_user2 <<": <span class=\"value\">" << caches_by_user1.size() << "</span><br>\n";
|
||||
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(cc2.begin(), cc2.end(), [ocpl_user_uuid1](auto& c) { return (c.recommended && c.owner_uuid == ocpl_user_uuid1); }) << "</span><br>\n";;
|
||||
std::cout << "Number of caches created by " << ocpl_user2 << " found by " << ocpl_user1 <<": <span class=\"value\">" << caches_by_user2.size() << "</span><br>\n";
|
||||
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(cc1.begin(), cc1.end(), [ocpl_user_uuid2](auto& c) { return (c.recommended && c.owner_uuid == ocpl_user_uuid2); }) << "</span><br>\n";;
|
||||
std::cout << "</div>\n";
|
||||
|
||||
// const int LIST_MAX = 100;
|
||||
short int n = 1;
|
||||
|
||||
std::cout << "<h2>Caches created by " << ocpl_user1 << " found by " << ocpl_user2 <<"</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>Date found</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto& i : caches_by_user1) {
|
||||
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->date << "</td>";
|
||||
std::cout << "<td>" << i->region << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
n = 1;
|
||||
std::cout << "<h2>Caches created by " << ocpl_user2 << " found by " << ocpl_user1 <<"</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>Date found</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto& i : caches_by_user2) {
|
||||
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->date << "</td>";
|
||||
std::cout << "<td>" << i->region << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
footer_html();
|
||||
}
|
|
@ -15,10 +15,12 @@ endif
|
|||
|
||||
link = ['-lheatmap']
|
||||
src = ['geostat.cpp', 'okapi.cpp', 'cache.cpp', 'debug.cpp', 'heat.cpp', 'ocdb.cpp', 'common.cpp', 'region.cpp']
|
||||
src_fr = ['geofriends.cpp', 'okapi.cpp', 'cache.cpp', 'debug.cpp', 'common.cpp']
|
||||
src_cli = ['geostat_cli.cpp', 'okapi.cpp', 'gpx.cpp', 'cache.cpp', 'debug.cpp', 'heat.cpp', 'ocdb.cpp', 'common.cpp', 'region.cpp']
|
||||
src_db = ['geodb.cpp', 'debug.cpp', 'ocdb.cpp', 'okapi.cpp', 'cache.cpp', 'common.cpp']
|
||||
|
||||
executable('geostat', src, dependencies : [curl_dep, json_dep, magick_dep, sqlite_dep], link_args: link, install: true)
|
||||
executable('geofriends', src_fr, dependencies : [curl_dep, json_dep], install: true)
|
||||
executable('geostat_cli', src_cli, dependencies : [curl_dep, json_dep, magick_dep, sqlite_dep, gpx_dep], link_args: link, install: true)
|
||||
executable('geodb', src_db, dependencies : [sqlite_dep, json_dep, curl_dep], install: true)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue