Class: PulseMeter::Sensor::Timelined::MultiPercentile

Inherits:
ZSetBased show all
Defined in:
lib/pulse_meter/sensor/timelined/multi_percentile.rb

Overview

Calculates n’th percentile in interval

Constant Summary

Constants inherited from PulseMeter::Sensor::Timeline

PulseMeter::Sensor::Timeline::DEFAULTS, PulseMeter::Sensor::Timeline::MAX_TIMESPAN_POINTS

Constants included from PulseMeter::Sensor::TimelineReduce

PulseMeter::Sensor::TimelineReduce::MAX_INTERVALS

Constants included from Mixins::Dumper

Mixins::Dumper::DUMP_REDIS_KEY

Instance Attribute Summary collapse

Attributes inherited from PulseMeter::Sensor::Timeline

#interval, #raw_data_ttl, #reduce_delay, #timezone, #ttl

Attributes inherited from Base

#name, #redis

Instance Method Summary collapse

Methods inherited from ZSetBased

#aggregate_event, #summarize, #update

Methods inherited from PulseMeter::Sensor::Timeline

#aggregate_event, #cleanup, #current_interval_id, #current_raw_data_key, #data_key, #deflate_safe, #drop_within, #event_at, #get_interval_id, #get_raw_value, #raw_data_key, #summarize, #timeline, #timeline_within

Methods included from PulseMeter::Sensor::TimelineReduce

#collect_ids_to_reduce, included, #reduce, #reduce_all_raw

Methods included from Mixins::Utils

#assert_array!, #assert_positive_integer!, #assert_ranged_float!, #camelize, #camelize_keys, #constantize, #each_subset, #parse_time, #subsets_of, #symbolize_keys, #titleize, #underscore, #uniqid

Methods inherited from Base

#annotate, #annotation, #cleanup, #command_aggregator, #event

Methods included from Mixins::Dumper

included

Constructor Details

#initialize(name, options) ⇒ MultiPercentile

Returns a new instance of MultiPercentile.



8
9
10
11
12
# File 'lib/pulse_meter/sensor/timelined/multi_percentile.rb', line 8

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

Instance Attribute Details

#p_valueObject (readonly)

Returns the value of attribute p_value.



6
7
8
# File 'lib/pulse_meter/sensor/timelined/multi_percentile.rb', line 6

def p_value
  @p_value
end

Instance Method Details

#calculate(key, count) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/pulse_meter/sensor/timelined/multi_percentile.rb', line 14

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