1818from . import entities
1919from . import exceptions
2020
21- REVENUE_GOAL_KEY = 'Total Revenue'
2221V1_CONFIG_VERSION = '1'
2322V2_CONFIG_VERSION = '2'
2423
@@ -54,20 +53,13 @@ def __init__(self, datafile, logger, error_handler):
5453 self .attributes = config .get ('attributes' , [])
5554 self .audiences = config .get ('audiences' , [])
5655 self .anonymize_ip = config .get ('anonymizeIP' , False )
57- self .features = config .get ('features' , [])
58- self .layers = config .get ('layers' , [])
5956
6057 # Utility maps for quick lookup
6158 self .group_id_map = self ._generate_key_map (self .groups , 'id' , entities .Group )
6259 self .experiment_key_map = self ._generate_key_map (self .experiments , 'key' , entities .Experiment )
6360 self .event_key_map = self ._generate_key_map (self .events , 'key' , entities .Event )
6461 self .attribute_key_map = self ._generate_key_map (self .attributes , 'key' , entities .Attribute )
6562 self .audience_id_map = self ._generate_key_map (self .audiences , 'id' , entities .Audience )
66- self .layer_id_map = self ._generate_key_map (self .layers , 'id' , entities .Layer )
67- for layer in self .layer_id_map .values ():
68- for experiment in layer .experiments :
69- self .experiment_key_map [experiment ['key' ]] = entities .Experiment (** experiment )
70-
7163 self .audience_id_map = self ._deserialize_audience (self .audience_id_map )
7264 for group in self .group_id_map .values ():
7365 experiments_in_group_key_map = self ._generate_key_map (group .experiments , 'key' , entities .Experiment )
@@ -81,7 +73,6 @@ def __init__(self, datafile, logger, error_handler):
8173 self .experiment_id_map = {}
8274 self .variation_key_map = {}
8375 self .variation_id_map = {}
84- self .variation_variable_usage_map = {}
8576 for experiment in self .experiment_key_map .values ():
8677 self .experiment_id_map [experiment .id ] = experiment
8778 self .variation_key_map [experiment .key ] = self ._generate_key_map (
@@ -90,22 +81,6 @@ def __init__(self, datafile, logger, error_handler):
9081 self .variation_id_map [experiment .key ] = {}
9182 for variation in self .variation_key_map .get (experiment .key ).values ():
9283 self .variation_id_map [experiment .key ][variation .id ] = variation
93- if variation .variables :
94- self .variation_variable_usage_map [variation .id ] = self ._generate_key_map (
95- variation .variables , 'id' , entities .Variation .VariableUsage
96- )
97-
98- self .feature_key_map = self ._generate_key_map (self .features , 'key' , entities .Feature )
99- for feature in self .feature_key_map .values ():
100- feature .variables = self ._generate_key_map (feature .variables , 'key' , entities .Variable )
101-
102- # Check if any of the experiments are in a group and add the group id for faster bucketing later on
103- for exp_id in feature .experimentIds :
104- experiment_in_feature = self .experiment_id_map [exp_id ]
105- if experiment_in_feature .groupId :
106- feature .groupId = experiment_in_feature .groupId
107- # Experiments in feature can only belong to one mutex group
108- break
10984
11085 self .parsing_succeeded = True
11186
@@ -154,26 +129,6 @@ def _deserialize_audience(audience_map):
154129
155130 return audience_map
156131
157- def _get_typecast_value (self , value , type ):
158- """ Helper method to determine actual value based on type of feature variable.
159-
160- Args:
161- value: Value in string form as it was parsed from datafile.
162- type: Type denoting the feature flag type.
163-
164- Return:
165- Value type-casted based on type of feature variable.
166- """
167-
168- if type == entities .Variable .Type .BOOLEAN :
169- return value == 'true'
170- elif type == entities .Variable .Type .INTEGER :
171- return int (value )
172- elif type == entities .Variable .Type .DOUBLE :
173- return float (value )
174- else :
175- return value
176-
177132 def was_parsing_successful (self ):
178133 """ Helper method to determine if parsing the datafile was successful.
179134
@@ -383,87 +338,6 @@ def get_attribute(self, attribute_key):
383338 self .error_handler .handle_error (exceptions .InvalidAttributeException (enums .Errors .INVALID_ATTRIBUTE_ERROR ))
384339 return None
385340
386- def get_feature_from_key (self , feature_key ):
387- """ Get feature for the provided feature key.
388-
389- Args:
390- feature_key: Feature key for which feature is to be fetched.
391-
392- Returns:
393- Feature corresponding to the provided feature key.
394- """
395- feature = self .feature_key_map .get (feature_key )
396-
397- if feature :
398- return feature
399-
400- self .logger .log (enums .LogLevels .ERROR , 'Feature "%s" is not in datafile.' % feature_key )
401- return None
402-
403- def get_layer_from_id (self , layer_id ):
404- """ Get layer for the provided layer id.
405-
406- Args:
407- layer_id: ID of the layer to be fetched.
408-
409- Returns:
410- Layer corresponding to the provided layer id.
411- """
412- layer = self .layer_id_map .get (layer_id )
413-
414- if layer :
415- return layer
416-
417- self .logger .log (enums .LogLevels .ERROR , 'Layer with ID "%s" is not in datafile.' % layer_id )
418- return None
419-
420- def get_variable_value_for_variation (self , variable , variation ):
421- """ Get the variable value for the given variation.
422-
423- Args:
424- Variable: The Variable for which we are getting the value.
425- Variation: The Variation for which we are getting the variable value.
426-
427- Returns:
428- The type-casted variable value or None if any of the inputs are invalid.
429- """
430- if not variable or not variation :
431- return None
432-
433- if variation .id not in self .variation_variable_usage_map :
434- self .logger .log (enums .LogLevels .ERROR , 'Variation with ID "%s" is not in the datafile.' % variation .id )
435- return None
436-
437- # Get all variable usages for the given variation
438- variable_usages = self .variation_variable_usage_map [variation .id ]
439-
440- # Find usage in given variation
441- variable_usage = variable_usages [variable .id ]
442-
443- value = self ._get_typecast_value (variable_usage .value , variable .type )
444- return value
445-
446- def get_variable_for_feature (self , feature_key , variable_key ):
447- """ Get the variable with the given variable key for the given feature
448-
449- Args:
450- feature_key: The key of the feature for which we are getting the variable.
451- variable_key: The key of the variable we are getting.
452-
453- Returns:
454- Variable with the given key in the given variation.
455- """
456- feature = self .feature_key_map .get (feature_key )
457- if not feature :
458- self .logger .log (enums .LogLevels .ERROR , 'Feature with key "%s" not found in the datafile.' % feature_key )
459- return None
460-
461- if variable_key not in feature .variables :
462- self .logger .log (enums .LogLevels .ERROR , 'Variable with key "%s" not found in the datafile.' % variable_key )
463- return None
464-
465- return feature .variables .get (variable_key )
466-
467341 def set_forced_variation (self , experiment_key , user_id , variation_key ):
468342 """ Sets users to a map of experiments to forced variations.
469343
0 commit comments