class Turnstile::Sampler
Public Instance Methods
extrapolate(n)
click to toggle source
# File lib/turnstile/sampler.rb, line 8 def extrapolate(n) (n * 100.0 / sampling_rate).to_i end
sample(uid)
click to toggle source
this method uses a unique string to integer hashing (object->hash) sampling shifts depending on the day of the month so that sampling does not stick to the same people all the time
# File lib/turnstile/sampler.rb, line 15 def sample(uid) ((uid.hash + Time.now.day) % 100) < sampling_rate end
sampling?()
click to toggle source
# File lib/turnstile/sampler.rb, line 19 def sampling? sampling_rate && sampling_rate <= 100 && sampling_rate >= 0 end
sampling_rate()
click to toggle source
# File lib/turnstile/sampler.rb, line 23 def sampling_rate config.sampling_rate end