Class: TabsTabs::Metrics::Counter::Stats
- Inherits:
-
Object
- Object
- TabsTabs::Metrics::Counter::Stats
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
#period ⇒ Object
Returns the value of attribute period.
9
10
11
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 9
def period
@period
end
|
#resolution ⇒ Object
Returns the value of attribute resolution.
9
10
11
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 9
def resolution
@resolution
end
|
#values ⇒ Object
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
#avg ⇒ Object
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
|
#first ⇒ Object
15
16
17
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 15
def first
values.first
end
|
#last ⇒ Object
19
20
21
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 19
def last
values.last
end
|
#max ⇒ Object
31
32
33
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 31
def max
@max ||= values.max_by { |v| v["count"] }["count"]
end
|
#min ⇒ Object
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_a ⇒ Object
44
45
46
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 44
def to_a
values
end
|
#total ⇒ Object
23
24
25
|
# File 'lib/tabs_tabs/metrics/counter/stats.rb', line 23
def total
@total ||= values.map { |v| v["count"] }.sum
end
|