Sha256: c2f8bf2287514e6d8e7ec1ab322ef68a2e101cf9ae9f37185eaeab6ba690cbc8

Contents?: true

Size: 1.35 KB

Versions: 19

Compression:

Stored size: 1.35 KB

Contents

module RailsPerformance

  class Utils
    # date key in redis store
    def Utils.cache_key(now = Date.today)
      "date-#{now}"
    end

    # write to current slot
    # time - date -minute
    def Utils.field_key(now = Time.now)
      now.strftime("%H:%M")
    end

    def Utils.fetch_from_redis(query)
      RailsPerformance.log "\n\n   [REDIS QUERY]   -->   #{query}\n\n"

      keys   = RailsPerformance.redis.keys(query)
      return [] if keys.blank?
      values = RailsPerformance.redis.mget(keys)

      RailsPerformance.log "\n\n   [FOUND]   -->   #{values.size}\n\n"

      [keys, values]
    end

    def Utils.save_to_redis(key, value, expire = RailsPerformance.duration.to_i)
      # TODO think here if add return
      #return if value.empty?

      RailsPerformance.log "  [SAVE]    key  --->  #{key}\n"
      RailsPerformance.log "  [SAVE]    value  --->  #{value.to_json}\n\n"
      RailsPerformance.redis.set(key, value.to_json, ex: expire.to_i)
    end

    def Utils.days
      (RailsPerformance.duration / 1.day) + 1
    end

    def Utils.median(array)
      sorted = array.sort
      size   = sorted.size
      center = size / 2

      if size == 0
        nil
      elsif size.even?
        (sorted[center - 1] + sorted[center]) / 2.0
      else
        sorted[center]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rails_performance-1.2.0.alpha4 lib/rails_performance/utils.rb
rails_performance-1.2.0.alpha3 lib/rails_performance/utils.rb
rails_performance-1.2.0.alpha2 lib/rails_performance/utils.rb
rails_performance-1.2.0.alpha1 lib/rails_performance/utils.rb
rails_performance-1.1.0 lib/rails_performance/utils.rb
rails_performance-1.0.5.3 lib/rails_performance/utils.rb
rails_performance-1.0.5.2 lib/rails_performance/utils.rb
rails_performance-1.0.5.1 lib/rails_performance/utils.rb
rails_performance-1.0.5 lib/rails_performance/utils.rb
rails_performance-1.0.4 lib/rails_performance/utils.rb
rails_performance-1.0.3 lib/rails_performance/utils.rb
rails_performance-1.0.2 lib/rails_performance/utils.rb
rails_performance-1.0.1 lib/rails_performance/utils.rb
rails_performance-1.0.0 lib/rails_performance/utils.rb
rails_performance-1.0.0.beta5 lib/rails_performance/utils.rb
rails_performance-1.0.0.beta4 lib/rails_performance/utils.rb
rails_performance-1.0.0.beta3 lib/rails_performance/utils.rb
rails_performance-1.0.0.beta2 lib/rails_performance/utils.rb
rails_performance-1.0.0.beta1 lib/rails_performance/utils.rb