Class: Twingly::Metrics::Snapshot
- Inherits:
-
Object
- Object
- Twingly::Metrics::Snapshot
- Defined in:
- lib/twingly/metrics/snapshot.rb
Constant Summary collapse
- MEDIAN_Q =
0.5- P75_Q =
0.75- P95_Q =
0.95- P98_Q =
0.98- P99_Q =
0.99- P999_Q =
0.999
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#get_75th_percentile ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #get_95th_percentile ⇒ Object
- #get_98th_percentile ⇒ Object
- #get_999th_percentile ⇒ Object
- #get_99th_percentile ⇒ Object
-
#initialize(values) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #median ⇒ Object
- #size ⇒ Object
-
#value(quantile) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(values) ⇒ Snapshot
Returns a new instance of Snapshot.
15 16 17 |
# File 'lib/twingly/metrics/snapshot.rb', line 15 def initialize(values) @values = values.sort end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
13 14 15 |
# File 'lib/twingly/metrics/snapshot.rb', line 13 def values @values end |
Instance Method Details
#get_75th_percentile ⇒ Object
rubocop:disable Naming/AccessorMethodName
43 44 45 |
# File 'lib/twingly/metrics/snapshot.rb', line 43 def get_75th_percentile value(P75_Q) end |
#get_95th_percentile ⇒ Object
47 48 49 |
# File 'lib/twingly/metrics/snapshot.rb', line 47 def get_95th_percentile value(P95_Q) end |
#get_98th_percentile ⇒ Object
51 52 53 |
# File 'lib/twingly/metrics/snapshot.rb', line 51 def get_98th_percentile value(P98_Q) end |
#get_999th_percentile ⇒ Object
59 60 61 |
# File 'lib/twingly/metrics/snapshot.rb', line 59 def get_999th_percentile value(P999_Q) end |
#get_99th_percentile ⇒ Object
55 56 57 |
# File 'lib/twingly/metrics/snapshot.rb', line 55 def get_99th_percentile value(P99_Q) end |
#median ⇒ Object
38 39 40 |
# File 'lib/twingly/metrics/snapshot.rb', line 38 def median value(MEDIAN_Q) end |
#size ⇒ Object
34 35 36 |
# File 'lib/twingly/metrics/snapshot.rb', line 34 def size @values.length end |
#value(quantile) ⇒ Object
rubocop:disable Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/twingly/metrics/snapshot.rb', line 19 def value(quantile) # rubocop:disable Metrics/AbcSize raise ArgumentError, "quantile must be between 0.0 and 1.0" if quantile < 0.0 || quantile > 1.0 return 0.0 if @values.empty? pos = quantile * (@values.length + 1) return @values.first if pos < 1 return @values.last if pos >= @values.length lower = @values[pos.to_i - 1] upper = @values[pos.to_i] lower + ((pos - pos.floor) * (upper - lower)) end |