class PIM::Statistics::StatisticCalculator

Attributes

counts[R]
items[R]
new_item[R]
old_item[R]
params[R]
scopes[R]

Public Class Methods

new(old_item, new_item, params, scopes, &block) click to toggle source
# File statistics.rb, line 98
def initialize old_item, new_item, params, scopes, &block

  @old_item = old_item
  @new_item = new_item
  @items = []
  @items << [old_item, -1] unless old_item.nil?
  @items << [new_item, 1] unless new_item.nil?

  @params = params
  @scopes = scopes
  @counts = {}

  if block.arity == 3
    self.instance_exec(old_item, new_item, params, &block)
  elsif block.arity == 2
    self.instance_exec(old_item, new_item, &block)
  elsif block.arity == 1
    self.instance_exec(new_item, &block)
  else
    self.instance_exec(&block)
  end

end

Public Instance Methods

count(key, value, *dimensions, scope: nil)

For legacy statistics

Alias for: set
decr(key, *dimensions, &scope_block) click to toggle source
# File statistics.rb, line 148
def decr key, *dimensions, &scope_block
  incr key, *dimensions, incr_value: -1, &scope_block
end
decr_all(keys, *dimensions, &scope_block) click to toggle source
# File statistics.rb, line 158
def decr_all keys, *dimensions, &scope_block
  incr_all keys, *dimensions, incr_value: -1, &scope_block
end
get(key, *dimensions, scope: nil) click to toggle source
# File statistics.rb, line 122
def get key, *dimensions, scope: nil
  counts = get_counts(key, scope: scope, create: false)
  return 0 if is_empty?(counts)
  counts[join_dimensions(*dimensions)] || 0
end
incr(key, *dimensions, incr_value: 1, scopes: @scopes, &scope_block) click to toggle source
# File statistics.rb, line 138
def incr key, *dimensions, incr_value: 1, scopes: @scopes, &scope_block
  return if scopes.nil?
  scopes.each do |scope|
    next unless filter_by_scope?(scope, key, *dimensions, &scope_block)
    current_value = get(key, *dimensions, scope: scope)
    current_value += incr_value
    set(key, current_value, *dimensions, scope: scope)
  end
end
incr_all(keys, *dimensions, incr_value: 1, scopes: @scopes, &scope_block) click to toggle source
# File statistics.rb, line 152
def incr_all keys, *dimensions, incr_value: 1, scopes: @scopes, &scope_block
  keys.each do |key|
    incr(key, *dimensions, incr_value: incr_value, scopes: scopes, &scope_block)
  end
end
set(key, value, *dimensions, scope: nil) click to toggle source
# File statistics.rb, line 128
def set key, value, *dimensions, scope: nil
  return if is_empty?(value) or not dimensions_set?(key, *dimensions)
  counts = get_counts(key, scope: scope, create: true)
  counts[join_dimensions(*dimensions)] = value
  value
end
Also aliased as: count