-
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
Merged
msohailhussain
merged 7 commits into
mpirnovar/forced_decisions
from
uzair/project-config-refactor
Dec 2, 2021
+116
−184
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a9f6b12
project config refactor
ozayr-zaviar 3955db0
use existing loop to generate flag_variation_map
ozayr-zaviar 6768457
get_variation_from_experiment_rule and get_variation_from_delivery_ru…
ozayr-zaviar 981ab70
fsc test fix
ozayr-zaviar dcf0a48
comment addressed
ozayr-zaviar ed543fa
commented code removed
ozayr-zaviar 39ab0b0
comments from main forced decision PR resolved
ozayr-zaviar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = {} | ||
|
||
for experiment in self.experiment_id_map.values(): | ||
self.experiment_key_map[experiment.key] = experiment | ||
|
@@ -121,45 +122,38 @@ def __init__(self, datafile, logger, error_handler): | |
|
||
self.feature_key_map = self._generate_key_map(self.feature_flags, 'key', entities.FeatureFlag) | ||
|
||
# As we cannot create json variables in datafile directly, here we convert | ||
# the variables of string type and json subType to json type | ||
# This is needed to fully support json variables | ||
# Dictionary containing dictionary of experiment ID to feature ID. | ||
# for checking that experiment is a feature experiment or not. | ||
self.experiment_feature_map = {} | ||
self.flag_rules_map = {} | ||
|
||
for feature_key, feature_value in self.feature_key_map.items(): | ||
for variable in self.feature_key_map[feature_key].variables: | ||
for feature in self.feature_key_map.values(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
# As we cannot create json variables in datafile directly, here we convert | ||
# the variables of string type and json subType to json type | ||
# This is needed to fully support json variables | ||
for variable in self.feature_key_map[feature.key].variables: | ||
sub_type = variable.get('subType', '') | ||
if variable['type'] == entities.Variable.Type.STRING and sub_type == entities.Variable.Type.JSON: | ||
variable['type'] = entities.Variable.Type.JSON | ||
|
||
# loop over features=flags already happening | ||
# get feature variables for eacg flag/feature | ||
feature_value.variables = self._generate_key_map(feature_value.variables, 'key', entities.Variable) | ||
for exp_id in feature_value.experimentIds: | ||
# Add this experiment in experiment-feature map. | ||
self.experiment_feature_map[exp_id] = [feature_value.id] | ||
|
||
# all rules(experiment rules and delivery rules) for each flag | ||
for flag in self.feature_flags: | ||
experiments = [] | ||
if len(flag['experimentIds']) > 0: | ||
for exp_id in flag['experimentIds']: | ||
experiments.append(self.experiment_id_map[exp_id]) | ||
if not flag['rolloutId'] == '': | ||
rollout = self.rollout_id_map[flag['rolloutId']] | ||
|
||
rollout_experiments = self.get_rollout_experiments(rollout) | ||
|
||
if rollout and rollout.experiments: | ||
experiments.extend(rollout_experiments) | ||
feature.variables = self._generate_key_map(feature.variables, 'key', entities.Variable) | ||
|
||
self.flag_rules_map[flag['key']] = experiments | ||
rules = [] | ||
variations = [] | ||
for exp_id in feature.experimentIds: | ||
# Add this experiment in experiment-feature map. | ||
self.experiment_feature_map[exp_id] = [feature.id] | ||
rules.append(self.experiment_id_map[exp_id]) | ||
rollout = None if len(feature.rolloutId) == 0 else self.rollout_id_map[feature.rolloutId] | ||
if rollout: | ||
for exp in rollout.experiments: | ||
rules.append(self.experiment_id_map[exp['id']]) | ||
|
||
# All variations for each flag | ||
# Datafile does not contain a separate entity for this. | ||
# We collect variations used in each rule (experiment rules and delivery rules) | ||
self.flag_variations_map = self.get_all_variations_for_each_rule(self.flag_rules_map) | ||
for rule in rules: | ||
# variation_id_map_by_experiment_id gives variation entity object while | ||
# experiment_id_map will give us dictionary | ||
for rule_variation in self.variation_id_map_by_experiment_id.get(rule.id).values(): | ||
if len(list(filter(lambda variation: variation.id == rule_variation.id, variations))) == 0: | ||
variations.append(rule_variation) | ||
self.flag_variations_map[feature.key] = variations | ||
|
||
@staticmethod | ||
def _generate_key_map(entity_list, key, entity_class): | ||
|
@@ -639,32 +633,6 @@ def get_variation_from_key_by_experiment_id(self, experiment_id, variation_key): | |
|
||
return {} | ||
|
||
def get_all_variations_for_each_rule(self, flag_rules_map): | ||
""" Helper method to get all variation objects from each flag. | ||
collects variations used in each rule (experiment rules and delivery rules). | ||
|
||
Args: | ||
flag_rules_map: A dictionary. A map of all rules per flag. | ||
|
||
Returns: | ||
Map of flag variations. | ||
""" | ||
flag_variations_map = {} | ||
|
||
for flag_key, rules in flag_rules_map.items(): | ||
variations = [] | ||
for rule in rules: | ||
# get variations as objects (rule.variations gives list) | ||
variation_objects = self.variation_id_map_by_experiment_id[rule.id].values() | ||
for variation in variation_objects: | ||
# append variation if it's not already in the list | ||
if variation not in variations: | ||
variations.append(variation) | ||
|
||
flag_variations_map[flag_key] = variations | ||
|
||
return flag_variations_map | ||
|
||
def get_flag_variation(self, flag_key, variation_attribute, target_value): | ||
""" | ||
Gets variation by specified variation attribute. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...