@@ -51,10 +51,14 @@ def _add_account_id(self):
51
51
52
52
self .params [self .EventParams .ACCOUNT_ID ] = self .config .get_account_id ()
53
53
54
+ @abstractmethod
54
55
def _add_user_id (self , user_id ):
55
- """ Add user ID to the event. """
56
+ """ Add user ID to the event.
56
57
57
- self .params [self .EventParams .END_USER_ID ] = user_id
58
+ Args:
59
+ user_id: ID of the user.
60
+ """
61
+ pass
58
62
59
63
@abstractmethod
60
64
def _add_attributes (self , attributes ):
@@ -70,15 +74,25 @@ def _add_source(self):
70
74
""" Add source information to the event. """
71
75
pass
72
76
73
- @abstractmethod
74
- def _add_time (self ):
75
- """ Add time information to the event. """
76
- pass
77
-
78
77
def _add_revision (self ):
79
78
""" Add datafile revision information to the event. """
80
79
pass
81
80
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
+
82
96
def _add_common_params (self , user_id , attributes ):
83
97
""" Add params which are used same in both conversion and impression events.
84
98
@@ -92,8 +106,7 @@ def _add_common_params(self, user_id, attributes):
92
106
self ._add_user_id (user_id )
93
107
self ._add_attributes (attributes )
94
108
self ._add_source ()
95
- self ._add_revision ()
96
- self ._add_time ()
109
+ self ._add_anonymize_ip ()
97
110
98
111
99
112
class EventBuilder (BaseEventBuilder ):
@@ -158,13 +171,12 @@ def _add_source(self):
158
171
self .params [self .EventParams .SOURCE_SDK_TYPE ] = 'python-sdk'
159
172
self .params [self .EventParams .SOURCE_SDK_VERSION ] = version .__version__
160
173
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.
165
176
166
- def _add_visitor (self , user_id ):
167
- """ Add user to the event """
177
+ Args:
178
+ user_id: ID of the user.
179
+ """
168
180
169
181
self .params [self .EventParams .USERS ] = []
170
182
# Add a single visitor
@@ -173,25 +185,6 @@ def _add_visitor(self, user_id):
173
185
visitor [self .EventParams .SNAPSHOTS ] = []
174
186
self .params [self .EventParams .USERS ].append (visitor )
175
187
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
-
195
188
def _add_required_params_for_impression (self , experiment , variation_id ):
196
189
""" Add parameters that are required for the impression event to register.
197
190
@@ -209,7 +202,7 @@ def _add_required_params_for_impression(self, experiment, variation_id):
209
202
210
203
snapshot [self .EventParams .EVENTS ] = [{
211
204
self .EventParams .EVENT_ID : experiment .layerId ,
212
- self .EventParams .TIME : int ( round ( time . time () * 1000 ) ),
205
+ self .EventParams .TIME : self . _get_time ( ),
213
206
self .EventParams .KEY : 'campaign_activated' ,
214
207
self .EventParams .UUID : str (uuid .uuid4 ())
215
208
}]
@@ -241,7 +234,7 @@ def _add_required_params_for_conversion(self, event_key, event_tags, decisions):
241
234
242
235
event_dict = {
243
236
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 ( ),
245
238
self .EventParams .KEY : event_key ,
246
239
self .EventParams .UUID : str (uuid .uuid4 ())
247
240
}
0 commit comments