master
Tomasz Golinski 2023-09-25 18:49:30 +02:00
rodzic 816c94049a
commit 48e43613d1
11 zmienionych plików z 53 dodań i 54 usunięć

Wyświetl plik

@ -45,11 +45,15 @@ uint find_streak(const Date_Caches& cc, std::time_t& start);
uint get_num(char c, char* opt); uint get_num(char c, char* opt);
template <typename T> void average_html(const Caches& cc, T Cache::*ptr, const std::string& caption); template <typename T>
template <typename T> float average(const Caches& cc, T Cache::*ptr); void average_html(const Caches& cc, T Cache::*ptr, const std::string& caption);
template <typename T>
float average(const Caches& cc, T Cache::*ptr);
template <typename T> void sum_html(const Caches& cc, T Cache::*ptr, const std::string& caption); template <typename T>
template <typename T> T sum(const Caches& cc, T Cache::*ptr); void sum_html(const Caches& cc, T Cache::*ptr, const std::string& caption);
template <typename T>
T sum(const Caches& cc, T Cache::*ptr);
int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test); int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test);

Wyświetl plik

@ -12,9 +12,9 @@ Debug::Debug(int n) : lvl(n) {
if (lvl > 1) indent.append("*** "); if (lvl > 1) indent.append("*** ");
buffer << indent; buffer << indent;
// std::time_t now = std::time(nullptr); // std::time_t now = std::time(nullptr);
// std::string dt = std::ctime(&now); // std::string dt = std::ctime(&now);
// std::cout << dt << " "; // std::cout << dt << " ";
} }
} }

Wyświetl plik

@ -12,7 +12,6 @@ void show_usage() {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
if (argc < 3) show_usage(); if (argc < 3) show_usage();
User user1, user2; User user1, user2;
@ -22,7 +21,7 @@ int main(int argc, char** argv) {
user2.use_oc = true; user2.use_oc = true;
user1.get_caches(); user1.get_caches();
user2.get_caches(); user2.get_caches();
int cc_no1 = user1.caches_hidden; int cc_no1 = user1.caches_hidden;
int cc_no2 = user2.caches_hidden; int cc_no2 = user2.caches_hidden;
@ -56,7 +55,7 @@ int main(int argc, char** argv) {
std::cout << "</div>\n"; std::cout << "</div>\n";
// const int LIST_MAX = 100; // const int LIST_MAX = 100;
short int n = 1; short int n = 1;
if (cc_no1 > 0) { if (cc_no1 > 0) {
@ -82,7 +81,7 @@ int main(int argc, char** argv) {
std::cout << "<td>" << i->region << "</td>"; std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n"; std::cout << "</tr>\n";
n++; n++;
// if (n > LIST_MAX) break; // if (n > LIST_MAX) break;
} }
std::cout << "</table>\n"; std::cout << "</table>\n";
} }
@ -111,7 +110,7 @@ int main(int argc, char** argv) {
std::cout << "<td>" << i->region << "</td>"; std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n"; std::cout << "</tr>\n";
n++; n++;
// if (n > LIST_MAX) break; // if (n > LIST_MAX) break;
} }
} }
std::cout << "</table>\n"; std::cout << "</table>\n";

Wyświetl plik

@ -13,7 +13,6 @@ void show_usage() {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
#include "config_user.h" #include "config_user.h"
if (argc == 1) show_usage(); if (argc == 1) show_usage();
@ -104,4 +103,3 @@ int main(int argc, char** argv) {
footer_html(); footer_html();
} }

Wyświetl plik

@ -49,7 +49,6 @@ int main(int argc, char** argv) {
if (argc == 1) show_usage(); if (argc == 1) show_usage();
int o; int o;
while ((o = getopt(argc, argv, "qNOQD:o::p:d:u:n:r:k:i:f:H:s:m:etah?")) != -1) while ((o = getopt(argc, argv, "qNOQD:o::p:d:u:n:r:k:i:f:H:s:m:etah?")) != -1)
switch (o) { switch (o) {
@ -303,8 +302,8 @@ int main(int argc, char** argv) {
show_histogram(user.cc, &Cache::owner, "Cache owners", 1); show_histogram(user.cc, &Cache::owner, "Cache owners", 1);
show_histogram(user.cc, &Cache::type, "Cache types", 1); show_histogram(user.cc, &Cache::type, "Cache types", 1);
show_histogram(user.cc, &Cache::size, "Cache sizes", 1); show_histogram(user.cc, &Cache::size, "Cache sizes", 1);
// show_histogram(fcc, &Cache::region, "Regions", 1); // show_histogram(fcc, &Cache::region, "Regions", 1);
// show_histogram(fcc, &Cache::subregion, "Subregions", 1); // show_histogram(fcc, &Cache::subregion, "Subregions", 1);
show_histogram(user.fcc, &Cache::country, "Countries", 1); show_histogram(user.fcc, &Cache::country, "Countries", 1);
show_nested_histogram(user.fcc, &Cache::region, &Cache::subregion, "Regions", 1); show_nested_histogram(user.fcc, &Cache::region, &Cache::subregion, "Regions", 1);
show_histogram(user.cc, &Cache::day_of_week, "Days of the week", 1, 0); show_histogram(user.cc, &Cache::day_of_week, "Days of the week", 1, 0);
@ -527,7 +526,7 @@ int main(int argc, char** argv) {
} }
std::cout << "</table>\n"; std::cout << "</table>\n";
// D/T matrix // D/T matrix
n = 0; n = 0;
std::cout << "<h2>Difficulty / terrain matrix</h2>\n"; std::cout << "<h2>Difficulty / terrain matrix</h2>\n";
@ -559,7 +558,7 @@ int main(int argc, char** argv) {
std::cout << "Average terrain: <span class=\"value\">" << average(user.cc, &Cache::terr) << "</span><br>\n"; std::cout << "Average terrain: <span class=\"value\">" << average(user.cc, &Cache::terr) << "</span><br>\n";
std::cout << "</div>\n"; std::cout << "</div>\n";
// Days matrix // Days matrix
n = 0; n = 0;
std::cout << "<h2>Caching days matrix</h2>\n"; std::cout << "<h2>Caching days matrix</h2>\n";
@ -609,7 +608,7 @@ int main(int argc, char** argv) {
std::cout << "Total <span class=\"value\">" << n << "</span> days out of 366 (" << std::setprecision(3) << n / 3.66 << "%).\n"; std::cout << "Total <span class=\"value\">" << n << "</span> days out of 366 (" << std::setprecision(3) << n / 3.66 << "%).\n";
std::cout << "</div>\n"; std::cout << "</div>\n";
// Hidden months matrix // Hidden months matrix
n = 0; n = 0;
y_min = std::min_element(user.cc.begin(), user.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; y_min = std::min_element(user.cc.begin(), user.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;
@ -697,20 +696,20 @@ int main(int argc, char** argv) {
std::cout << "<td>"; std::cout << "<td>";
std::cout << i->completed_perc << "% / " << i->treshold_perc << "%</td>"; std::cout << i->completed_perc << "% / " << i->treshold_perc << "%</td>";
std::cout << "<td>"; std::cout << "<td>";
if (!i->completed) if (!i->completed)
std::cout << i->needed; std::cout << i->needed;
std::cout << "</td>"; std::cout << "</td>";
std::cout << "<td>"; std::cout << "<td>";
if (i->active_caches_not_found && i->active_caches_not_found < UINT_MAX-1024) if (i->active_caches_not_found && i->active_caches_not_found < UINT_MAX - 1024)
std::cout << i->active_caches_not_found; std::cout << i->active_caches_not_found;
std::cout << "</td>"; std::cout << "</td>";
std::cout << "</tr>\n"; std::cout << "</tr>\n";
n++; n++;
// if (n > LIST_MAX) break; // if (n > LIST_MAX) break;
} }
std::cout << "</table>\n"; std::cout << "</table>\n";
// show_histogram(tt, "Power trails (completion percentage)", 1); // show_histogram(tt, "Power trails (completion percentage)", 1);
std::cout << "<div class=\"basic_stats\">\n"; std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Number of completed power trails: <span class=\"value\">" << std::count_if(user.tt.begin(), user.tt.end(), [&](const auto& a) { return a->completed; }) << "</span><br>\n"; std::cout << "Number of completed power trails: <span class=\"value\">" << std::count_if(user.tt.begin(), user.tt.end(), [&](const auto& a) { return a->completed; }) << "</span><br>\n";
std::cout << "Number of started power trails: <span class=\"value\">" << user.tt.size() << "</span><br>\n"; std::cout << "Number of started power trails: <span class=\"value\">" << user.tt.size() << "</span><br>\n";
@ -737,7 +736,7 @@ int main(int argc, char** argv) {
std::cout << "<td>" << i->founds << "</td>"; std::cout << "<td>" << i->founds << "</td>";
std::cout << "</tr>\n"; std::cout << "</tr>\n";
n++; n++;
// if (n > LIST_MAX) break; // if (n > LIST_MAX) break;
} }
std::cout << "</table>\n"; std::cout << "</table>\n";
std::cout << "<div class=\"basic_stats\">\n"; std::cout << "<div class=\"basic_stats\">\n";

Wyświetl plik

@ -65,12 +65,12 @@ int main(int argc, char** argv) {
int o; int o;
while ((o = getopt(argc, argv, "qNOg:o::p:d:u:n:r:k:MDCH:s:m:etaLTYh?")) != -1) while ((o = getopt(argc, argv, "qNOg:o::p:d:u:n:r:k:MDCH:s:m:etaLTYh?")) != -1)
switch (o) { switch (o) {
// case 'd': // case 'd':
// Debug::set_debug_level(get_num('d',optarg)); // Debug::set_debug_level(get_num('d',optarg));
// break; // break;
// case 'g': // case 'g':
// gpx_file = optarg; // gpx_file = optarg;
break; break;
case 'o': case 'o':
user.use_oc = 1; user.use_oc = 1;
if (optarg) { if (optarg) {
@ -112,9 +112,9 @@ int main(int argc, char** argv) {
case 'M': case 'M':
show_minmax = 1; show_minmax = 1;
break; break;
// case 'D': // case 'D':
// show_dist = 1; // show_dist = 1;
// break; // break;
case 'C': case 'C':
show_calendar = 1; show_calendar = 1;
break; break;
@ -224,7 +224,7 @@ int main(int argc, char** argv) {
// if (show_dist) { // if (show_dist) {
// auto far = *std::max_element(user.fcc.begin(), user.fcc.end(), [&](const Cache* a, const Cache* b) { return a->distance() < b->distance(); }); // auto far = *std::max_element(user.fcc.begin(), user.fcc.end(), [&](const Cache* a, const Cache* b) { return a->distance() < b->distance(); });
// auto near = *std::min_element(user.fcc.begin(), user.fcc.end(), [&](const Cache* a, const Cache* b) { return a->distance() < b->distance(); }); // auto near = *std::min_element(user.fcc.begin(), user.fcc.end(), [&](const Cache* a, const Cache* b) { return a->distance() < b->distance(); });
// //
// std::cout << "Nearest cache: " << near->distance() << " km\n"; // std::cout << "Nearest cache: " << near->distance() << " km\n";
// near->show(); // near->show();
// std::cout << "Furthest cache: " << far->distance() << " km\n"; // std::cout << "Furthest cache: " << far->distance() << " km\n";

Wyświetl plik

@ -289,15 +289,15 @@ void Okapi::update_caches(Caches& cc) const {
// void Okapi::update_caches_ratings(Caches& cc) const { // void Okapi::update_caches_ratings(Caches& cc) const {
// std::map<std::string, Cache*> pcc; // std::map<std::string, Cache*> pcc;
// std::string code; // std::string code;
// //
// uint k; // uint k;
// std::string codes_list; // std::string codes_list;
// codes_list.reserve(MAX_CACHES * 8); // maximum of MAX_CACHES codes, 7 chars per code plus a separator // codes_list.reserve(MAX_CACHES * 8); // maximum of MAX_CACHES codes, 7 chars per code plus a separator
// //
// auto it = cc.begin(); // auto it = cc.begin();
// while (it != cc.end()) { // while (it != cc.end()) {
// k = 0; // k = 0;
// //
// while (it != cc.end() && k < MAX_CACHES) { // while (it != cc.end() && k < MAX_CACHES) {
// codes_list += it->code; // codes_list += it->code;
// codes_list += '|'; // codes_list += '|';
@ -306,16 +306,16 @@ void Okapi::update_caches(Caches& cc) const {
// k++; // k++;
// } // }
// codes_list.pop_back(); // remove trailing '|' // codes_list.pop_back(); // remove trailing '|'
// //
// get_caches_ratings_json(codes_list); // get_caches_ratings_json(codes_list);
// json j = json::parse(curl_output); // json j = json::parse(curl_output);
// codes_list.clear(); // codes_list.clear();
// //
// for (auto& el : j.items()) { // for (auto& el : j.items()) {
// code = el.value()["code"]; // code = el.value()["code"];
// pcc[code]->fav = el.value()["recommendations"]; // pcc[code]->fav = el.value()["recommendations"];
// if (!el.value()["rating"].is_null()) pcc[code]->rating = el.value()["rating"]; // if (!el.value()["rating"].is_null()) pcc[code]->rating = el.value()["rating"];
// //
// if (el.value()["status"] == "Available") // if (el.value()["status"] == "Available")
// pcc[code]->status = ok; // pcc[code]->status = ok;
// else if (el.value()["status"] == "Temporarily unavailable") // else if (el.value()["status"] == "Temporarily unavailable")

Wyświetl plik

@ -53,7 +53,7 @@ public:
std::string get_changelog_json(int revision) const; std::string get_changelog_json(int revision) const;
void update_caches(Caches& cc) const; void update_caches(Caches& cc) const;
// void update_caches_ratings(Caches& cc) const; // void update_caches_ratings(Caches& cc) const;
std::string get_uuid(const std::string& username, uint* id = nullptr) const; std::string get_uuid(const std::string& username, uint* id = nullptr) const;
std::string get_profile_url(const std::string& uuid) const; std::string get_profile_url(const std::string& uuid) const;
void get_ftf(uint uid, Caches& cc) const; void get_ftf(uint uid, Caches& cc) const;

Wyświetl plik

@ -12,7 +12,7 @@ using json = nlohmann::json;
// } // }
int main() { int main() {
// Debug::set_debug_level(5); // Debug::set_debug_level(5);
PowertrailDB T; PowertrailDB T;
for (int i = 1; i < 2000; i++) for (int i = 1; i < 2000; i++)

Wyświetl plik

@ -5,7 +5,6 @@
#include "debug.h" #include "debug.h"
void User::get_caches() { void User::get_caches() {
if (use_oc) { if (use_oc) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) { if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
Okapi OCpl(ocpl); Okapi OCpl(ocpl);
@ -29,7 +28,7 @@ void User::get_caches() {
} }
for (const auto& i : tt_map) { for (const auto& i : tt_map) {
i.second->completed_perc = (100 * i.second->found / i.second->caches.size()); i.second->completed_perc = (100 * i.second->found / i.second->caches.size());
if (i.second->found >= i.second->treshold ) if (i.second->found >= i.second->treshold)
i.second->completed = 1; i.second->completed = 1;
else else
i.second->needed = i.second->treshold - i.second->found; i.second->needed = i.second->treshold - i.second->found;
@ -80,11 +79,11 @@ void User::get_caches() {
} }
} }
// if (!gpx_file.empty()) { // if (!gpx_file.empty()) {
// GPX gpxfile(gpx_file); // GPX gpxfile(gpx_file);
// Caches tmp = gpxfile.get_user_caches(); // Caches tmp = gpxfile.get_user_caches();
// std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); // std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
// } // }
if (use_ocdb) { if (use_ocdb) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) { if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
@ -122,7 +121,7 @@ void User::get_caches() {
Okapi OCde(ocde); Okapi OCde(ocde);
OCde.update_caches(tmp); OCde.update_caches(tmp);
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc)); std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
// region_count = db.get_region_stats(); // region_count = db.get_region_stats();
} else if (get_owned) { } else if (get_owned) {
Caches tmp = db.get_user_caches_owned(ocde_user_uuid); Caches tmp = db.get_user_caches_owned(ocde_user_uuid);
Okapi OCde(ocde); Okapi OCde(ocde);

2
user.h
Wyświetl plik

@ -36,7 +36,7 @@ public:
std::string ocnl_user; std::string ocnl_user;
std::string ocro_user; std::string ocro_user;
std::string ocuk_user; std::string ocuk_user;
// std::string gpx_file; // std::string gpx_file;
bool get_not_found = 0; bool get_not_found = 0;
bool get_owned = 0; bool get_owned = 0;