Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
88b4f1e
update: integrate CMAB components into OptimizelyFactory
FarhanAnjum-opti Jun 4, 2025
2563c7b
update: add cmab_service parameter to Optimizely constructor for CMAB…
FarhanAnjum-opti Jun 4, 2025
fac8946
update: add docstring to DefaultCmabService class for improved docume…
FarhanAnjum-opti Jun 4, 2025
f74bc8c
update: implement CMAB support in bucketer and decision service, reve…
FarhanAnjum-opti Jun 13, 2025
6d1f73d
linting fix
FarhanAnjum-opti Jun 13, 2025
91d53b6
update: add cmab_uuid handling in DecisionService and related tests
FarhanAnjum-opti Jun 16, 2025
3eb755f
- updated function bucket_to_entity_id
FarhanAnjum-opti Jun 16, 2025
a5e4993
update: add None parameter to Decision constructor in user context tests
FarhanAnjum-opti Jun 16, 2025
c1cd97a
update: enhance CMAB decision handling and add related tests
FarhanAnjum-opti Jun 16, 2025
fd7c723
update: fix logger message formatting in CMAB experiment tests
FarhanAnjum-opti Jun 16, 2025
ec19c3b
mypy fix
FarhanAnjum-opti Jun 16, 2025
029262d
update: refine traffic allocation type hints and key naming in bucket…
FarhanAnjum-opti Jun 16, 2025
180fdee
update: remove unused import of cast in bucketer.py
FarhanAnjum-opti Jun 16, 2025
cd5ba39
update: fix return type for numeric_metric_value in get_numeric_value…
FarhanAnjum-opti Jun 16, 2025
92a3258
update: specify type hint for numeric_metric_value in get_numeric_val…
FarhanAnjum-opti Jun 16, 2025
fe100cb
update: fix logger reference in DefaultCmabClient initialization and …
FarhanAnjum-opti Jun 17, 2025
60a4ada
update: enhance error logging for CMAB fetch failures with detailed m…
FarhanAnjum-opti Jun 20, 2025
265d82b
update: enhance decision result handling by introducing VariationResu…
FarhanAnjum-opti Jun 20, 2025
6ca1102
update: refactor get_variation return structure and change tests acco…
FarhanAnjum-opti Jun 20, 2025
c2b3d96
-Error propagated to optimizely.py
FarhanAnjum-opti Jun 23, 2025
b901c5f
update: modify get_variation to return VariationResult and adjust rel…
FarhanAnjum-opti Jun 27, 2025
d2fc631
update: unit test fixes
FarhanAnjum-opti Jun 27, 2025
b9a8555
Revert "update: unit test fixes"
FarhanAnjum-opti Jun 30, 2025
a129854
Revert "update: modify get_variation to return VariationResult and ad…
FarhanAnjum-opti Jun 30, 2025
c637878
update: enhance decision service to handle error states and improve b…
FarhanAnjum-opti Jul 3, 2025
0bc4fbd
update: remove debug print statement from Optimizely class
FarhanAnjum-opti Jul 3, 2025
fcdad1f
update: enhance bucketing logic to support CMAB traffic allocations
FarhanAnjum-opti Jul 3, 2025
aca7df4
update: improve error logging for CMAB decision fetch failures
FarhanAnjum-opti Jul 3, 2025
72955a0
update: improve logging and error handling in bucketer and decision s…
FarhanAnjum-opti Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update: modify get_variation to return VariationResult and adjust rel…
…ated logic for improved variation handling
  • Loading branch information
FarhanAnjum-opti committed Jun 27, 2025
commit b901c5fae4b76b51d038ffbc1f9350153bf26a7f
25 changes: 14 additions & 11 deletions optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .decision.optimizely_decide_option import OptimizelyDecideOption
from .decision.optimizely_decision import OptimizelyDecision
from .decision.optimizely_decision_message import OptimizelyDecisionMessage
from .decision_service import Decision
from .decision_service import Decision, VariationResult
from .error_handler import NoOpErrorHandler, BaseErrorHandler
from .event import event_factory, user_event_factory
from .event.event_processor import BatchEventProcessor, BaseEventProcessor
Expand Down Expand Up @@ -535,8 +535,10 @@ def activate(self, experiment_key: str, user_id: str, attributes: Optional[UserA
self.logger.error(enums.Errors.INVALID_PROJECT_CONFIG.format('activate'))
return None

variation_key = self.get_variation(experiment_key, user_id, attributes)

variation_result = self.get_variation(experiment_key, user_id, attributes)
variation_key = None
if variation_result:
variation_key = variation_result['variation'].key
if not variation_key:
self.logger.info(f'Not activating user "{user_id}".')
return None
Expand Down Expand Up @@ -612,17 +614,18 @@ def track(

def get_variation(
self, experiment_key: str, user_id: str, attributes: Optional[UserAttributes] = None
) -> Optional[str]:
""" Gets variation where user will be bucketed.
) -> Optional[VariationResult]:
"""
Returns the variation result for the given user in the specified experiment.

Args:
experiment_key: Experiment for which user variation needs to be determined.
user_id: ID for user.
attributes: Dict representing user attributes.
experiment_key: The key identifying the experiment.
user_id: The user ID.
attributes: Optional dictionary of user attributes.

Returns:
Variation key representing the variation the user will be bucketed in.
None if user is not in experiment or if experiment is not Running.
A VariationResult object containing the variation assigned to the user, or None if the user is not
bucketed into any variation or the experiment is not running.
"""

if not self.is_valid:
Expand Down Expand Up @@ -675,7 +678,7 @@ def get_variation(
{'experiment_key': experiment_key, 'variation_key': variation_key},
)

return variation_key
return variation_result

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