Skip to content

Commit fa77cca

Browse files
Merge branch 'farhan-anjum/FSSDK-11175-add-decision-service-methods-for-cmab' into farhan-anjum/FSSDK-11184-update-impression-event-for-cmab
2 parents 088f4af + b901c5f commit fa77cca

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

optimizely/optimizely.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from .decision.optimizely_decide_option import OptimizelyDecideOption
3131
from .decision.optimizely_decision import OptimizelyDecision
3232
from .decision.optimizely_decision_message import OptimizelyDecisionMessage
33-
from .decision_service import Decision
33+
from .decision_service import Decision, VariationResult
3434
from .error_handler import NoOpErrorHandler, BaseErrorHandler
3535
from .event import event_factory, user_event_factory
3636
from .event.event_processor import BatchEventProcessor, BaseEventProcessor
@@ -538,8 +538,10 @@ def activate(self, experiment_key: str, user_id: str, attributes: Optional[UserA
538538
self.logger.error(enums.Errors.INVALID_PROJECT_CONFIG.format('activate'))
539539
return None
540540

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
543545
if not variation_key:
544546
self.logger.info(f'Not activating user "{user_id}".')
545547
return None
@@ -615,17 +617,18 @@ def track(
615617

616618
def get_variation(
617619
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.
620623
621624
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.
625628
626629
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.
629632
"""
630633

631634
if not self.is_valid:
@@ -678,7 +681,7 @@ def get_variation(
678681
{'experiment_key': experiment_key, 'variation_key': variation_key},
679682
)
680683

681-
return variation_key
684+
return variation_result
682685

683686
def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optional[UserAttributes] = None) -> bool:
684687
""" Returns true if the feature is enabled for the given user.

0 commit comments

Comments
 (0)