2019-06-18 06:54:32 +02:00
|
|
|
#include "stats.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <chrono>
|
2019-06-24 02:20:43 +02:00
|
|
|
#include <iostream>
|
2019-06-18 06:54:32 +02:00
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
2021-01-05 06:38:40 +01:00
|
|
|
namespace oxen {
|
2019-06-18 06:54:32 +02:00
|
|
|
|
|
|
|
static void cleanup_old(std::deque<test_result_t>& tests, time_t cutoff_time) {
|
|
|
|
|
|
|
|
const auto it = std::find_if(tests.begin(), tests.end(),
|
|
|
|
[cutoff_time](const test_result_t& res) {
|
|
|
|
return res.timestamp > cutoff_time;
|
|
|
|
});
|
|
|
|
|
|
|
|
tests.erase(tests.begin(), it);
|
|
|
|
}
|
|
|
|
|
2019-07-11 06:54:42 +02:00
|
|
|
static constexpr std::chrono::seconds ROLLING_WINDOW_SIZE = 120min;
|
2019-06-18 06:54:32 +02:00
|
|
|
|
|
|
|
void all_stats_t::cleanup() {
|
|
|
|
|
|
|
|
using std::chrono::duration_cast;
|
|
|
|
using std::chrono::seconds;
|
|
|
|
|
|
|
|
const auto cutoff = time(nullptr) - ROLLING_WINDOW_SIZE.count();
|
|
|
|
|
|
|
|
for (auto& kv : peer_report_) {
|
|
|
|
|
|
|
|
const sn_record_t& sn = kv.first;
|
|
|
|
|
|
|
|
cleanup_old(peer_report_[sn].storage_tests, cutoff);
|
|
|
|
}
|
2019-08-08 09:37:34 +02:00
|
|
|
|
|
|
|
/// updated stats for "previous period"
|
|
|
|
this->next_period();
|
2019-06-18 06:54:32 +02:00
|
|
|
}
|
|
|
|
|
2021-01-05 06:38:40 +01:00
|
|
|
} // namespace oxen
|