Sha256: a59c75733aacbf5d5f7ac3a33096191125bd5866e4b40faa084fb2ab86812753

Contents?: true

Size: 843 Bytes

Versions: 29

Compression:

Stored size: 843 Bytes

Contents

# typed: true

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.com/terms.html

require 'sqreen/metrics/base'

module Sqreen
  module Metric
    # This perform an average aggregation
    class Average < Base
      # from class attr_accessor :aggregate

      def update(key, value)
        super
        @sums[key] ||= 0
        @sums[key] += value
        @counts[key] ||= 0
        @counts[key] += 1
      end

      protected

      def new_sample(time)
        super(time)
        @sums = {}
        @counts = {}
      end

      def finalize_sample(time)
        super(time)
        @sample[FINISH_KEY] = time
        h = {}
        @sums.each do |k, v|
          h[k] = v.to_f / @counts[k]
        end
        @sample[OBSERVATION_KEY] = h
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
sqreen-1.19.3-java lib/sqreen/metrics/average.rb
sqreen-1.19.3 lib/sqreen/metrics/average.rb
sqreen-1.19.2-java lib/sqreen/metrics/average.rb
sqreen-1.19.2 lib/sqreen/metrics/average.rb
sqreen-1.19.1-java lib/sqreen/metrics/average.rb
sqreen-1.19.1 lib/sqreen/metrics/average.rb
sqreen-1.19.0-java lib/sqreen/metrics/average.rb
sqreen-1.19.0 lib/sqreen/metrics/average.rb
sqreen-1.19.0.beta1 lib/sqreen/metrics/average.rb