Porównaj commity

...

4 Commity

Autor SHA1 Wiadomość Data
Tomasz Golinski 4efce13974 Merge remote-tracking branch 'origin/master' 2023-12-24 23:40:36 +01:00
Tomasz Golinski 26d3bc56d2 Trivial cppcheck fixes 2023-12-24 23:38:55 +01:00
Tomasz Golinski 48e43613d1 clang-format 2023-09-25 19:01:46 +02:00
Tomasz Golinski 816c94049a Add some constexpr to some functions 2023-09-25 18:35:05 +02:00
13 zmienionych plików z 78 dodań i 76 usunięć

Wyświetl plik

@ -5,11 +5,6 @@
#include <algorithm>
#include <numeric>
#include <iterator>
#include <cmath>
float degtorad(float x) {
return x * M_PI / 180;
}
void htmlencode(std::string& data) {
std::string tmp;
@ -41,7 +36,7 @@ void htmlencode(std::string& data) {
data.swap(tmp);
}
static std::string string_mangle(const std::string& str) {
constexpr static std::string string_mangle(const std::string& str) {
std::string tmp;
tmp.reserve(str.size());
@ -71,7 +66,7 @@ void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string
std::map<std::string, int> histogram;
for (auto el : cc)
for (const auto& el : cc)
histogram[el.*ptr]++;
show_histogram(histogram, caption, html, sort_by_val);
@ -351,7 +346,7 @@ void footer_html() {
Position Cache::home;
Position::Position(std::string loc) {
Position::Position(const std::string& loc) {
int pos = loc.find("|");
lat = stof(loc.substr(0, pos));
lon = stof(loc.substr(pos + 1));

Wyświetl plik

@ -1,13 +1,11 @@
#pragma once
// #include "cache.h"
// #include "powertrail.h"
#include <functional>
#include <string>
#include <map>
#include <vector>
#include <ctime>
#include <cmath>
class Cache;
@ -47,11 +45,15 @@ uint find_streak(const Date_Caches& cc, std::time_t& start);
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> float average(const Caches& cc, T Cache::*ptr);
template <typename T>
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> T sum(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>
T sum(const Caches& cc, T Cache::*ptr);
int count_caches(const Caches& cc, std::string& codes, std::function<bool(const Cache& c)> test);
@ -65,10 +67,11 @@ public:
Position() = default;
Position(float y, float x) : lat(y), lon(x) {}
explicit Position(std::string loc);
explicit Position(const std::string& loc);
};
float cache_distance(const Cache& a, const Cache& b);
float degtorad(float x);
constexpr float degtorad(float x) {
return x * M_PI / 180;
}

Wyświetl plik

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

Wyświetl plik

@ -12,7 +12,6 @@ void show_usage() {
}
int main(int argc, char** argv) {
if (argc < 3) show_usage();
User user1, user2;
@ -22,7 +21,7 @@ int main(int argc, char** argv) {
user2.use_oc = true;
user1.get_caches();
user2.get_caches();
int cc_no1 = user1.caches_hidden;
int cc_no2 = user2.caches_hidden;
@ -49,7 +48,7 @@ int main(int argc, char** argv) {
std::cout << "<div class=\"users\">\n";
std::cout << "<div class=\"user\">\n";
// const int LIST_MAX = 100;
// const int LIST_MAX = 100;
short int n = 1;
std::cout << "<h2>Caches created by " << user1.ocpl_user << " found by " << user2.ocpl_user << "</h2>\n";
@ -79,7 +78,7 @@ int main(int argc, char** argv) {
std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break;
// if (n > LIST_MAX) break;
}
std::cout << "</table>\n";
}
@ -114,7 +113,7 @@ int main(int argc, char** argv) {
std::cout << "<td>" << i->region << "</td>";
std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break;
// if (n > LIST_MAX) break;
}
}
std::cout << "</table>\n";

Wyświetl plik

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

Wyświetl plik

@ -49,7 +49,6 @@ int main(int argc, char** argv) {
if (argc == 1) show_usage();
int o;
while ((o = getopt(argc, argv, "qNOQD:o::p:d:u:n:r:k:i:f:H:s:m:etah?")) != -1)
switch (o) {
@ -245,7 +244,7 @@ int main(int argc, char** argv) {
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(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); }));
max = std::max(max, std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); }));
if (max > 0) {
std::cout << "<h2>Caching timeline</h2>\n";
@ -259,7 +258,7 @@ int main(int argc, char** argv) {
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(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); });
count = std::count_if(user.cc.begin(), user.cc.end(), [i, j](const 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";
@ -281,7 +280,7 @@ int main(int argc, char** argv) {
std::cout << "<tr><th>" << i + 1900 << "</th> ";
for (int j = 1; j <= 12; j++) { // j -> months in cols
std::map<int, int> days_count;
for (auto el : user.cc) {
for (const auto& el : user.cc) {
if (el.date_tm.tm_mon == j - 1 && el.date_tm.tm_year == i)
days_count[el.date_tm.tm_mday]++;
}
@ -303,8 +302,8 @@ int main(int argc, char** argv) {
show_histogram(user.cc, &Cache::owner, "Cache owners", 1);
show_histogram(user.cc, &Cache::type, "Cache types", 1);
show_histogram(user.cc, &Cache::size, "Cache sizes", 1);
// show_histogram(fcc, &Cache::region, "Regions", 1);
// show_histogram(fcc, &Cache::subregion, "Subregions", 1);
// show_histogram(fcc, &Cache::region, "Regions", 1);
// show_histogram(fcc, &Cache::subregion, "Subregions", 1);
show_histogram(user.fcc, &Cache::country, "Countries", 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);
@ -527,7 +526,7 @@ int main(int argc, char** argv) {
}
std::cout << "</table>\n";
// D/T matrix
// D/T matrix
n = 0;
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 << "</div>\n";
// Days matrix
// Days matrix
n = 0;
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 << "</div>\n";
// Hidden months matrix
// Hidden months matrix
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;
@ -697,20 +696,20 @@ int main(int argc, char** argv) {
std::cout << "<td>";
std::cout << i->completed_perc << "% / " << i->treshold_perc << "%</td>";
std::cout << "<td>";
if (!i->completed)
std::cout << i->needed;
if (!i->completed)
std::cout << i->needed;
std::cout << "</td>";
std::cout << "<td>";
if (i->active_caches_not_found && i->active_caches_not_found < UINT_MAX-1024)
std::cout << i->active_caches_not_found;
if (i->active_caches_not_found && i->active_caches_not_found < UINT_MAX - 1024)
std::cout << i->active_caches_not_found;
std::cout << "</td>";
std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break;
// if (n > LIST_MAX) break;
}
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 << "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";
@ -737,7 +736,7 @@ int main(int argc, char** argv) {
std::cout << "<td>" << i->founds << "</td>";
std::cout << "</tr>\n";
n++;
// if (n > LIST_MAX) break;
// if (n > LIST_MAX) break;
}
std::cout << "</table>\n";
std::cout << "<div class=\"basic_stats\">\n";
@ -780,7 +779,7 @@ int main(int argc, char** argv) {
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(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); }));
max = std::max(max, std::count_if(user.cc.begin(), user.cc.end(), [i, j](const 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";
@ -793,7 +792,7 @@ int main(int argc, char** argv) {
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(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.date_hidden_tm.tm_year == i && c.date_hidden_tm.tm_mon == j - 1); });
count = std::count_if(user.cc.begin(), user.cc.end(), [i, j](const 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";

Wyświetl plik

@ -65,12 +65,12 @@ int main(int argc, char** argv) {
int o;
while ((o = getopt(argc, argv, "qNOg:o::p:d:u:n:r:k:MDCH:s:m:etaLTYh?")) != -1)
switch (o) {
// case 'd':
// Debug::set_debug_level(get_num('d',optarg));
// break;
// case 'g':
// gpx_file = optarg;
break;
// case 'd':
// Debug::set_debug_level(get_num('d',optarg));
// break;
// case 'g':
// gpx_file = optarg;
break;
case 'o':
user.use_oc = 1;
if (optarg) {
@ -112,9 +112,9 @@ int main(int argc, char** argv) {
case 'M':
show_minmax = 1;
break;
// case 'D':
// show_dist = 1;
// break;
// case 'D':
// show_dist = 1;
// break;
case 'C':
show_calendar = 1;
break;
@ -224,7 +224,7 @@ int main(int argc, char** argv) {
// 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 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";
// near->show();
// std::cout << "Furthest cache: " << far->distance() << " km\n";
@ -260,7 +260,7 @@ int main(int argc, char** argv) {
for (int i = 2; i <= 10; i++) { // i -> diff in rows
std::cout << std::setw(5) << i / 2.0;
for (int j = 2; j <= 10; j++) { // j -> terr in cols
dt_table[i][j] = std::count_if(user.cc.begin(), user.cc.end(), [i, j](Cache c) { return (c.diff == i / 2.0 && c.terr == j / 2.0); });
dt_table[i][j] = std::count_if(user.cc.begin(), user.cc.end(), [i, j](const Cache& c) { return (c.diff == i / 2.0 && c.terr == j / 2.0); });
std::cout << std::setw(5) << dt_table[i][j];
}
std::cout << '\n';
@ -268,7 +268,7 @@ int main(int argc, char** argv) {
}
} else {
if (show_list) {
for (auto el : user.cc)
for (const auto& el : user.cc)
el.show();
}
}

Wyświetl plik

@ -485,7 +485,7 @@ std::map<std::string, int> OCdb::get_region_stats() {
throw 0;
}
for (auto reg : regions) {
for (const auto& reg : regions) {
sqlite3_bind_text(stmt, 1, reg.c_str(), -1, nullptr);
res = sqlite3_step(stmt);
if (res != SQLITE_ROW) {

Wyświetl plik

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

Wyświetl plik

@ -53,7 +53,7 @@ public:
std::string get_changelog_json(int revision) 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_profile_url(const std::string& uuid) const;
void get_ftf(uint uid, Caches& cc) const;

Wyświetl plik

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

Wyświetl plik

@ -5,7 +5,6 @@
#include "debug.h"
void User::get_caches() {
if (use_oc) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
Okapi OCpl(ocpl);
@ -29,7 +28,7 @@ void User::get_caches() {
}
for (const auto& i : tt_map) {
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;
else
i.second->needed = i.second->treshold - i.second->found;
@ -80,11 +79,11 @@ void User::get_caches() {
}
}
// if (!gpx_file.empty()) {
// GPX gpxfile(gpx_file);
// Caches tmp = gpxfile.get_user_caches();
// std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
// }
// if (!gpx_file.empty()) {
// GPX gpxfile(gpx_file);
// Caches tmp = gpxfile.get_user_caches();
// std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
// }
if (use_ocdb) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
@ -122,7 +121,7 @@ void User::get_caches() {
Okapi OCde(ocde);
OCde.update_caches(tmp);
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) {
Caches tmp = db.get_user_caches_owned(ocde_user_uuid);
Okapi OCde(ocde);
@ -213,3 +212,10 @@ void User::header() const {
if (!ocuk_user.empty())
std::cout << "<img alt=\"OCuk\" src=\"" << flag_uk << "\"> <a href=\"" << ocuk_user_profile << "\">" << ocuk_user << "</a><br>\n";
}
std::string User::user_link(std::string name) const {
if (!ocpl_user_uuid.empty())
return "<a href=\"/cgi-bin/geofr-form.pl?nick_pl1=" + ocpl_user + "&nick_pl2=" + name + "\">" + name + "</a>";
else
return name;
}

4
user.h
Wyświetl plik

@ -36,7 +36,7 @@ public:
std::string ocnl_user;
std::string ocro_user;
std::string ocuk_user;
// std::string gpx_file;
// std::string gpx_file;
bool get_not_found = 0;
bool get_owned = 0;
@ -65,4 +65,6 @@ public:
void prepare_lists_of_caches(); // Prepare sorted list of caches, excluding moving caches
void header() const;
std::string user_link(std::string name) const;
};