class RailsPerformance::Utils
Public Class Methods
cache_key(now = Date.today)
click to toggle source
date key in redis store
# File lib/rails_performance/utils.rb, line 5 def Utils.cache_key(now = Date.today) "date-#{now}" end
days()
click to toggle source
# File lib/rails_performance/utils.rb, line 36 def Utils.days (RailsPerformance.duration / 1.day) + 1 end
fetch_from_redis(query)
click to toggle source
# File lib/rails_performance/utils.rb, line 15 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
field_key(now = Time.now)
click to toggle source
write to current slot time - date -minute
# File lib/rails_performance/utils.rb, line 11 def Utils.field_key(now = Time.now) now.strftime("%H:%M") end
median(array)
click to toggle source
# File lib/rails_performance/utils.rb, line 40 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
save_to_redis(key, value, expire = RailsPerformance.duration.to_i)
click to toggle source
# File lib/rails_performance/utils.rb, line 27 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