Sha256: 2e97676f7acbf92e69bb34e61972a736da4c96dcf6d7156648a0594bee60d80a

Contents?: true

Size: 622 Bytes

Versions: 9

Compression:

Stored size: 622 Bytes

Contents

module PulseMeter
  module Sensor
    module Timelined
      # Calculates max value in interval
      class Max < Timeline

        def aggregate_event(key, value)
          redis.zadd(key, value, "#{value}::#{uniqid}")
          redis.zremrangebyrank(key, 0, -2)
        end

        def summarize(key)
          count = redis.zcard(key)
          if count > 0
            max_el = redis.zrange(key, -1, -1)[0]
            redis.zscore(key, max_el)
          else
            nil
          end
        end

        private
        
        def deflate(value)
          value.to_f
        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pulse-meter-0.3.1 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.3.0 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.11 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.10 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.9 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.8 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.7 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.6 lib/pulse-meter/sensor/timelined/max.rb
pulse-meter-0.2.5 lib/pulse-meter/sensor/timelined/max.rb