aboutsummaryrefslogtreecommitdiff
path: root/src/models/counter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/counter.cpp')
-rw-r--r--src/models/counter.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/models/counter.cpp b/src/models/counter.cpp
new file mode 100644
index 0000000..4855c24
--- /dev/null
+++ b/src/models/counter.cpp
@@ -0,0 +1,35 @@
+#include "models/counter.hpp"
+
+double FreqCounter::rate() const {
+ uint64_t ms = _timer->total_duration_ms();
+
+ if(_timer->overtime()) {
+ ms = _timer->preset_ms();
+ }
+
+ return static_cast<double>(_cnt) / (ms / 60.0e3);
+}
+
+
+double FreqCounter::overtime_rate() const {
+ return static_cast<double>(_overtime_cnt) / (_timer->total_duration_ms() / 60.0e3);
+}
+
+std::string FreqCounter::display_value() const {
+ if(_cnt == UINT32_MAX) {
+ return "ERR";
+ }
+
+ return std::to_string(_cnt);
+}
+
+void FreqCounter::inc() {
+
+ if(_overtime_cnt != UINT32_MAX)
+ _overtime_cnt++;
+
+ if(!_timer->overtime()) {
+ _cnt = _overtime_cnt;
+ }
+
+}