-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassigner.rb
43 lines (38 loc) · 958 Bytes
/
assigner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Experiment
class Assigner
attr_reader :gate, :scope, :user, :settings
def initialize(gate:, scope:, user:)
@gate = gate
@scope = scope
@user = user
@settings = GATE_KEEPER_GATES_AND_SCOPES_AND_WEIGHTS[gate]
end
def build_range_for_new_user
if scope.exists?(user.id)
in_scope = 1
in_experiment = segment_user_for_experiment
groups = segment_user_for_groups
else
in_scope = 0
in_experiment = 0
groups = [0,0,0]
end
{
arrived: 1,
scope: in_scope,
experiment: in_experiment,
group_a: groups[0],
group_b: groups[1],
group_c: groups[2]
}.values.join()
end
private
def segment_user_for_groups
#for later more complicated experiments
[0,0,0]
end
def segment_user_for_experiment
rand(100) < settings[:weights][:experiment] ? 1 : 0
end
end
end