class Bmg::Summarizer::Percentile
Percentile
summarizer.
Example:
# direct ruby usage Bmg::Summarizer.percentile(:qty, 50).summarize(...)
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(*args, &bl)
click to toggle source
Calls superclass method
Bmg::Summarizer::new
# File lib/bmg/summarizer/percentile.rb, line 17 def initialize(*args, &bl) @nth = args.find{|a| a.is_a?(Integer) } || 50 functor = args.find{|a| a.is_a?(Symbol) } || bl options = args.select{|a| a.is_a?(Hash) }.inject(DEFAULT_OPTIONS){|memo,opts| memo.merge(opts) }.dup super(functor, options) end
Public Instance Methods
_happens(memo, val)
click to toggle source
Collects the value
# File lib/bmg/summarizer/percentile.rb, line 32 def _happens(memo, val) memo << val end
finalize(memo)
click to toggle source
Finalizes the computation.
# File lib/bmg/summarizer/percentile.rb, line 37 def finalize(memo) return nil if memo.empty? index = memo.size.to_f * (@nth.to_f / 100.0) floor, ceil = index.floor, index.ceil ceil +=1 if floor == ceil below = [floor - 1, 0].max above = [[ceil - 1, memo.size - 1].min, 0].max sorted = memo.sort if options[:variant] == :continuous (sorted[above] + sorted[below]) / 2.0 else sorted[below] end end
least()
click to toggle source
Returns [] as least value.
# File lib/bmg/summarizer/percentile.rb, line 27 def least() [] end