Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Auerbach committed May 23, 2017
1 parent 8876e03 commit d4fb809
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions optimizely/event_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def _add_account_id(self):

def _add_visitor(self, user_id):
""" Add user ID to the event """
self.params['visitors'] = []
self.params[self.EventParams.VISITORS] = []
# Add a single visitor
visitor = {}
visitor[self.EventParams.END_USER_ID] = user_id
# put snaps visitors
visitor['snapshots'] = []
self.params['visitors'].append(visitor)
visitor[self.EventParams.SNAPSHOTS] = []
self.params[self.EventParams.VISITORS].append(visitor)

@abstractmethod
def _add_attributes(self, attributes):
Expand Down Expand Up @@ -125,7 +125,10 @@ class EventParams(object):
REVISION = 'revision'
TIME = 'timestamp'
KEY = 'key'
TAGS = 'tags'
UUID = 'uuid'
VISITORS = 'visitors'
SNAPSHOTS = 'snapshots'
SOURCE_SDK_TYPE = 'clientName'
SOURCE_SDK_VERSION = 'clientVersion'

Expand All @@ -139,7 +142,7 @@ def _add_attributes(self, attributes):
if not attributes:
return

visitor = next(iter(self.params['visitors'] or []), None)
visitor = next(iter(self.params[self.EventParams.VISITORS] or []), None)
visitor[self.EventParams.ATTRIBUTES] = []

for attribute_key in attributes.keys():
Expand Down Expand Up @@ -192,12 +195,12 @@ def _add_required_params_for_impression(self, experiment, variation_id):
self.snapshot[self.EventParams.EVENT] = [{
self.EventParams.EVENT_ID: experiment.layerId,
self.EventParams.TIME: int(round(time.time() * 1000)),
self.EventParams.KEY : 'campaign_activated',
self.EventParams.UUID : str(uuid.uuid4())
self.EventParams.KEY: 'campaign_activated',
self.EventParams.UUID: str(uuid.uuid4())
}]

visitor_list = next(iter(self.params['visitors'] or []), None)
visitor_list['snapshots'].append(self.snapshot)
visitor_list = next(iter(self.params[self.EventParams.VISITORS] or []), None)
visitor_list[self.EventParams.SNAPSHOTS].append(self.snapshot)

def _add_required_params_for_conversion(self, event_key, user_id, event_tags, valid_experiments):
""" Add parameters that are required for the conversion event to register.
Expand All @@ -212,7 +215,8 @@ def _add_required_params_for_conversion(self, event_key, user_id, event_tags, va
event_list = []
self.snapshot[self.EventParams.EVENT] = []

visitor = next(iter(self.params['visitors'] or []), None)
# get the only visitor
visitor = next(iter(self.params[self.EventParams.VISITORS] or []), None)

for experiment in valid_experiments:
variation = self.bucketer.bucket(experiment, user_id)
Expand All @@ -226,8 +230,8 @@ def _add_required_params_for_conversion(self, event_key, user_id, event_tags, va
event_dict = {
self.EventParams.EVENT_ID: self.config.get_event(event_key).id,
self.EventParams.TIME: int(round(time.time() * 1000)),
self.EventParams.KEY : event_key,
self.EventParams.UUID : str(uuid.uuid4())
self.EventParams.KEY: event_key,
self.EventParams.UUID: str(uuid.uuid4())
}

if event_tags:
Expand All @@ -238,11 +242,11 @@ def _add_required_params_for_conversion(self, event_key, user_id, event_tags, va
del event_tags['revenue']

if len(event_tags) > 0:
event_dict['tags'] = event_tags
event_dict[self.EventParams.TAGS] = event_tags

self.snapshot[self.EventParams.EVENT].append(event_dict)
self.snapshot[self.EventParams.EVENT].append(event_dict)

visitor['snapshots'].append(self.snapshot)
visitor[self.EventParams.SNAPSHOTS].append(self.snapshot)

def create_impression_event(self, experiment, variation_id, user_id, attributes):
""" Create impression Event to be sent to the logging endpoint.
Expand Down

0 comments on commit d4fb809

Please sign in to comment.