Class: TabsTabs::Metrics::Counter::Stats

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Helpers
Defined in:
lib/tabs_tabs/metrics/counter/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#normalize_period, #timestamp_range, #to_numeric

Constructor Details

#initialize(period, resolution, values) ⇒ Stats

Returns a new instance of Stats.



11
12
13
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 11

def initialize(period, resolution, values)
  @period, @resolution, @values = period, resolution, values
end

Instance Attribute Details

#periodObject (readonly)

Returns the value of attribute period.



9
10
11
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 9

def period
  @period
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



9
10
11
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 9

def resolution
  @resolution
end

#valuesObject (readonly)

Returns the value of attribute values.



9
10
11
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 9

def values
  @values
end

Instance Method Details

#avgObject



35
36
37
38
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 35

def avg
  return 0 if values.size.zero?
  (self.total.to_f / values.size.to_f).round(Config.decimal_precision)
end

#each(&block) ⇒ Object



40
41
42
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 40

def each(&block)
  values.each(&block)
end

#firstObject



15
16
17
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 15

def first
  values.first
end

#lastObject



19
20
21
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 19

def last
  values.last
end

#maxObject



31
32
33
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 31

def max
  @max ||= values.max_by { |v| v["count"] }["count"]
end

#minObject



27
28
29
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 27

def min
  @min ||= values.min_by { |v| v["count"] }["count"]
end

#to_aObject



44
45
46
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 44

def to_a
  values
end

#totalObject



23
24
25
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 23

def total
  @total ||= values.map { |v| v["count"] }.sum
end