8000 Add forced-decisions APIs to OptimizelyUserContext by Mat001 · Pull Request #361 · optimizely/python-sdk · GitHub
[go: up one dir, main page]

Skip to content

Add forced-decisions APIs to OptimizelyUserContext #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c5d9dae
add maps to project config
Mat001 Sep 9, 2021
17ad742
initial code
Mat001 Sep 15, 2021
cee1fb8
Merge branch 'master' of github.com:optimizely/python-sdk into mpirno…
Mat001 Sep 16, 2021
58977d2
feat: add remaining implementation
Mat001 Oct 1, 2021
340cbce
WIP: addressed implementation PR comments and fixed failing unit tests
Mat001 Oct 19, 2021
c81a425
Fixed lint errors
Mat001 Oct 19, 2021
c89bc3c
fix failing tests in py 3.5
Mat001 Oct 20, 2021
2fe78ab
fixed failing logger import for Py2
Mat001 Oct 20, 2021
d80c555
add OptimizelyDecisionContext and OptmizelyForcedDecisions
Mat001 Oct 27, 2021
5ed2fb4
testcases added
ozayr-zaviar Nov 2, 2021
6003fdc
Update optimizely/optimizely_user_context.py
Mat001 Nov 2, 2021
e4dc745
Update optimizely/optimizely_user_context.py
Mat001 Nov 2, 2021
d75f389
Update optimizely/optimizely_user_context.py
Mat001 Nov 2, 2021
68146a1
make rule key optional in OptimizelyDecisionContext
Mat001 Nov 2, 2021
a261899
Mutex lock and testcases added
ozayr-zaviar Nov 3, 2021
a837f03
Merge branch 'master' into mpirnovar/forced_decisions
Mat001 Nov 3, 2021
de4a31c
Update optimizely/optimizely_user_context.py
Mat001 Nov 5, 2021
0c52707
use get() vs [] in remove_forced_decision
Mat001 Nov 5, 2021
4116b43
add self lock and keys(0
Mat001 Nov 5, 2021
081cd79
add missing colon
Mat001 Nov 7, 2021
e061abc
fix displaying reasons
Mat001 Nov 11, 2021
337f8d9
Update optimizely/optimizely.py
Mat001 Nov 12, 2021
a71f50e
address PR comments
Mat001 Nov 16, 2021
981cbe5
updating
Mat001 Nov 16, 2021
94d5af9
more PR review fixes
Mat001 Nov 17, 2021
e9cd304
fixed few more PR comments
Mat001 Nov 17, 2021
2dff4c6
added bucket reasons
Mat001 Nov 17, 2021
e2f1db3
FSC fixes
ozayr-zaviar Nov 18, 2021
6849c33
addressed more PR comments, fixed FSC test failuer about impressin ev…
Mat001 Nov 19, 2021
55fe98f
address more PR comments
Mat001 Nov 19, 2021
94a0c26
use is_valid check on opti client
Mat001 Nov 19, 2021
e5aaccb
addressed more PR comments
Mat001 Nov 19, 2021
44373e9
reasons and key name fixed
ozayr-zaviar Nov 22, 2021
e6c1772
create get_default method for empty experiment object
Mat001 Nov 22, 2021
ab40d9e
fixed further PR comments
Mat001 Nov 24, 2021
795b41a
fix logger so we use the top logger in optimizely client
Mat001 Dec 1, 2021
dbbc051
Refact: Refactored Forced decision (#365)
msohailhussain Dec 2, 2021
75fe2bb
coupl of corrections
Mat001 Dec 2, 2021
243d447
remove check on config
Mat001 Dec 2, 2021
1010ece
remove redundant import
Mat001 Dec 2, 2021
17efc27
remove redundant test about invalid datafile
Mat001 Dec 3, 2021
201548f
add reasons to return
Mat001 Dec 4, 2021
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
fixed few more PR comments
  • Loading branch information
Mat001 committed Nov 17, 2021
commit e9cd3049b6857b864c51cbca247ecc8e9710e416
18 changes: 11 additions & 7 deletions optimizely/decision_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ def get_variation_for_rollout(self, project_config, feature, user, options):
if not feature:
return Decision(None, None, enums.DecisionSources.ROLLOUT), decide_reasons

if not feature.rolloutId:
return Decision(None, None, enums.DecisionSources.ROLLOUT), decide_reasons

rollout = project_config.get_rollout_from_id(feature.rolloutId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protect from when feature.rolloutId is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge 349 - 354?


if not rollout:
Expand All @@ -375,7 +378,11 @@ def get_variation_for_rollout(self, project_config, feature, user, options):

decide_reasons += reasons_received

if decision_response:
if not decision_response:
# TODO - MATJAZ - careful - check how this exists the loop and terminates properly
# when return is hit
return Decision(None, None, enums.DecisionSources.ROLLOUT), decide_reasons
else:
variation, skip_to_everyone_else = decision_response

if variation:
Expand Down Expand Up @@ -431,6 +438,7 @@ def get_variation_from_delivery_rule(self, config, feature, rules, rule_index, u
config: Instance of ProjectConfig.
flag_key: Key of the flag.
rules: Experiment rule.
rule_index: integer index of the rule in the list.
user: ID and attributes for user.
options: Decide options.

Expand Down Expand Up @@ -459,7 +467,8 @@ def get_variation_from_delivery_rule(self, config, feature, rules, rule_index, u
# regular decision
user_id = user.user_id
attributes = user.get_user_attributes()
bucketing_id = self._get_bucketing_id(user_id, attributes)
# TODO this bucket_reasons go somewhere?
bucketing_id, bucket_reasons = self._get_bucketing_id(user_id, attributes)

everyone_else = (rule_index == len(rules) - 1)
logging_key = "Everyone Else" if everyone_else else str(rule_index + 1)
Expand All @@ -473,7 +482,6 @@ def get_variation_from_delivery_rule(self, config, feature, rules, rule_index, u
decide_reasons += reasons_received_audience

if audience_decision_response:

message = 'User "{}" meets audience conditions for targeting rule {}.'.format(user_id, logging_key)
self.logger.debug(message)
decide_reasons.append(message)
Expand Down Expand Up @@ -535,10 +543,6 @@ def get_variation_for_feature(self, project_config, feature, user_context, ignor
if feature.rolloutId:
return self.get_variation_for_rollout(project_config, feature, user_context, ignore_user_profile)

# check if not part of experiment
if not feature.experimentIds:
return Decision(None, None, enums.DecisionSources.FEATURE_TEST), decide_reasons

# check if not part of rollout
if not feature.rolloutId:
return Decision(None, None, enums.DecisionSources.ROLLOUT), decide_reasons
4 changes: 2 additions & 2 deletions optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,8 @@ def _decide(self, user_context, key, decide_options=None):
else:
# Regular decision
decision, decision_reasons = self.decision_service.get_variation_for_feature(config,
feature_flag,
user_context, ignore_ups)
feature_flag,
user_context, ignore_ups)

reasons += decision_reasons

Expand Down
2 changes: 1 addition & 1 deletion optimizely/project_config.py