@@ -94,7 +94,7 @@ def get_stored_variation(self, experiment, user_profile):
9494
9595 return None
9696
97- def get_variation (self , experiment , user_id , attributes , ignore_user_profile = False ):
97+ def get_variation (self , experiment , user_id , attributes ):
9898 """ Top-level function to help determine variation user should be put in.
9999
100100 First, check if experiment is running.
@@ -107,7 +107,6 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
107107 experiment_key: Experiment for which user variation needs to be determined.
108108 user_id: ID for user.
109109 attributes: Dict representing user attributes.
110- ignore_user_profile: True to ignore the user profile lookup. Defaults to False.
111110
112111 Returns:
113112 Variation user should see. None if user is not in experiment or experiment is not running.
@@ -130,7 +129,7 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
130129
131130 # Check to see if user has a decision available for the given experiment
132131 user_profile = UserProfile (user_id )
133- if not ignore_user_profile and self .user_profile_service :
132+ if self .user_profile_service :
134133 try :
135134 retrieved_profile = self .user_profile_service .lookup (user_id )
136135 except :
@@ -163,7 +162,7 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
163162
164163 if variation :
165164 # Store this new decision and return the variation for the user
166- if not ignore_user_profile and self .user_profile_service :
165+ if self .user_profile_service :
167166 try :
168167 user_profile .save_variation_for_experiment (experiment .id , variation .id )
169168 self .user_profile_service .save (user_profile .__dict__ )
@@ -174,102 +173,3 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
174173 return variation
175174
176175 return None
177-
178- def get_variation_for_layer (self , layer , user_id , attributes = None , ignore_user_profile = False ):
179- """ Determine which variation the user is in for a given layer.
180- Returns the variation of the first experiment the user qualifies for.
181-
182- Args:
183- layer: Layer for which we are getting the variation.
184- user_id: ID for user.
185- attributes: Dict representing user attributes.
186- ignore_user_profile: True to ignore the user profile lookup. Defaults to False.
187-
188-
189- Returns:
190- Variation the user should see. None if the user is not in any of the layer's experiments.
191- """
192- # Go through each experiment in order and try to get the variation for the user
193- if layer :
194- for experiment_dict in layer .experiments :
195- experiment = self .config .get_experiment_from_key (experiment_dict ['key' ])
196- variation = self .get_variation (experiment , user_id , attributes , ignore_user_profile )
197- if variation :
198- self .logger .log (enums .LogLevels .DEBUG ,
199- 'User "%s" is in variation %s of experiment %s.' % (user_id , variation .key , experiment .key ))
200- # Return as soon as we get a variation
201- return variation
202-
203- return None
204-
205- def get_experiment_in_group (self , group , bucketing_id ):
206- """ Determine which experiment in the group the user is bucketed into.
207-
208- Args:
209- group: The group to bucket the user into.
210- bucketing_id: ID to be used for bucketing the user.
211-
212- Returns:
213- Experiment if the user is bucketed into an experiment in the specified group. None otherwise.
214- """
215-
216- experiment_id = self .bucketer .find_bucket (bucketing_id , group .id , group .trafficAllocation )
217- if experiment_id :
218- experiment = self .config .get_experiment_from_id (experiment_id )
219- if experiment :
220- self .logger .log (enums .LogLevels .INFO ,
221- 'User with bucketing ID "%s" is in experiment %s of group %s.' %
222- (bucketing_id , experiment .key , group .id ))
223- return experiment
224-
225- self .logger .log (enums .LogLevels .INFO ,
226- 'User with bucketing ID "%s" is not in any experiments of group %s.' %
227- (bucketing_id , group .id ))
228-
229- return None
230-
231- def get_variation_for_feature (self , feature , user_id , attributes = None ):
232- """ Returns the variation the user is bucketed in for the given feature.
233-
234- Args:
235- feature: Feature for which we are determining if it is enabled or not for the given user.
236- user_id: ID for user.
237- attributes: Dict representing user attributes.
238-
239- Returns:
240- Variation that the user is bucketed in. None if the user is not in any variation.
241- """
242- variation = None
243- bucketing_id = self ._get_bucketing_id (user_id , attributes )
244-
245- # First check if the feature is in a mutex group
246- if feature .groupId :
247- group = self .config .get_group (feature .groupId )
248- if group :
249- experiment = self .get_experiment_in_group (group , bucketing_id )
250- if experiment and experiment .id in feature .experimentIds :
251- variation = self .get_variation (experiment , user_id , attributes )
252-
253- if variation :
254- self .logger .log (enums .LogLevels .DEBUG ,
255- 'User "%s" is in variation %s of experiment %s.' % (user_id , variation .key , experiment .key ))
256- else :
257- self .logger .log (enums .LogLevels .ERROR , enums .Errors .INVALID_GROUP_ID_ERROR .format ('_get_variation_for_feature' ))
258-
259- # Next check if the feature is being experimented on
260- elif feature .experimentIds :
261- # If an experiment is not in a group, then the feature can only be associated with one experiment
262- experiment = self .config .get_experiment_from_id (feature .experimentIds [0 ])
263- if experiment :
264- variation = self .get_variation (experiment , user_id , attributes )
265-
266- if variation :
267- self .logger .log (enums .LogLevels .DEBUG ,
268- 'User "%s" is in variation %s of experiment %s.' % (user_id , variation .key , experiment .key ))
269-
270- # Next check if user is part of a rollout
271- if not variation and feature .layerId :
272- layer = self .config .get_layer_from_id (feature .layerId )
273- variation = self .get_variation_for_layer (layer , user_id , attributes , ignore_user_profile = True )
274-
275- return variation
0 commit comments