@@ -38,41 +38,41 @@ def __init__(self):
3838 def _generate_unsigned_hash_code_32_bit (self , bucketing_id ):
3939 """ Helper method to retrieve hash code.
4040
41- Args:
42- bucketing_id: ID for bucketing.
41+ Args:
42+ bucketing_id: ID for bucketing.
4343
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+ """
4747
4848 # Adjusting MurmurHash code to be unsigned
4949 return mmh3 .hash (bucketing_id , self .bucket_seed ) & UNSIGNED_MAX_32_BIT_VALUE
5050
5151 def _generate_bucket_value (self , bucketing_id ):
5252 """ Helper function to generate bucket value in half-closed interval [0, MAX_TRAFFIC_VALUE).
5353
54- Args:
55- bucketing_id: ID for bucketing.
54+ Args:
55+ bucketing_id: ID for bucketing.
5656
57- Returns:
58- Bucket value corresponding to the provided bucketing ID.
59- """
57+ Returns:
58+ Bucket value corresponding to the provided bucketing ID.
59+ """
6060
6161 ratio = float (self ._generate_unsigned_hash_code_32_bit (bucketing_id )) / MAX_HASH_VALUE
6262 return math .floor (ratio * MAX_TRAFFIC_VALUE )
6363
6464 def find_bucket (self , project_config , bucketing_id , parent_id , traffic_allocations ):
6565 """ Determine entity based on bucket value and traffic allocations.
6666
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.
7272
73- Returns:
74- Entity ID which may represent experiment or variation.
75- """
73+ Returns:
74+ Entity ID which may represent experiment or variation.
75+ """
7676
7777 bucketing_key = BUCKETING_ID_TEMPLATE .format (bucketing_id = bucketing_id , parent_id = parent_id )
7878 bucketing_number = self ._generate_bucket_value (bucketing_key )
@@ -90,20 +90,21 @@ def find_bucket(self, project_config, bucketing_id, parent_id, traffic_allocatio
9090 def bucket (self , project_config , experiment , user_id , bucketing_id ):
9191 """ For a given experiment and bucketing ID determines variation to be shown to user.
9292
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.
9898
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+ """
102102
103103 if not experiment :
104104 return None
105105
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.
107108 if experiment .groupPolicy in GROUP_POLICIES :
108109 group = project_config .get_group (experiment .groupId )
109110
@@ -131,10 +132,6 @@ def bucket(self, project_config, experiment, user_id, bucketing_id):
131132 variation_id = self .find_bucket (project_config , bucketing_id , experiment .id , experiment .trafficAllocation )
132133 if variation_id :
133134 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- )
137135 return variation
138136
139- project_config .logger .info ('User "%s" is in no variation.' % user_id )
140137 return None
0 commit comments