Skip to content

Commit 574c8f7

Browse files
committed
Revert "Add is_feature_enabled API method (#58)"
This reverts commit 3cd878c.
1 parent cf665ec commit 574c8f7

File tree

5 files changed

+5
-462
lines changed

5 files changed

+5
-462
lines changed

optimizely/decision_service.py

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -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

optimizely/optimizely.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -280,55 +280,6 @@ def get_variation(self, experiment_key, user_id, attributes=None):
280280

281281
return None
282282

283-
def is_feature_enabled(self, feature_key, user_id, attributes=None):
284-
""" Returns true if the feature is enabled for the given user.
285-
286-
Args:
287-
feature_key: The key of the feature for which we are determining if it is enabled or not for the given user.
288-
user_id: ID for user.
289-
attributes: Dict representing user attributes.
290-
291-
Returns:
292-
True if the feature is enabled for the user. False otherwise.
293-
"""
294-
if not self.is_valid:
295-
self.logger.log(enums.LogLevels.ERROR, enums.Errors.INVALID_DATAFILE.format('is_feature_enabled'))
296-
return False
297-
298-
feature = self.config.get_feature_from_key(feature_key)
299-
if not feature:
300-
return False
301-
302-
variation = self.decision_service.get_variation_for_feature(feature, user_id, attributes)
303-
if variation:
304-
self.logger.log(enums.LogLevels.INFO, 'Feature "%s" is enabled for user "%s".' % (feature_key, user_id))
305-
return True
306-
307-
self.logger.log(enums.LogLevels.INFO, 'Feature "%s" is not enabled for user "%s".' % (feature_key, user_id))
308-
return False
309-
310-
def get_enabled_features(self, user_id, attributes=None):
311-
""" Returns the list of features that are enabled for the user.
312-
313-
Args:
314-
user_id: ID for user.
315-
attributes: Dict representing user attributes.
316-
317-
Returns:
318-
A list of the keys of the features that are enabled for the user.
319-
320-
"""
321-
if not self.is_valid:
322-
self.logger.log(enums.LogLevels.ERROR, enums.Errors.INVALID_DATAFILE.format('get_enabled_features'))
323-
return False
324-
325-
enabled_features = []
326-
for feature in self.config.feature_key_map.values():
327-
if self.is_feature_enabled(feature.key, user_id, attributes):
328-
enabled_features.append(feature.key)
329-
330-
return enabled_features
331-
332283
def set_forced_variation(self, experiment_key, user_id, variation_key):
333284
""" Force a user into a variation for a given experiment.
334285

tests/base.py

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -177,66 +177,7 @@ def setUp(self):
177177
'id': '111129'
178178
}]
179179
}],
180-
'groups': [{
181-
'id': '19228',
182-
'policy': 'random',
183-
'experiments': [{
184-
'id': '32222',
185-
'key': 'group_exp_1',
186-
'status': 'Running',
187-
'audienceIds': [],
188-
'layerId': '111183',
189-
'variations': [{
190-
'key': 'group_exp_1_control',
191-
'id': '28901'
192-
}, {
193-
'key': 'group_exp_1_variation',
194-
'id': '28902'
195-
}],
196-
'forcedVariations': {
197-
'user_1': 'group_exp_1_control',
198-
'user_2': 'group_exp_1_control'
199-
},
200-
'trafficAllocation': [{
201-
'entityId': '28901',
202-
'endOfRange': 3000
203-
}, {
204-
'entityId': '28902',
205-
'endOfRange': 9000
206-
}]
207-
}, {
208-
'id': '32223',
209-
'key': 'group_exp_2',
210-
'status': 'Running',
211-
'audienceIds': [],
212-
'layerId': '111184',
213-
'variations': [{
214-
'key': 'group_exp_2_control',
215-
'id': '28905'
216-
}, {
217-
'key': 'group_exp_2_variation',
218-
'id': '28906'
219-
}],
220-
'forcedVariations': {
221-
'user_1': 'group_exp_2_control',
222-
'user_2': 'group_exp_2_control'
223-
},
224-
'trafficAllocation': [{
225-
'entityId': '28905',
226-
'endOfRange': 8000
227-
}, {
228-
'entityId': '28906',
229-
'endOfRange': 10000
230-
}]
231-
}],
232-
'trafficAllocation': [{
233-
'entityId': '32222',
234-
"endOfRange": 3000
235-
}, {
236-
'entityId': '32223',
237-
'endOfRange': 7500
238-
}]
239-
}],
180+
'groups': [],
240181
'attributes': [{
241182
'key': 'test_attribute',
242183
'id': '111094'
@@ -295,18 +236,6 @@ def setUp(self):
295236
'experimentIds': [],
296237
'layerId': '211111',
297238
'variables': [],
298-
}, {
299-
'id': '91113',
300-
'key': 'test_feature_in_group',
301-
'experimentIds': ['32222'],
302-
'layerId': '',
303-
'variables': [],
304-
}, {
305-
'id': '91114',
306-
'key': 'test_feature_in_experiment_and_rollout',
307-
'experimentIds': ['111127'],
308-
'layerId': '211111',
309-
'variables': [],
310239
}]
311240
}
312241

0 commit comments

Comments
 (0)