kopia lustrzana https://gitlab.com/tomaszg/geostat
Replace trails histogram with a table and add some convenience functions to powertrail.h
rodzic
68813370b0
commit
91d250cb3a
26
common.cpp
26
common.cpp
|
@ -72,18 +72,18 @@ void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string
|
|||
show_histogram(histogram, caption, html, sort_by_val);
|
||||
}
|
||||
|
||||
void show_histogram(const pPowertrails& tt, const std::string& caption, bool html, bool sort_by_val) {
|
||||
if (tt.empty()) return;
|
||||
|
||||
std::map<std::string, int> histogram;
|
||||
|
||||
for (auto el : tt) {
|
||||
std::string link = "<a href=\"https://opencaching.pl/powerTrail.php?ptAction=showSerie&ptrail=" + std::to_string(el.second->number) + "\">" + el.second->name + "</a>";
|
||||
histogram[link] = 100 * el.second->found / el.second->caches.size();
|
||||
}
|
||||
|
||||
show_histogram(histogram, caption, html, sort_by_val);
|
||||
}
|
||||
// void show_histogram(const pPowertrails& tt, const std::string& caption, bool html, bool sort_by_val) {
|
||||
// if (tt.empty()) return;
|
||||
//
|
||||
// std::map<std::string, int> histogram;
|
||||
//
|
||||
// for (auto el : tt) {
|
||||
// std::string link = "<a href=\"https://opencaching.pl/powerTrail.php?ptAction=showSerie&ptrail=" + std::to_string(el.second->number) + "\">" + el.second->name + "</a>";
|
||||
// histogram[link] = 100 * el.second->found / el.second->caches.size();
|
||||
// }
|
||||
//
|
||||
// show_histogram(histogram, caption, html, sort_by_val);
|
||||
// }
|
||||
|
||||
void show_histogram(const std::map<std::string, int>& data, const std::string& caption, bool html, bool sort_by_val) {
|
||||
if (data.empty()) return;
|
||||
|
@ -324,7 +324,7 @@ void header_html() {
|
|||
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=14\">\n";
|
||||
std::cout << " <link rel=\"stylesheet\" type=\"text/css\" href=\"geo.css?ver=15\">\n";
|
||||
std::cout << " <title>Geocaching stats</title>\n";
|
||||
std::cout << "</head>\n";
|
||||
std::cout << "<body>\n";
|
||||
|
|
2
common.h
2
common.h
|
@ -10,7 +10,7 @@ void htmlencode(std::string& data);
|
|||
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
void show_histogram(const pCaches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
void show_histogram(const std::map<std::string, int>& data, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
void show_histogram(const pPowertrails& tt, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
// void show_histogram(const pPowertrails& tt, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
|
||||
uint find_streak(const Date_Caches& cc, std::time_t& start);
|
||||
|
|
4
geo.css
4
geo.css
|
@ -110,6 +110,10 @@ table.list {
|
|||
background-color: #f0f8ff;
|
||||
}
|
||||
|
||||
.list tr.highlight {
|
||||
background-color: #ffaaaa;
|
||||
}
|
||||
|
||||
.list th {
|
||||
background-color: #fff;
|
||||
font-weight: bold;
|
||||
|
|
40
geostat.cpp
40
geostat.cpp
|
@ -208,15 +208,20 @@ int main(int argc, char** argv) {
|
|||
t.read_from_json("powertrails.json");
|
||||
tc.read_from_json("caches_in_power.json");
|
||||
|
||||
std::unordered_map<int, const Powertrail*> tt_map; // Needed to deduplicate trails
|
||||
|
||||
for ( auto& c : tmp ) {
|
||||
if (tc.data.count(c.code) > 0) {
|
||||
c.trail = tc.data[c.code];
|
||||
t.data[c.trail].found++;
|
||||
if (t.data[c.trail].found >= t.data[c.trail].caches.size() * t.data[c.trail].treshold_perc / 100)
|
||||
t.data[c.trail].completed = 1;
|
||||
tt[c.trail] = &(t.data[c.trail]);
|
||||
tt_map[c.trail] = &(t.data[c.trail]);
|
||||
}
|
||||
}
|
||||
for (const auto& i : tt_map)
|
||||
tt.push_back(i.second);
|
||||
std::sort(tt.begin(), tt.end(), [&](const auto& a, const auto& b) { return 1.0 * a->found / a->caches.size() > 1.0 * b->found / b->caches.size(); });
|
||||
|
||||
OCpl.get_ftf(uid, tmp);
|
||||
|
||||
|
@ -909,9 +914,38 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
|
||||
show_histogram(tt, "Power trails (completion percentage)", 1);
|
||||
n = 1;
|
||||
|
||||
std::cout << "<h2>Power trails (by completion percentage)</h2>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Trail</th>";
|
||||
// std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Caches</th>";
|
||||
std::cout << "<th>Found</th>";
|
||||
std::cout << "<th>Treshold</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto& i : tt) {
|
||||
if (i->completed)
|
||||
std::cout << "<tr class=\"highlight\">";
|
||||
else
|
||||
std::cout << "<tr>";
|
||||
std::cout << "<th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
// std::cout << "<td>" << i->type << "</td>";
|
||||
std::cout << "<td>" << i->caches.size() << "</td>";
|
||||
std::cout << "<td>" << i->found << "</td>";
|
||||
std::cout << "<td>" << (100 * i->found / i->caches.size()) << "% / " << i->treshold_perc << "%</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
// show_histogram(tt, "Power trails (completion percentage)", 1);
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Number of completed power trails: <span class=\"value\">" << std::count_if(tt.begin(), tt.end(), [&](const auto& a) { return a.second->completed; }) << "</span><br>\n";
|
||||
std::cout << "Number of completed power trails: <span class=\"value\">" << std::count_if(tt.begin(), tt.end(), [&](const auto& a) { return a->completed; }) << "</span><br>\n";
|
||||
std::cout << "Number of started power trails: <span class=\"value\">" << tt.size() << "</span><br>\n";
|
||||
std::cout << "</div>\n";
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ src_fr = ['geofriends.cpp', 'okapi.cpp', 'cache.cpp', 'debug.cpp', 'common.cpp']
|
|||
src_lst = ['geolist.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']
|
||||
src_traildb = ['powertrail.cpp', 'debug.cpp', 'traildb.cpp']
|
||||
src_traildb = ['powertrail.cpp', 'debug.cpp', 'traildb.cpp', 'common.cpp']
|
||||
|
||||
executable('geostat', src, dependencies : [curl_dep, json_dep, magick_dep, sqlite_dep, boost_dep], link_args: link, install: true)
|
||||
executable('geofriends', src_fr, dependencies : [curl_dep, json_dep], install: true)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "powertrail.h"
|
||||
#include "debug.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <regex>
|
||||
#include <fstream>
|
||||
|
@ -27,6 +28,19 @@ void from_json(const json& j, Powertrail& item) {
|
|||
strptime(item.date_str.c_str(), "%d-%m-%Y", &item.date);
|
||||
}
|
||||
|
||||
std::string Powertrail::link() const {
|
||||
return "https://opencaching.pl/powerTrail.php?ptAction=showSerie&ptrail=" + std::to_string(number);
|
||||
}
|
||||
|
||||
std::string Powertrail::link_name() const {
|
||||
return "<a href=\"" + link() + "\">" + safe_name() + "</a>";
|
||||
}
|
||||
|
||||
std::string Powertrail::safe_name() const {
|
||||
std::string tmp = name;
|
||||
htmlencode(tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
PowertrailDB::PowertrailDB() {
|
||||
curl = curl_easy_init();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
|
||||
#include "cache.h"
|
||||
|
@ -21,6 +22,10 @@ public:
|
|||
|
||||
uint found = 0;
|
||||
bool completed = 0;
|
||||
|
||||
std::string link() const;
|
||||
std::string link_name() const;
|
||||
std::string safe_name() const;
|
||||
};
|
||||
|
||||
class PowertrailDB {
|
||||
|
@ -58,4 +63,4 @@ public:
|
|||
private:
|
||||
};
|
||||
|
||||
typedef std::unordered_map<int, const Powertrail*> pPowertrails;
|
||||
typedef std::vector<const Powertrail*> pPowertrails;
|
||||
|
|
Ładowanie…
Reference in New Issue