Class: Nightfury::Metric::CountTimeSeries

Inherits:
TimeSeries show all
Defined in:
lib/nightfury/metric/count_time_series.rb

Constant Summary

Constants inherited from Base

Base::ALLOWED_STEPS

Instance Attribute Summary

Attributes inherited from Base

#name, #redis, #redis_key_prefix, #step, #store_as

Instance Method Summary collapse

Methods inherited from TimeSeries

#default_meta, #each_timestamp, floor_time, #floor_time, #get, #get_all, #get_exact, #get_range, #get_step_time, #initialize, #meta, #meta=, seconds_in_step, #seconds_in_step, #set

Methods inherited from Base

#delete, #initialize, #redis_key

Constructor Details

This class inherits a constructor from Nightfury::Metric::TimeSeries

Instance Method Details

#decr(step = 1, time = Time.now) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/nightfury/metric/count_time_series.rb', line 24

def decr(step=1, time = Time.now)
  value = 0
  step_time = get_step_time(time)
  data_point = get_exact(step_time)
  value = data_point.flatten[1] unless data_point.nil?
  updated_value = value.to_i - step
  set(updated_value, step_time)
end

#get_padded_range(start_time, end_time) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/nightfury/metric/count_time_series.rb', line 4

def get_padded_range(start_time, end_time)
  data_points = get_range(start_time, end_time)
  each_timestamp(start_time, end_time) do |current_step_time, last_step_time|
    current_step_time = current_step_time.to_s
    last_step_time = last_step_time.to_s
    next if data_points[current_step_time]
    data_points[current_step_time] = 0.to_s
  end
  Hash[data_points.sort]
end

#incr(step = 1, time = Time.now) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/nightfury/metric/count_time_series.rb', line 15

def incr(step=1, time = Time.now)
  value = 0
  step_time = get_step_time(time)
  data_point = get_exact(step_time)
  value = data_point.flatten[1] unless data_point.nil?
  updated_value = value.to_i + step
  set(updated_value, step_time) 
end