@@ -38,41 +38,41 @@ def __init__(self):
38
38
def _generate_unsigned_hash_code_32_bit (self , bucketing_id ):
39
39
""" Helper method to retrieve hash code.
40
40
41
- Args:
42
- bucketing_id: ID for bucketing.
41
+ Args:
42
+ bucketing_id: ID for bucketing.
43
43
44
- Returns:
45
- Hash code which is a 32 bit unsigned integer.
46
- """
44
+ Returns:
45
+ Hash code which is a 32 bit unsigned integer.
46
+ """
47
47
48
48
# Adjusting MurmurHash code to be unsigned
49
49
return mmh3 .hash (bucketing_id , self .bucket_seed ) & UNSIGNED_MAX_32_BIT_VALUE
50
50
51
51
def _generate_bucket_value (self , bucketing_id ):
52
52
""" Helper function to generate bucket value in half-closed interval [0, MAX_TRAFFIC_VALUE).
53
53
54
- Args:
55
- bucketing_id: ID for bucketing.
54
+ Args:
55
+ bucketing_id: ID for bucketing.
56
56
57
- Returns:
58
- Bucket value corresponding to the provided bucketing ID.
59
- """
57
+ Returns:
58
+ Bucket value corresponding to the provided bucketing ID.
59
+ """
60
60
61
61
ratio = float (self ._generate_unsigned_hash_code_32_bit (bucketing_id )) / MAX_HASH_VALUE
62
62
return math .floor (ratio * MAX_TRAFFIC_VALUE )
63
63
64
64
def find_bucket (self , project_config , bucketing_id , parent_id , traffic_allocations ):
65
65
""" Determine entity based on bucket value and traffic allocations.
66
66
67
- Args:
68
- project_config: Instance of ProjectConfig.
69
- bucketing_id: ID to be used for bucketing the user.
70
- parent_id: ID representing group or experiment.
71
- traffic_allocations: Traffic allocations representing traffic allotted to experiments or variations.
67
+ Args:
68
+ project_config: Instance of ProjectConfig.
69
+ bucketing_id: ID to be used for bucketing the user.
70
+ parent_id: ID representing group or experiment.
71
+ traffic_allocations: Traffic allocations representing traffic allotted to experiments or variations.
72
72
73
- Returns:
74
- Entity ID which may represent experiment or variation.
75
- """
73
+ Returns:
74
+ Entity ID which may represent experiment or variation.
75
+ """
76
76
77
77
bucketing_key = BUCKETING_ID_TEMPLATE .format (bucketing_id = bucketing_id , parent_id = parent_id )
78
78
bucketing_number = self ._generate_bucket_value (bucketing_key )
@@ -90,20 +90,21 @@ def find_bucket(self, project_config, bucketing_id, parent_id, traffic_allocatio
90
90
def bucket (self , project_config , experiment , user_id , bucketing_id ):
91
91
""" For a given experiment and bucketing ID determines variation to be shown to user.
92
92
93
- Args:
94
- project_config: Instance of ProjectConfig.
95
- experiment: Object representing the experiment for which user is to be bucketed.
96
- user_id: ID for user.
97
- bucketing_id: ID to be used for bucketing the user.
93
+ Args:
94
+ project_config: Instance of ProjectConfig.
95
+ experiment: Object representing the experiment or rollout rule in which user is to be bucketed.
96
+ user_id: ID for user.
97
+ bucketing_id: ID to be used for bucketing the user.
98
98
99
- Returns:
100
- Variation in which user with ID user_id will be put in. None if no variation.
101
- """
99
+ Returns:
100
+ Variation in which user with ID user_id will be put in. None if no variation.
101
+ """
102
102
103
103
if not experiment :
104
104
return None
105
105
106
- # Determine if experiment is in a mutually exclusive group
106
+ # Determine if experiment is in a mutually exclusive group.
107
+ # This will not affect evaluation of rollout rules.
107
108
if experiment .groupPolicy in GROUP_POLICIES :
108
109
group = project_config .get_group (experiment .groupId )
109
110
@@ -131,10 +132,6 @@ def bucket(self, project_config, experiment, user_id, bucketing_id):
131
132
variation_id = self .find_bucket (project_config , bucketing_id , experiment .id , experiment .trafficAllocation )
132
133
if variation_id :
133
134
variation = project_config .get_variation_from_id (experiment .key , variation_id )
134
- project_config .logger .info (
135
- 'User "%s" is in variation "%s" of experiment %s.' % (user_id , variation .key , experiment .key )
136
- )
137
135
return variation
138
136
139
- project_config .logger .info ('User "%s" is in no variation.' % user_id )
140
137
return None
0 commit comments