diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-07-13 16:04:55 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-07-13 16:04:55 -0500 |
commit | 8633fe4774a83f90969e965c02b35e531d2ac6df (patch) | |
tree | 47ab02f5cf9885d0a856fcdf4a92ae1d5e180891 /src/models | |
parent | 0c39f286f6125ecc98e9216443d98a011b17a8c1 (diff) | |
download | freqtimer-web-8633fe4774a83f90969e965c02b35e531d2ac6df.tar.xz freqtimer-web-8633fe4774a83f90969e965c02b35e531d2ac6df.zip |
Refactor, move label-making components into the model class, create a single update function for all labels
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/counter.cpp | 18 | ||||
-rw-r--r-- | src/models/counter.hpp | 1 | ||||
-rw-r--r-- | src/models/timer.cpp | 20 | ||||
-rw-r--r-- | src/models/timer.hpp | 2 |
4 files changed, 41 insertions, 0 deletions
diff --git a/src/models/counter.cpp b/src/models/counter.cpp index 1b6315d..a80515e 100644 --- a/src/models/counter.cpp +++ b/src/models/counter.cpp @@ -1,4 +1,5 @@ #include "models/counter.hpp" +#include "utils/utils.hpp" double FreqCounter::rate() const { uint64_t ms = _timer->total_duration_ms(); @@ -23,6 +24,23 @@ std::string FreqCounter::display_value() const { return std::to_string(_overtime_cnt); } +std::string FreqCounter::rate_display() const { + double rate = this->rate(); + + std::string rate_display_val; + format_rate(rate_display_val, rate); + + if(_timer->overtime()) { + std::string rate_overtime; + format_rate(rate_overtime, overtime_rate()); + + rate_display_val.append(", "); + rate_display_val.append(rate_overtime); + } + + return rate_display_val; +} + void FreqCounter::inc() { if(_overtime_cnt != UINT32_MAX) diff --git a/src/models/counter.hpp b/src/models/counter.hpp index fa9e1c5..74f4e46 100644 --- a/src/models/counter.hpp +++ b/src/models/counter.hpp @@ -26,6 +26,7 @@ class FreqCounter { [[nodiscard]] std::string display_value() const; + [[nodiscard]] std::string rate_display() const; private: diff --git a/src/models/timer.cpp b/src/models/timer.cpp index a05e8c1..8ab3c23 100644 --- a/src/models/timer.cpp +++ b/src/models/timer.cpp @@ -1,6 +1,9 @@ #include "timer.hpp" + #include <cinttypes> +#include "utils/utils.hpp" + #ifdef EMSCRIPTEN #include <emscripten/html5.h> #endif @@ -73,6 +76,23 @@ std::string FreqTimer::counter_display_value() const { return display_val; } +std::string FreqTimer::record_floor_display() const { + double record_floor = this->record_floor(); + + std::string record_floor_label; + format_rate(record_floor_label, record_floor); + + if(overtime()) { + std::string rec_floor_overtime; + format_rate(rec_floor_overtime, overtime_record_floor()); + + record_floor_label.append(", "); + record_floor_label.append(rec_floor_overtime); + } + + return record_floor_label; +} + void FreqTimer::increment_preset_ms(uint64_t amount_ms) { if(_state != State::SETTING) { clear(); diff --git a/src/models/timer.hpp b/src/models/timer.hpp index 0b0a978..fcaec1a 100644 --- a/src/models/timer.hpp +++ b/src/models/timer.hpp @@ -47,6 +47,8 @@ class FreqTimer { [[nodiscard]] std::string counter_display_value() const; + [[nodiscard]] std::string record_floor_display() const; + /* * Lowest frequency which can be measured * in the interval (as measured in events/min |