Add option to limit time for computed statistics

sql-rework
Tomasz Golinski 2020-02-23 02:26:23 +01:00
rodzic f28ca37ee1
commit 2be5e5b143
1 zmienionych plików z 27 dodań i 11 usunięć

Wyświetl plik

@ -24,6 +24,8 @@ void show_usage() {
std::cout << "\t-k user\t\tuser for opencaching.uk\n";
std::cout << "\t-g file\t\tuse specified gpx file\n";
std::cout << "\t-q\t\tuse local SQLite file with dump of OC database\n";
std::cout << "\t-i timestamp\t\tstart date\n";
std::cout << "\t-f timestamp\t\tfinish date\n";
std::cout << " * Output:\n";
std::cout << "\t-N\t\tcompute stats only for unfound caches (works only with SQLite)\n";
std::cout << "\t-Q\t\texclude quiz caches from unfound caches\n";
@ -46,6 +48,8 @@ int main(int argc, char** argv) {
bool use_ocpl_db = 0;
bool get_not_found = 0;
bool exclude_quiz = 0;
std::time_t start_time = 0;
std::time_t end_time = std::time(nullptr);
std::string ocpl_user;
std::string ocde_user;
@ -77,7 +81,7 @@ int main(int argc, char** argv) {
if (argc == 1) show_usage();
int o;
while ((o = getopt(argc, argv, "qNQg:o::p:d:u:n:r:k:H:s:m:eth?")) != -1)
while ((o = getopt(argc, argv, "qNQg:o::p:d:u:n:r:k:i:f:H:s:m:eth?")) != -1)
switch (o) {
// case 'd':
// Debug::set_debug_level(get_num('d',optarg));
@ -117,6 +121,12 @@ int main(int argc, char** argv) {
case 'q':
use_ocpl_db = 1;
break;
case 'i':
start_time = get_num('i',optarg);
break;
case 'f':
end_time = get_num('f',optarg);
break;
case 'N':
get_not_found = 1;
break;
@ -232,17 +242,23 @@ int main(int argc, char** argv) {
Caches fcc;
if (!get_not_found) {
for (auto& i : cc) {
dates[i.date]++;
sorted_caches.insert({ i.date_t, &i });
if (i.type != "Moving" && i.type != "Own" && (!get_not_found || !exclude_quiz || i.type != "Quiz")) {
sorted_fcaches.insert({ i.date_t, &i });
fcc.insert(i);
for (auto i = cc.begin(); i != cc.end(); ) {
if (i->date_t > end_time || i->date_t < start_time) {
i = cc.erase(i);
continue;
}
sorted_caches_by_hidden.insert({ i.date_hidden_t, &i });
caches_by_fav.push_back(&i);
caches_by_fav_perc.push_back(&i);
caches_by_finds.push_back(&i);
dates[i->date]++;
sorted_caches.insert({ i->date_t, &*i });
if (i->type != "Moving" && i->type != "Own" && (!get_not_found || !exclude_quiz || i->type != "Quiz")) {
sorted_fcaches.insert({ i->date_t, &*i });
fcc.insert(*i);
}
sorted_caches_by_hidden.insert({ i->date_hidden_t, &*i });
caches_by_fav.push_back(&*i);
caches_by_fav_perc.push_back(&*i);
caches_by_finds.push_back(&*i);
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; });