From 30d38d8fc4bb0a3079d67ae272517fc539c2645f Mon Sep 17 00:00:00 2001 From: Tomasz Golinski Date: Mon, 18 Jul 2022 19:39:13 +0200 Subject: [PATCH] Precompute treshold for powertrails, note rounding is always up --- powertrail.cpp | 4 ++++ powertrail.h | 1 + 2 files changed, 5 insertions(+) diff --git a/powertrail.cpp b/powertrail.cpp index 7664e96..0fd9775 100644 --- a/powertrail.cpp +++ b/powertrail.cpp @@ -32,6 +32,8 @@ void from_json(const json& j, Powertrail& item) { j.at("caches").get_to(item.caches); j.at("type").get_to(item.type); strptime(item.date_str.c_str(), "%d-%m-%Y", &item.date); + item.treshold = (item.caches.size() * item.treshold_perc + 99) / 100; // Integer division rounding up + item.active_caches_not_found = item.active_caches; } std::string Powertrail::link() const { @@ -132,6 +134,8 @@ void PowertrailDB::get_trail(uint n) { T.active_caches++; } + T.treshold = (T.caches.size() * T.treshold_perc + 99) / 100; // Integer division rounding up + data.insert({ n, T }); } diff --git a/powertrail.h b/powertrail.h index 12acb0a..f4535f6 100644 --- a/powertrail.h +++ b/powertrail.h @@ -27,6 +27,7 @@ public: std::tm date; std::string date_str; uint treshold_perc; + uint treshold; std::unordered_set caches; uint active_caches = 0;