@@ -51,10 +51,14 @@ def _add_account_id(self):
5151
5252 self .params [self .EventParams .ACCOUNT_ID ] = self .config .get_account_id ()
5353
54+ @abstractmethod
5455 def _add_user_id (self , user_id ):
55- """ Add user ID to the event. """
56+ """ Add user ID to the event.
5657
57- self .params [self .EventParams .END_USER_ID ] = user_id
58+ Args:
59+ user_id: ID of the user.
60+ """
61+ pass
5862
5963 @abstractmethod
6064 def _add_attributes (self , attributes ):
@@ -70,15 +74,25 @@ def _add_source(self):
7074 """ Add source information to the event. """
7175 pass
7276
73- @abstractmethod
74- def _add_time (self ):
75- """ Add time information to the event. """
76- pass
77-
7877 def _add_revision (self ):
7978 """ Add datafile revision information to the event. """
8079 pass
8180
81+ def _add_anonymize_ip (self ):
82+ """ Add IP anonymization bool to the event """
83+
84+ self .params [self .EventParams .ANONYMIZE_IP ] = self .config .get_anonymize_ip_value ()
85+
86+ @abstractmethod
87+ def _get_time (self ):
88+ """ Get time in milliseconds to be added to the event.
89+
90+ Returns:
91+ Current time in milliseconds.
92+ """
93+
94+ return int (round (time .time () * 1000 ))
95+
8296 def _add_common_params (self , user_id , attributes ):
8397 """ Add params which are used same in both conversion and impression events.
8498
@@ -92,8 +106,7 @@ def _add_common_params(self, user_id, attributes):
92106 self ._add_user_id (user_id )
93107 self ._add_attributes (attributes )
94108 self ._add_source ()
95- self ._add_revision ()
96- self ._add_time ()
109+ self ._add_anonymize_ip ()
97110
98111
99112class EventBuilder (BaseEventBuilder ):
@@ -158,13 +171,12 @@ def _add_source(self):
158171 self .params [self .EventParams .SOURCE_SDK_TYPE ] = 'python-sdk'
159172 self .params [self .EventParams .SOURCE_SDK_VERSION ] = version .__version__
160173
161- def _add_time (self ):
162- """ Add time information to the event. """
163-
164- self .params [self .EventParams .TIME ] = int (round (time .time () * 1000 ))
174+ def _add_user_id (self , user_id ):
175+ """ Add user ID to the event.
165176
166- def _add_visitor (self , user_id ):
167- """ Add user to the event """
177+ Args:
178+ user_id: ID of the user.
179+ """
168180
169181 self .params [self .EventParams .USERS ] = []
170182 # Add a single visitor
@@ -173,25 +185,6 @@ def _add_visitor(self, user_id):
173185 visitor [self .EventParams .SNAPSHOTS ] = []
174186 self .params [self .EventParams .USERS ].append (visitor )
175187
176- def _add_anonymize_ip (self ):
177- """ Add IP anonymization bool to the event """
178-
179- self .params [self .EventParams .ANONYMIZE_IP ] = self .config .get_anonymize_ip_value ()
180-
181- def _add_common_params (self , user_id , attributes ):
182- """ Add params which are used same in both conversion and impression events.
183-
184- Args:
185- user_id: ID for user.
186- attributes: Dict representing user attributes and values which need to be recorded.
187- """
188- self ._add_project_id ()
189- self ._add_account_id ()
190- self ._add_visitor (user_id )
191- self ._add_attributes (attributes )
192- self ._add_source ()
193- self ._add_anonymize_ip ()
194-
195188 def _add_required_params_for_impression (self , experiment , variation_id ):
196189 """ Add parameters that are required for the impression event to register.
197190
@@ -209,7 +202,7 @@ def _add_required_params_for_impression(self, experiment, variation_id):
209202
210203 snapshot [self .EventParams .EVENTS ] = [{
211204 self .EventParams .EVENT_ID : experiment .layerId ,
212- self .EventParams .TIME : int ( round ( time . time () * 1000 ) ),
205+ self .EventParams .TIME : self . _get_time ( ),
213206 self .EventParams .KEY : 'campaign_activated' ,
214207 self .EventParams .UUID : str (uuid .uuid4 ())
215208 }]
@@ -241,7 +234,7 @@ def _add_required_params_for_conversion(self, event_key, event_tags, decisions):
241234
242235 event_dict = {
243236 self .EventParams .EVENT_ID : self .config .get_event (event_key ).id ,
244- self .EventParams .TIME : int ( round ( time . time () * 1000 ) ),
237+ self .EventParams .TIME : self . _get_time ( ),
245238 self .EventParams .KEY : event_key ,
246239 self .EventParams .UUID : str (uuid .uuid4 ())
247240 }
0 commit comments