class Aeternitas::Metrics::Ratio
Stores time series data for ratios @!attribute [r] from
@return [DateTime] start of the time series
@!attribute [r] to
@return [DateTime] end of the time series
@!attribute [r] resolution
@return [Symbol] resolution of the time series
@!attribute [r] values
@return [Array] time series data
The time series values have the following format:
{ timestamp: DateTime("2000-01-01 00:00:00 UTC"), ratio: 0.01 }
Attributes
from[R]
resolution[R]
to[R]
values[R]
Public Class Methods
new(from, to, resolution, values)
click to toggle source
Create a new ratio time series @param [DateTime] from start of the time series @param [DateTime] to end of the time series @param [Symbol] resolution time series resolution @param [Array] values time series data
# File lib/aeternitas/metrics/ratio.rb, line 27 def initialize(from, to, resolution, values) @from = from @to = to @resolution = resolution @values = values end
Public Instance Methods
avg()
click to toggle source
Computes the average ration within the time series. @return [Float] the average ratio
# File lib/aeternitas/metrics/ratio.rb, line 56 def avg return 0 if count.zero? p @values @values.inject(0) { |sum, v| sum + v[:ratio] } / @values.count end
each(&block)
click to toggle source
# File lib/aeternitas/metrics/ratio.rb, line 34 def each(&block) @values.each(&block) end
max()
click to toggle source
Computes the maximum ration within the time series. @return [Float] the maximum ratio
# File lib/aeternitas/metrics/ratio.rb, line 50 def max @values.max_by { |v| v['ratio'] }['ratio'] end
min()
click to toggle source
Computes the minimum ration within the time series. @return [Float] the minimum ratio
# File lib/aeternitas/metrics/ratio.rb, line 44 def min @values.min_by { |v| v['ratio'] }['ratio'] end
to_a()
click to toggle source
# File lib/aeternitas/metrics/ratio.rb, line 38 def to_a @values.to_a end
to_s()
click to toggle source
# File lib/aeternitas/metrics/ratio.rb, line 62 def to_s values.to_s end