@@ -119,6 +119,34 @@ def bucket(
119
119
and array of log messages representing decision making.
120
120
*/.
121
121
"""
122
+ variation_id , decide_reasons = self .bucket_to_entity_id (project_config , experiment , user_id , bucketing_id )
123
+ if variation_id :
124
+ variation = project_config .get_variation_from_id_by_experiment_id (experiment .id , variation_id )
125
+ return variation , decide_reasons
126
+
127
+ else :
128
+ message = 'Bucketed into an empty traffic range. Returning nil.'
129
+ project_config .logger .info (message )
130
+ decide_reasons .append (message )
131
+
132
+ return None , decide_reasons
133
+
134
+ def bucket_to_entity_id (
135
+ self , project_config : ProjectConfig ,
136
+ experiment : Experiment , user_id : str , bucketing_id : str
137
+ ) -> tuple [Optional [str ], list [str ]]:
138
+ """
139
+ For a given experiment and bucketing ID determines variation ID to be shown to user.
140
+
141
+ Args:
142
+ project_config: Instance of ProjectConfig.
143
+ experiment: The experiment object (used for group/groupPolicy logic if needed).
144
+ user_id: The user ID string.
145
+ bucketing_id: The bucketing ID string for the user.
146
+
147
+ Returns:
148
+ Tuple of (entity_id or None, list of decide reasons).
149
+ """
122
150
decide_reasons : list [str ] = []
123
151
if not experiment :
124
152
return None , decide_reasons
@@ -151,16 +179,16 @@ def bucket(
151
179
project_config .logger .info (message )
152
180
decide_reasons .append (message )
153
181
182
+ traffic_allocations : list [TrafficAllocation ] = experiment .trafficAllocation
183
+ if experiment .cmab :
184
+ traffic_allocations = [
185
+ {
186
+ "entityId" : "$" ,
187
+ "endOfRange" : experiment .cmab ['trafficAllocation' ]
188
+ }
189
+ ]
154
190
# Bucket user if not in white-list and in group (if any)
155
191
variation_id = self .find_bucket (project_config , bucketing_id ,
156
- experiment .id , experiment .trafficAllocation )
157
- if variation_id :
158
- variation = project_config .get_variation_from_id_by_experiment_id (experiment .id , variation_id )
159
- return variation , decide_reasons
192
+ experiment .id , traffic_allocations )
160
193
161
- else :
162
- message = 'Bucketed into an empty traffic range. Returning nil.'
163
- project_config .logger .info (message )
164
- decide_reasons .append (message )
165
-
166
- return None , decide_reasons
194
+ return variation_id , decide_reasons
0 commit comments