-
Notifications
You must be signed in to change notification settings - Fork 35
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
Duplicate experiment Key issue with multi feature flag #347
Changes from 4 commits
12de61b
bf7e099
ff9625b
b6324c9
ba99b6f
4e25c21
f0c1733
617cc4d
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 |
---|---|---|
|
@@ -68,7 +68,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.experiment_key_map = self._generate_key_map(self.experiments, 'key', entities.Experiment) | ||
self.experiment_id_map = self._generate_key_map(self.experiments, 'id', 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) | ||
|
||
|
@@ -84,27 +84,36 @@ def __init__(self, datafile, logger, error_handler): | |
self.rollout_id_map = self._generate_key_map(self.rollouts, 'id', entities.Layer) | ||
for layer in self.rollout_id_map.values(): | ||
for experiment in layer.experiments: | ||
self.experiment_key_map[experiment['key']] = entities.Experiment(**experiment) | ||
self.experiment_id_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(): | ||
experiments_in_group_id_map = self._generate_key_map(group.experiments, 'id', entities.Experiment) | ||
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_key_map) | ||
self.experiment_id_map.update(experiments_in_group_id_map) | ||
|
||
self.experiment_id_map = {} | ||
self.experiment_key_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_id_map_by_experiment_id = {} | ||
self.variation_key_map_by_experiment_id = {} | ||
|
||
for experiment in self.experiment_id_map.values(): | ||
self.experiment_key_map[experiment.key] = experiment | ||
self.variation_key_map[experiment.key] = self._generate_key_map( | ||
experiment.variations, 'key', entities.Variation | ||
) | ||
|
||
self.variation_id_map[experiment.key] = {} | ||
self.variation_id_map_by_experiment_id[experiment.id] = {} | ||
self.variation_key_map_by_experiment_id[experiment.id] = {} | ||
|
||
for variation in self.variation_key_map.get(experiment.key).values(): | ||
self.variation_id_map[experiment.key][variation.id] = variation | ||
self.variation_id_map_by_experiment_id[experiment.id][variation.id] = variation | ||
self.variation_key_map_by_experiment_id[experiment.id][variation.key] = variation | ||
self.variation_variable_usage_map[variation.id] = self._generate_key_map( | ||
variation.variables, 'id', entities.Variation.VariableUsage | ||
) | ||
|
@@ -557,3 +566,35 @@ def is_feature_experiment(self, experiment_id): | |
""" | ||
|
||
return experiment_id in self.experiment_feature_map | ||
|
||
def get_variation_from_id_by_experiment_id(self, experiment_id, variation_id): | ||
""" Gets experiment id and variation id | ||
|
||
Returns: | ||
The variation for the experiment id and variation id | ||
or empty dict if not found | ||
""" | ||
if (experiment_id in self.variation_id_map_by_experiment_id and | ||
variation_id in self.variation_id_map_by_experiment_id[experiment_id]): | ||
return self.variation_id_map_by_experiment_id[experiment_id][variation_id] | ||
|
||
self.logger.error('Variation with id "%s" not defined in the datafile for experiment "%s".', | ||
variation_id, experiment_id) | ||
|
||
return {} | ||
|
||
def get_variation_from_key_by_experiment_id(self, experiment_id, variation_key): | ||
""" Gets experiment id and variation 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 rephrase and have more clear explanation. 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. comments changed to better describe what is happening. |
||
|
||
Returns: | ||
The variation for the experiment id and variation key | ||
or empty dict if not found | ||
""" | ||
if (experiment_id in self.variation_key_map_by_experiment_id and | ||
variation_key in self.variation_key_map_by_experiment_id[experiment_id]): | ||
return self.variation_key_map_by_experiment_id[experiment_id][variation_key] | ||
|
||
self.logger.error('Variation with key "%s" not defined in the datafile for experiment "%s".', | ||
variation_key, experiment_id) | ||
|
||
return {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ def test_init(self): | |
self.config_dict['groups'][0]['trafficAllocation'], | ||
) | ||
} | ||
|
||
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. ? 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. Only curious because it was by itself. 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 need a new line to satisfy Flake8 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. formatter... |
||
expected_experiment_key_map = { | ||
'test_experiment': entities.Experiment( | ||
'111127', | ||
|
@@ -1213,3 +1214,27 @@ def test_is_feature_experiment(self): | |
|
||
self.assertStrictFalse(project_config.is_feature_experiment(experiment.id)) | ||
self.assertStrictTrue(project_config.is_feature_experiment(feature_experiment.id)) | ||
|
||
def test_get_variation_from_id_by_experiment_id(self): | ||
|
||
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict)) | ||
project_config = opt_obj.config_manager.get_config() | ||
|
||
experiment_id = '111127' | ||
variation_id = '111128' | ||
|
||
variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id) | ||
|
||
self.assertIsInstance(variation, entities.Variation) | ||
|
||
def test_get_variation_from_key_by_experiment_id(self): | ||
|
||
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict)) | ||
project_config = opt_obj.config_manager.get_config() | ||
|
||
experiment_id = '111127' | ||
variation_key = 'control' | ||
|
||
variation = project_config.get_variation_from_key_by_experiment_id(experiment_id, variation_key) | ||
|
||
self.assertIsInstance(variation, entities.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.
Gets only variation by variation id under specific experiment 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.
please rephrase
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.
comments changed to better describe what is happening.