Sha256: ec267c9af0ddb1a0c022639b73266f7e199acb8748922004f24a0ecb9b35fa5a
Contents?: true
Size: 880 Bytes
Versions: 15
Compression:
Stored size: 880 Bytes
Contents
module PulseMeter module Sensor module Timelined # Calculates n'th percentile in interval class MultiPercentile < ZSetBased attr_reader :p_value def initialize(name, options) @p_value = assert_array!(options, :p, []) @p_value.each {|p| assert_ranged_float!({:percentile => p}, :percentile, 0, 1)} super(name, options) end def calculate(key, count) count = @p_value.each_with_object({}) { |p, acc| position = p > 0 ? (p * count).round - 1 : 0 el = redis.zrange(key, position, position)[0] acc[p] = redis.zscore(key, el) }.to_json end private def deflate(value) hash = JSON.parse(value) hash.each {|p, v| hash[p] = v.to_f} hash end end end end end
Version data entries
15 entries across 15 versions & 2 rubygems