|
30 | 30 | from .decision.optimizely_decide_option import OptimizelyDecideOption
|
31 | 31 | from .decision.optimizely_decision import OptimizelyDecision
|
32 | 32 | from .decision.optimizely_decision_message import OptimizelyDecisionMessage
|
33 |
| -from .decision_service import Decision |
| 33 | +from .decision_service import Decision, VariationResult |
34 | 34 | from .error_handler import NoOpErrorHandler, BaseErrorHandler
|
35 | 35 | from .event import event_factory, user_event_factory
|
36 | 36 | from .event.event_processor import BatchEventProcessor, BaseEventProcessor
|
@@ -538,8 +538,10 @@ def activate(self, experiment_key: str, user_id: str, attributes: Optional[UserA
|
538 | 538 | self.logger.error(enums.Errors.INVALID_PROJECT_CONFIG.format('activate'))
|
539 | 539 | return None
|
540 | 540 |
|
541 |
| - variation_key = self.get_variation(experiment_key, user_id, attributes) |
542 |
| - |
| 541 | + variation_result = self.get_variation(experiment_key, user_id, attributes) |
| 542 | + variation_key = None |
| 543 | + if variation_result: |
| 544 | + variation_key = variation_result['variation'].key |
543 | 545 | if not variation_key:
|
544 | 546 | self.logger.info(f'Not activating user "{user_id}".')
|
545 | 547 | return None
|
@@ -615,17 +617,18 @@ def track(
|
615 | 617 |
|
616 | 618 | def get_variation(
|
617 | 619 | self, experiment_key: str, user_id: str, attributes: Optional[UserAttributes] = None
|
618 |
| - ) -> Optional[str]: |
619 |
| - """ Gets variation where user will be bucketed. |
| 620 | + ) -> Optional[VariationResult]: |
| 621 | + """ |
| 622 | + Returns the variation result for the given user in the specified experiment. |
620 | 623 |
|
621 | 624 | Args:
|
622 |
| - experiment_key: Experiment for which user variation needs to be determined. |
623 |
| - user_id: ID for user. |
624 |
| - attributes: Dict representing user attributes. |
| 625 | + experiment_key: The key identifying the experiment. |
| 626 | + user_id: The user ID. |
| 627 | + attributes: Optional dictionary of user attributes. |
625 | 628 |
|
626 | 629 | Returns:
|
627 |
| - Variation key representing the variation the user will be bucketed in. |
628 |
| - None if user is not in experiment or if experiment is not Running. |
| 630 | + A VariationResult object containing the variation assigned to the user, or None if the user is not |
| 631 | + bucketed into any variation or the experiment is not running. |
629 | 632 | """
|
630 | 633 |
|
631 | 634 | if not self.is_valid:
|
@@ -678,7 +681,7 @@ def get_variation(
|
678 | 681 | {'experiment_key': experiment_key, 'variation_key': variation_key},
|
679 | 682 | )
|
680 | 683 |
|
681 |
| - return variation_key |
| 684 | + return variation_result |
682 | 685 |
|
683 | 686 | def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optional[UserAttributes] = None) -> bool:
|
684 | 687 | """ Returns true if the feature is enabled for the given user.
|
|
0 commit comments