Class: Turnstile::Sampler

Inherits:
Object
  • Object
show all
Defined in:
lib/turnstile/sampler.rb

Instance Method Summary collapse

Instance Method Details

#extrapolate(n) ⇒ Object



3
4
5
# File 'lib/turnstile/sampler.rb', line 3

def extrapolate(n)
  (n * 100.0 / sampling_rate).to_i
end

#sample(uid) ⇒ Object

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



10
11
12
# File 'lib/turnstile/sampler.rb', line 10

def sample(uid)
  ((uid.hash + Time.now.day) % 100) < sampling_rate
end