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