Sha256: 18d8b8612bcce8c4aa841f04442955bd3b304076ff2406a83118109d25c8b171

Contents?: true

Size: 624 Bytes

Versions: 18

Compression:

Stored size: 624 Bytes

Contents

module PulseMeter
  module Sensor
    module Timelined
      # Average value over interval
      class Average < Timeline

        def aggregate_event(key, value)
          command_aggregator.hincrby(key, :count, 1)
          command_aggregator.hincrby(key, :sum, value)
        end

        def summarize(key)
          count = redis.hget(key, :count)
          sum = redis.hget(key, :sum)
          if count && !count.empty?
            sum.to_f / count.to_f
          else
            0
          end
        end

        private

        def deflate(value)
          value.to_f
        end

      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
pulse_meter_core-0.5.5 lib/pulse_meter/sensor/timelined/average.rb
pulse_meter_core-0.5.4 lib/pulse_meter/sensor/timelined/average.rb
pulse_meter_core-0.5.3 lib/pulse_meter/sensor/timelined/average.rb
pulse_meter_core-0.5.2 lib/pulse_meter/sensor/timelined/average.rb
pulse_meter_core-0.5.1 lib/pulse_meter/sensor/timelined/average.rb
pulse_meter_core-0.5.0 lib/pulse_meter/sensor/timelined/average.rb
pulse_meter_core-0.4.13 lib/pulse_meter/sensor/timelined/average.rb
pulse-meter-0.4.9 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.8 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.7 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.6 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.5 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.4 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.3 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.2 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.1 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.4.0 lib/pulse-meter/sensor/timelined/average.rb
pulse-meter-0.3.2 lib/pulse-meter/sensor/timelined/average.rb