Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types/collection_duration.hpp" |
| 4 | #include "types/collection_time_scope.hpp" |
| 5 | #include "types/operation_type.hpp" |
| 6 | |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 7 | #include <chrono> |
| 8 | #include <cstdint> |
| 9 | #include <ostream> |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 10 | #include <string> |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 11 | #include <vector> |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 12 | |
| 13 | class MetricParams final |
| 14 | { |
| 15 | public: |
| 16 | MetricParams& operationType(OperationType val) |
| 17 | { |
| 18 | operationTypeProperty = val; |
| 19 | return *this; |
| 20 | } |
| 21 | |
| 22 | const OperationType& operationType() const |
| 23 | { |
| 24 | return operationTypeProperty; |
| 25 | } |
| 26 | |
| 27 | MetricParams& id(std::string val) |
| 28 | { |
| 29 | idProperty = std::move(val); |
| 30 | return *this; |
| 31 | } |
| 32 | |
| 33 | const std::string& id() const |
| 34 | { |
| 35 | return idProperty; |
| 36 | } |
| 37 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 38 | MetricParams& collectionTimeScope(CollectionTimeScope val) |
| 39 | { |
| 40 | collectionTimeScopeProperty = val; |
| 41 | return *this; |
| 42 | } |
| 43 | |
| 44 | const CollectionTimeScope& collectionTimeScope() const |
| 45 | { |
| 46 | return collectionTimeScopeProperty; |
| 47 | } |
| 48 | |
| 49 | MetricParams& collectionDuration(CollectionDuration val) |
| 50 | { |
| 51 | collectionDurationProperty = val; |
| 52 | return *this; |
| 53 | } |
| 54 | |
| 55 | const CollectionDuration& collectionDuration() const |
| 56 | { |
| 57 | return collectionDurationProperty; |
| 58 | } |
| 59 | |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 60 | MetricParams& readings(std::vector<std::pair<Milliseconds, double>> value) |
| 61 | { |
| 62 | readingsProperty = std::move(value); |
| 63 | return *this; |
| 64 | } |
| 65 | |
| 66 | const std::vector<std::pair<Milliseconds, double>>& readings() const |
| 67 | { |
| 68 | return readingsProperty; |
| 69 | } |
| 70 | |
| 71 | MetricParams& expectedReading(Milliseconds delta, double reading) |
| 72 | { |
| 73 | expectedReadingProperty = std::make_pair(delta, reading); |
| 74 | return *this; |
| 75 | } |
| 76 | |
| 77 | const std::pair<Milliseconds, double>& expectedReading() const |
| 78 | { |
| 79 | return expectedReadingProperty; |
| 80 | } |
| 81 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame^] | 82 | bool expectedIsTimerRequired() const |
| 83 | { |
| 84 | return expectedIsTimerRequiredProperty; |
| 85 | } |
| 86 | |
| 87 | MetricParams& expectedIsTimerRequired(bool value) |
| 88 | { |
| 89 | expectedIsTimerRequiredProperty = value; |
| 90 | return *this; |
| 91 | } |
| 92 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 93 | private: |
| 94 | OperationType operationTypeProperty = {}; |
| 95 | std::string idProperty = "MetricId"; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 96 | CollectionTimeScope collectionTimeScopeProperty = {}; |
| 97 | CollectionDuration collectionDurationProperty = |
| 98 | CollectionDuration(Milliseconds(0u)); |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 99 | std::vector<std::pair<Milliseconds, double>> readingsProperty = {}; |
| 100 | std::pair<Milliseconds, double> expectedReadingProperty = {}; |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame^] | 101 | bool expectedIsTimerRequiredProperty = true; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 102 | }; |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 103 | |
| 104 | inline std::ostream& operator<<(std::ostream& os, const MetricParams& mp) |
| 105 | { |
| 106 | using utils::enumToString; |
| 107 | |
| 108 | os << "{ op: " << enumToString(mp.operationType()) |
| 109 | << ", timeScope: " << enumToString(mp.collectionTimeScope()) |
| 110 | << ", duration: " << mp.collectionDuration().t.count() |
| 111 | << ", readings: { "; |
| 112 | for (auto [timestamp, reading] : mp.readings()) |
| 113 | { |
| 114 | os << reading << "(" << timestamp.count() << "ms), "; |
| 115 | } |
| 116 | |
| 117 | auto [timestamp, reading] = mp.expectedReading(); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame^] | 118 | os << " }, expectedReading: " << reading << "(" << timestamp.count() |
| 119 | << "ms), expectedIsTimerRequired: " << std::boolalpha |
| 120 | << mp.expectedIsTimerRequired() << " }"; |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 121 | return os; |
| 122 | } |