Class: TabsTabs::Metrics::Value::Stats
- Inherits:
-
Object
- Object
- TabsTabs::Metrics::Value::Stats
show all
- Includes:
- Enumerable, Helpers
- Defined in:
- lib/tabs_tabs/metrics/value/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/value/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/value/stats.rb', line 9
def period
@period
end
|
#resolution ⇒ Object
Returns the value of attribute resolution.
9
10
11
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 9
def resolution
@resolution
end
|
#values ⇒ Object
Returns the value of attribute values.
9
10
11
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 9
def values
@values
end
|
Instance Method Details
#avg ⇒ Object
39
40
41
42
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 39
def avg
return 0 if count.zero?
(self.sum.to_f / self.count.to_f).round(Config.decimal_precision)
end
|
#count ⇒ Object
23
24
25
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 23
def count
@count ||= values.map { |v| v["count"] }.sum
end
|
#each(&block) ⇒ Object
44
45
46
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 44
def each(&block)
values.each(&block)
end
|
#first ⇒ Object
15
16
17
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 15
def first
values.first
end
|
#last ⇒ Object
19
20
21
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 19
def last
values.last
end
|
#max ⇒ Object
35
36
37
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 35
def max
@max ||= values.max_by { |v| v["max"] }["max"]
end
|
#min ⇒ Object
31
32
33
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 31
def min
@min ||= values.min_by { |v| v["min"] }["min"]
end
|
#sum ⇒ Object
27
28
29
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 27
def sum
@sum ||= values.map { |v| v["sum"] }.sum
end
|
#to_a ⇒ Object
48
49
50
|
# File 'lib/tabs_tabs/metrics/value/stats.rb', line 48
def to_a
values
end
|