-
Notifications
You must be signed in to change notification settings - Fork 36
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
Refact: Refactored Forced decision #365
Refact: Refactored Forced decision #365
Conversation
@@ -100,6 +100,7 @@ def __init__(self, datafile, logger, error_handler): | |||
self.variation_variable_usage_map = {} | |||
self.variation_id_map_by_experiment_id = {} | |||
self.variation_key_map_by_experiment_id = {} | |||
self.flag_variations_map = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
holding this PR for now...
optimizely/project_config.py
Outdated
@@ -215,6 +195,28 @@ def get_rollout_experiments(self, rollout): | |||
|
|||
return rollout_experiments | |||
|
|||
def get_rules_for_flag(self, feature_flag): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't make sense to add this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One change suggested
optimizely/project_config.py
Outdated
if rollout: | ||
rollout_experiments = rollout.experiments | ||
for exp in rollout_experiments: | ||
rules.append(self.experiment_id_map[exp['id']]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand experiment_id_map is for ab-tests only, not including rollout rules. Did it pass our tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All unit tests and FSC is passing.
optimizely/project_config.py
Outdated
@@ -120,46 +121,25 @@ def __init__(self, datafile, logger, error_handler): | |||
) | |||
|
|||
self.feature_key_map = self._generate_key_map(self.feature_flags, 'key', entities.FeatureFlag) | |||
|
|||
self.flag_variations_map = self.generate_feature_variation_map(self.feature_flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line 103
optimizely/decision_service.py
Outdated
|
||
if experiment: | ||
# variation, variation_reasons = self.get_variation_from_experiment_rule( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments overall looks good.
optimizely/decision_service.py
Outdated
|
||
if experiment: | ||
# variation, variation_reasons = self.get_variation_from_experiment_rule( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this commented code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing this code with travis. Will remove it on finalization.
optimizely/project_config.py
Outdated
|
||
if rollout and rollout.experiments: | ||
experiments.extend(rollout_experiments) | ||
# Dict containing map of experiment ID to feature ID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Dict containing map of experiment ID to feature ID. | |
# Dictionary containing dictionary of experiment ID to feature ID. |
# Dict containing map of experiment ID to feature ID. | ||
# for checking that experiment is a feature experiment or not. | ||
self.experiment_feature_map = {} | ||
for feature in self.feature_key_map.values(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we running this loop again see line 127 can we reuse it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All lgtm, seems a few tests are failing in CI for pypy3, even after rerunning several times. I dont see this as a concern right now and can be addressed later as this seems to be a common issue with these versions of Python.
true. |
* add maps to project config * initial code * feat: add remaining implementation * WIP: addressed implementation PR comments and fixed failing unit tests * Fixed lint errors * fix failing tests in py 3.5 * fixed failing logger import for Py2 * add OptimizelyDecisionContext and OptmizelyForcedDecisions * testcases added * Update optimizely/optimizely_user_context.py Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com> * Update optimizely/optimizely_user_context.py Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com> * Update optimizely/optimizely_user_context.py Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com> * make rule key optional in OptimizelyDecisionContext * Mutex lock and testcases added * Update optimizely/optimizely_user_context.py Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com> * use get() vs [] in remove_forced_decision * add missing colon * fix displaying reasons * Update optimizely/optimizely.py Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com> * address PR comments * more PR review fixes * fixed few more PR comments * added bucket reasons * FSC fixes * addressed more PR comments, fixed FSC test failuer about impressin events * address more PR comments * use is_valid check on opti client * addressed more PR comments * reasons and key name fixed * create get_default method for empty experiment object * fixed further PR comments * fix logger so we use the top logger in optimizely client * Refact: Refactored Forced decision (#365) * project config refactor * use existing loop to generate flag_variation_map * get_variation_from_experiment_rule and get_variation_from_delivery_rule removed * fsc test fix * comment addressed * commented code removed * comments from main forced decision PR resolved Co-authored-by: ozayr-zaviar <uzairzaviar@gmail.com> * coupl of corrections * remove check on config * remove redundant import * remove redundant test about invalid datafile * add reasons to return Co-authored-by: ozayr-zaviar <uzairzaviar@gmail.com> Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com> Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com> Co-authored-by: msohailhussain <mirza.sohailhussain@gmail.com>
Summary
get_variation_from_experiment_rule
andget_variation_from_delivery_rule
from decision service.flag_variations_map
logic improved using existing loops and removedget_all_variations_for_each_rule
.Test plan
All FSC and unit tests should pass