|
15 | 15 | import sys |
16 | 16 |
|
17 | 17 | from . import decision_service |
18 | | -from . import entities |
19 | 18 | from . import event_builder |
20 | 19 | from . import exceptions |
21 | 20 | from . import project_config |
22 | 21 | from .error_handler import NoOpErrorHandler as noop_error_handler |
23 | 22 | from .event_dispatcher import EventDispatcher as default_event_dispatcher |
24 | 23 | from .helpers import enums |
| 24 | +from .helpers import event_tag_utils |
25 | 25 | from .helpers import validator |
26 | 26 | from .logger import NoOpLogger as noop_logger |
27 | 27 | from .logger import SimpleLogger |
@@ -182,64 +182,6 @@ def _send_impression_event(self, experiment, variation, user_id, attributes): |
182 | 182 | self.notification_center.send_notifications(enums.NotificationTypes.ACTIVATE, |
183 | 183 | experiment, user_id, attributes, variation, impression_event) |
184 | 184 |
|
185 | | - def _get_feature_variable_for_type(self, feature_key, variable_key, variable_type, user_id, attributes): |
186 | | - """ Helper method to determine value for a certain variable attached to a feature flag based on type of variable. |
187 | | -
|
188 | | - Args: |
189 | | - feature_key: Key of the feature whose variable's value is being accessed. |
190 | | - variable_key: Key of the variable whose value is to be accessed. |
191 | | - variable_type: Type of variable which could be one of boolean/double/integer/string. |
192 | | - user_id: ID for user. |
193 | | - attributes: Dict representing user attributes. |
194 | | -
|
195 | | - Returns: |
196 | | - Value of the variable. None if: |
197 | | - - Feature key is invalid. |
198 | | - - Variable key is invalid. |
199 | | - - Mismatch with type of variable. |
200 | | - """ |
201 | | - |
202 | | - feature_flag = self.config.get_feature_from_key(feature_key) |
203 | | - if not feature_flag: |
204 | | - return None |
205 | | - |
206 | | - variable = self.config.get_variable_for_feature(feature_key, variable_key) |
207 | | - if not variable: |
208 | | - return None |
209 | | - |
210 | | - # Return None if type differs |
211 | | - if variable.type != variable_type: |
212 | | - self.logger.log( |
213 | | - enums.LogLevels.WARNING, |
214 | | - 'Requested variable type "%s", but variable is of type "%s". ' |
215 | | - 'Use correct API to retrieve value. Returning None.' % (variable_type, variable.type) |
216 | | - ) |
217 | | - return None |
218 | | - |
219 | | - decision = self.decision_service.get_variation_for_feature(feature_flag, user_id, attributes) |
220 | | - if decision.variation: |
221 | | - variable_value = self.config.get_variable_value_for_variation(variable, decision.variation) |
222 | | - self.logger.log( |
223 | | - enums.LogLevels.INFO, |
224 | | - 'Value for variable "%s" of feature flag "%s" is %s for user "%s".' % ( |
225 | | - variable_key, feature_key, variable_value, user_id |
226 | | - )) |
227 | | - else: |
228 | | - variable_value = variable.defaultValue |
229 | | - self.logger.log( |
230 | | - enums.LogLevels.INFO, |
231 | | - 'User "%s" is not in any variation or rollout rule. ' |
232 | | - 'Returning default value for variable "%s" of feature flag "%s".' % (user_id, variable_key, feature_key) |
233 | | - ) |
234 | | - |
235 | | - try: |
236 | | - actual_value = self.config.get_typecast_value(variable_value, variable_type) |
237 | | - except: |
238 | | - self.logger.log(enums.LogLevels.ERROR, 'Unable to cast value. Returning None.') |
239 | | - actual_value = None |
240 | | - |
241 | | - return actual_value |
242 | | - |
243 | 185 | def activate(self, experiment_key, user_id, attributes=None): |
244 | 186 | """ Buckets visitor and sends impression event to Optimizely. |
245 | 187 |
|
@@ -413,82 +355,6 @@ def get_enabled_features(self, user_id, attributes=None): |
413 | 355 |
|
414 | 356 | return enabled_features |
415 | 357 |
|
416 | | - def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None): |
417 | | - """ Returns value for a certain boolean variable attached to a feature flag. |
418 | | -
|
419 | | - Args: |
420 | | - feature_key: Key of the feature whose variable's value is being accessed. |
421 | | - variable_key: Key of the variable whose value is to be accessed. |
422 | | - user_id: ID for user. |
423 | | - attributes: Dict representing user attributes. |
424 | | -
|
425 | | - Returns: |
426 | | - Boolean value of the variable. None if: |
427 | | - - Feature key is invalid. |
428 | | - - Variable key is invalid. |
429 | | - - Mismatch with type of variable. |
430 | | - """ |
431 | | - |
432 | | - variable_type = entities.Variable.Type.BOOLEAN |
433 | | - return self._get_feature_variable_for_type(feature_key, variable_key, variable_type, user_id, attributes) |
434 | | - |
435 | | - def get_feature_variable_double(self, feature_key, variable_key, user_id, attributes=None): |
436 | | - """ Returns value for a certain double variable attached to a feature flag. |
437 | | -
|
438 | | - Args: |
439 | | - feature_key: Key of the feature whose variable's value is being accessed. |
440 | | - variable_key: Key of the variable whose value is to be accessed. |
441 | | - user_id: ID for user. |
442 | | - attributes: Dict representing user attributes. |
443 | | -
|
444 | | - Returns: |
445 | | - Double value of the variable. None if: |
446 | | - - Feature key is invalid. |
447 | | - - Variable key is invalid. |
448 | | - - Mismatch with type of variable. |
449 | | - """ |
450 | | - |
451 | | - variable_type = entities.Variable.Type.DOUBLE |
452 | | - return self._get_feature_variable_for_type(feature_key, variable_key, variable_type, user_id, attributes) |
453 | | - |
454 | | - def get_feature_variable_integer(self, feature_key, variable_key, user_id, attributes=None): |
455 | | - """ Returns value for a certain integer variable attached to a feature flag. |
456 | | -
|
457 | | - Args: |
458 | | - feature_key: Key of the feature whose variable's value is being accessed. |
459 | | - variable_key: Key of the variable whose value is to be accessed. |
460 | | - user_id: ID for user. |
461 | | - attributes: Dict representing user attributes. |
462 | | -
|
463 | | - Returns: |
464 | | - Integer value of the variable. None if: |
465 | | - - Feature key is invalid. |
466 | | - - Variable key is invalid. |
467 | | - - Mismatch with type of variable. |
468 | | - """ |
469 | | - |
470 | | - variable_type = entities.Variable.Type.INTEGER |
471 | | - return self._get_feature_variable_for_type(feature_key, variable_key, variable_type, user_id, attributes) |
472 | | - |
473 | | - def get_feature_variable_string(self, feature_key, variable_key, user_id, attributes=None): |
474 | | - """ Returns value for a certain string variable attached to a feature. |
475 | | -
|
476 | | - Args: |
477 | | - feature_key: Key of the feature whose variable's value is being accessed. |
478 | | - variable_key: Key of the variable whose value is to be accessed. |
479 | | - user_id: ID for user. |
480 | | - attributes: Dict representing user attributes. |
481 | | -
|
482 | | - Returns: |
483 | | - String value of the variable. None if: |
484 | | - - Feature key is invalid. |
485 | | - - Variable key is invalid. |
486 | | - - Mismatch with type of variable. |
487 | | - """ |
488 | | - |
489 | | - variable_type = entities.Variable.Type.STRING |
490 | | - return self._get_feature_variable_for_type(feature_key, variable_key, variable_type, user_id, attributes) |
491 | | - |
492 | 358 | def set_forced_variation(self, experiment_key, user_id, variation_key): |
493 | 359 | """ Force a user into a variation for a given experiment. |
494 | 360 |
|
|
0 commit comments