Don't compute unnecessary things when looking for caches not found

sql-rework
Tomasz Golinski 2020-02-17 00:37:03 +01:00
rodzic add05af439
commit bada68f34c
1 zmienionych plików z 40 dodań i 24 usunięć

Wyświetl plik

@ -163,6 +163,16 @@ int main(int argc, char** argv) {
Caches cc;
if (get_not_found) {
use_oc = 0;
use_ocpl_db = 1;
trail = 0;
if (ocpl_user_uuid.empty() && ocpl_user.empty()) {
std::cout << "Option \"-N\" works only with OCpl\n";
std::exit(EXIT_FAILURE);
}
}
if (use_oc) {
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
Okapi OCpl(ocpl_url, ocpl_key);
@ -209,8 +219,8 @@ int main(int argc, char** argv) {
if (use_ocpl_db) {
OCdb db(Database);
Okapi OCpl(ocpl_url, ocpl_key);
if (!ocpl_user.empty()) {
Okapi OCpl(ocpl_url, ocpl_key);
ocpl_user_uuid = OCpl.get_uuid(ocpl_user);
}
if (get_not_found) {
@ -239,23 +249,31 @@ int main(int argc, char** argv) {
Caches fcc;
std::tm tmp;
for (auto& i : cc) {
dates[i.date]++;
tmp = i.date_tm;
sorted_caches.insert({ std::mktime(&tmp), &i });
if (i.type != "Moving" && i.type != "Own" && (!get_not_found || !exclude_quiz || i.type != "Quiz")) {
sorted_fcaches.insert({ std::mktime(&tmp), &i });
fcc.insert(i);
if (!get_not_found) {
for (auto& i : cc) {
dates[i.date]++;
tmp = i.date_tm;
sorted_caches.insert({ std::mktime(&tmp), &i });
if (i.type != "Moving" && i.type != "Own" && (!get_not_found || !exclude_quiz || i.type != "Quiz")) {
sorted_fcaches.insert({ std::mktime(&tmp), &i });
fcc.insert(i);
}
tmp = i.date_hidden_tm;
sorted_caches_by_hidden.insert({ std::mktime(&tmp), &i });
caches_by_fav.push_back(&i);
caches_by_fav_perc.push_back(&i);
caches_by_finds.push_back(&i);
}
std::sort(caches_by_fav.begin(), caches_by_fav.end(), [&](const Cache* a, const Cache* b) { return a->fav > b->fav; });
std::sort(caches_by_fav_perc.begin(), caches_by_fav_perc.end(), [&](const Cache* a, const Cache* b) { return 1.0 * a->fav / a->founds > 1.0 * b->fav / b-> founds; });
std::sort(caches_by_finds.begin(), caches_by_finds.end(), [&](const Cache* a, const Cache* b) { return a->founds > b->founds; });
} else {
for (auto& i : cc) {
if (i.type != "Moving" && i.type != "Own" && (!get_not_found || !exclude_quiz || i.type != "Quiz")) {
fcc.insert(i);
}
}
tmp = i.date_hidden_tm;
sorted_caches_by_hidden.insert({ std::mktime(&tmp), &i });
caches_by_fav.push_back(&i);
caches_by_fav_perc.push_back(&i);
caches_by_finds.push_back(&i);
}
std::sort(caches_by_fav.begin(), caches_by_fav.end(), [&](const Cache* a, const Cache* b) { return a->fav > b->fav; });
std::sort(caches_by_fav_perc.begin(), caches_by_fav_perc.end(), [&](const Cache* a, const Cache* b) { return 1.0 * a->fav / a->founds > 1.0 * b->fav / b-> founds; });
std::sort(caches_by_finds.begin(), caches_by_finds.end(), [&](const Cache* a, const Cache* b) { return a->founds > b->founds; });
std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
std::cout << "<html>\n";
@ -324,15 +342,7 @@ int main(int argc, char** argv) {
if (sorted_fcaches.size() > 1)
std::cout << "Average distance between caches: <span class=\"value\">" << tot_dist / (sorted_fcaches.size() - 1) << "</span> km<br>\n";
std::cout << "</div>\n";
}
if (get_not_found) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Still <span class=\"value\">" << cc.size() << "</span> caches to be found...<br>\n";
std::cout << "</div>\n";
}
if (!get_not_found) {
auto N = std::max_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lat < b.pos.lat; });
auto S = std::min_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lat < b.pos.lat; });
auto E = std::max_element(fcc.begin(), fcc.end(), [&](const Cache& a, const Cache& b) { return a.pos.lon < b.pos.lon; });
@ -625,6 +635,12 @@ int main(int argc, char** argv) {
} // end of main if
if (get_not_found) {
std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Still <span class=\"value\">" << cc.size() << "</span> caches to be found...<br>\n";
std::cout << "</div>\n";
}
std::cout << "<div id=\"footer\">\n";
std::cout << "Stats generated by <a href=\"https://gitlab.com/tomaszg/geostat\">GeoStat</a>.<br>\n";
std::cout << "Data obtained from Opencaching sites via <a href=\"https://github.com/opencaching/okapi/\">OKAPI</a>:<br>\n";