-
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
wrong variation issue fix #346
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from .helpers import enums | ||
from . import entities | ||
from . import exceptions | ||
import copy | ||
|
||
SUPPORTED_VERSIONS = [ | ||
enums.DatafileVersions.V2, | ||
|
@@ -56,6 +57,7 @@ def __init__(self, datafile, logger, error_handler): | |
self.environment_key = config.get('environmentKey', None) | ||
self.groups = config.get('groups', []) | ||
self.experiments = config.get('experiments', []) | ||
self.mapexperiment = copy.deepcopy(self.experiments) | ||
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. this doesn't look ok to me. 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. Found some other issues as well with test cases. working through now. |
||
self.events = config.get('events', []) | ||
self.attributes = config.get('attributes', []) | ||
self.audiences = config.get('audiences', []) | ||
|
@@ -68,6 +70,7 @@ def __init__(self, datafile, logger, error_handler): | |
|
||
# Utility maps for quick lookup | ||
self.group_id_map = self._generate_key_map(self.groups, 'id', entities.Group) | ||
self.experimentID_map = self._generate_key_map(self.mapexperiment, 'id', entities.Experiment) | ||
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. We shouldn't mix camel cases with snake_case 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 experiment's can't be passed? what's the need of mapexperiment? |
||
self.experiment_key_map = self._generate_key_map(self.experiments, 'key', entities.Experiment) | ||
self.event_key_map = self._generate_key_map(self.events, 'key', entities.Event) | ||
self.attribute_key_map = self._generate_key_map(self.attributes, 'key', entities.Attribute) | ||
|
@@ -85,18 +88,24 @@ def __init__(self, datafile, logger, error_handler): | |
for layer in self.rollout_id_map.values(): | ||
for experiment in layer.experiments: | ||
self.experiment_key_map[experiment['key']] = entities.Experiment(**experiment) | ||
self.experimentID_map[experiment['id']] = entities.Experiment(**experiment) | ||
|
||
self.audience_id_map = self._deserialize_audience(self.audience_id_map) | ||
for group in self.group_id_map.values(): | ||
experiments_in_group_key_map = self._generate_key_map(group.experiments, 'key', entities.Experiment) | ||
for experiment in experiments_in_group_key_map.values(): | ||
experiment.__dict__.update({'groupId': group.id, 'groupPolicy': group.policy}) | ||
self.experiment_key_map.update(experiments_in_group_key_map) | ||
experiments_in_group_id_map = self._generate_key_map(group.experiments, 'id', entities.Experiment) | ||
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. To avoid confusion maybe we should rename this function or create a new one for ids. |
||
for experiment in experiments_in_group_id_map.values(): | ||
experiment.__dict__.update({'groupId': group.id, 'groupPolicy': group.policy}) | ||
self.experiment_key_map.update(experiments_in_group_id_map) | ||
|
||
self.experiment_id_map = {} | ||
self.variation_key_map = {} | ||
self.variation_id_map = {} | ||
self.variation_variable_usage_map = {} | ||
|
||
for experiment in self.experiment_key_map.values(): | ||
self.experiment_id_map[experiment.id] = experiment | ||
self.variation_key_map[experiment.key] = self._generate_key_map( | ||
|
@@ -108,6 +117,26 @@ def __init__(self, datafile, logger, error_handler): | |
self.variation_variable_usage_map[variation.id] = self._generate_key_map( | ||
variation.variables, 'id', entities.Variation.VariableUsage | ||
) | ||
self.correct_variation_id_map = {} | ||
self.temp_variation_id_map = {} | ||
for experiment in self.experimentID_map.values(): | ||
self.temp_variation_id_map[experiment.id] = self._generate_key_map( | ||
experiment.variations, 'id', entities.Variation | ||
) | ||
self.correct_variation_id_map[experiment.id] = {} | ||
for variation in self.temp_variation_id_map.get(experiment.id).values(): | ||
self.correct_variation_id_map[experiment.id][variation.id] = variation | ||
self.variation_variable_usage_map[variation.id] = self._generate_key_map( | ||
variation.variables, 'id', entities.Variation.VariableUsage | ||
) | ||
|
||
|
||
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. Too many blank lines between code, should be removed to follow lint. |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
self.feature_key_map = self._generate_key_map(self.feature_flags, 'key', entities.FeatureFlag) | ||
|
||
|
@@ -280,8 +309,8 @@ def get_experiment_from_id(self, experiment_id): | |
Experiment corresponding to the provided experiment ID. | ||
""" | ||
|
||
experiment = self.experiment_id_map.get(experiment_id) | ||
|
||
# experiment = self.experiment_id_map.get(experiment_id) | ||
experiment = self.experimentID_map.get(experiment_id) | ||
if experiment: | ||
return experiment | ||
|
||
|
@@ -362,8 +391,8 @@ def get_variation_from_id(self, experiment_key, variation_id): | |
Object representing the variation. | ||
""" | ||
|
||
variation_map = self.variation_id_map.get(experiment_key) | ||
|
||
#variation_map = self.variation_id_map.get(experiment_key) | ||
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. Please remove commented code |
||
variation_map = self.correct_variation_id_map.get(experiment_key) | ||
if variation_map: | ||
variation = variation_map.get(variation_id) | ||
if variation: | ||
|
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 commented code (minor).