Sha256: 7bcc41405e00b2c7362b51d8fc33d8d1a4c98c3ef336b4ad2e907cae3bad0bb7
Contents?: true
Size: 965 Bytes
Versions: 6
Compression:
Stored size: 965 Bytes
Contents
module Tabs module Metrics class Counter class Stats include Enumerable include Helpers attr_reader :period, :resolution, :values def initialize(period, resolution, values) @period, @resolution, @values = period, resolution, values end def first values.first end def last values.last end def total @total ||= values.map { |v| v["count"] }.sum end def min @min ||= values.min_by { |v| v["count"] }["count"] end def max @max ||= values.max_by { |v| v["count"] }["count"] end def avg return 0 if values.size.zero? (self.total.to_f / values.size.to_f).round(Config.decimal_precision) end def each(&block) values.each(&block) end def to_a values end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems