Class: Sqreen::Metric::Binning
- Defined in:
- lib/sqreen/metrics/binning.rb
Overview
Takes numbers as samples and bins them (effectively, rounds them). Also collect max values
Constant Summary collapse
- BASE_KEY =
'base'.freeze
- FACTOR_KEY =
'factor'.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Binning
constructor
upper bound of i-th bin is factor * base^(i-1).
- #next_sample(time) ⇒ Object
- #update(_key, x) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Binning
upper bound of i-th bin is factor * base^(i-1)
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sqreen/metrics/binning.rb', line 17 def initialize(opts={}) = opts.dup @base = .delete(BASE_KEY) @factor = .delete(FACTOR_KEY) super() log_base = Math.log(@base) log_factor = Math.log(@factor) @inv_log_base = 1 / log_base @add_parcel = - log_factor / log_base new_sample(Sqreen.time) end |
Instance Method Details
#next_sample(time) ⇒ Object
36 37 38 39 |
# File 'lib/sqreen/metrics/binning.rb', line 36 def next_sample(time) return nil if @sample[OBSERVATION_KEY].empty? super(time) end |
#update(_key, x) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/sqreen/metrics/binning.rb', line 29 def update(_key, x) h = @sample[OBSERVATION_KEY] bin = bin_no(x) h[bin] += 1 h['max'] = x if x > h['max'] end |