20
20
from baseplate .lib .events import DebugLogger
21
21
from baseplate .lib .events import EventLogger
22
22
from baseplate .lib .file_watcher import FileWatcher
23
- from baseplate .lib .file_watcher import T
24
23
from baseplate .lib .file_watcher import WatchedFileNotAvailableError
25
24
from reddit_edgecontext import ValidatedAuthenticationToken
26
25
from rust_decider import Decider as RustDecider
@@ -62,33 +61,53 @@ class ExperimentConfig:
62
61
63
62
64
63
class DeciderContext :
65
- """DeciderContext() is used to contain all fields necessary for
64
+ """:code:` DeciderContext` is used to contain all fields necessary for
66
65
bucketing, targeting, and overrides.
67
- :code:`DeciderContext()` is populated in :code:`make_object_for_context()`.
66
+ :code:`DeciderContext` is populated in :code:`make_object_for_context()`
67
+
68
+ :param user_id: user's t2 id
69
+ :param device_id: device installation uuid
70
+ :param canonical_url: an url string
71
+ :param subreddit_id: subreddit link's t3 identifier
72
+ :param ad_account_id: an ad_account id string identifier
73
+ :param business_id: business id identifier used by ads
74
+ :param country_code: 2-letter country codes
75
+ :param locale: ISO 639-1 primary language subtag and an optional ISO 3166-1 alpha-2 region subtag
76
+ :param user_is_employee:
77
+ :param logged_in: is user logged in
78
+ :param oauth_client_id: OAuth Client ID
79
+ :param origin_service: Service where request originated
80
+ :param cookie_created_timestamp: When the authentication cookie was created
81
+ :param loid_created_timestamp: Epoch milliseconds when the current LoID cookie was created
82
+ :param extracted_fields: Optional dict of additional fields, e.g. app_name & build_number
68
83
"""
69
84
70
- T = TypeVar ("T" )
71
-
72
85
def __init__ (
73
86
self ,
74
87
user_id : Optional [str ] = None ,
88
+ device_id : Optional [str ] = None ,
89
+ subreddit_id : Optional [str ] = None ,
90
+ ad_account_id : Optional [str ] = None ,
91
+ business_id : Optional [str ] = None ,
75
92
country_code : Optional [str ] = None ,
76
93
locale : Optional [str ] = None ,
77
94
user_is_employee : Optional [bool ] = None ,
78
95
logged_in : Optional [bool ] = None ,
79
- device_id : Optional [str ] = None ,
80
96
oauth_client_id : Optional [str ] = None ,
81
97
origin_service : Optional [str ] = None ,
82
98
cookie_created_timestamp : Optional [float ] = None ,
83
99
loid_created_timestamp : Optional [float ] = None ,
84
100
extracted_fields : Optional [dict ] = None ,
85
101
):
86
102
self ._user_id = user_id
103
+ self ._device_id = device_id
104
+ self ._subreddit_id = subreddit_id
105
+ self ._ad_account_id = ad_account_id
106
+ self ._business_id = business_id
87
107
self ._country_code = country_code
88
108
self ._locale = locale
89
109
self ._user_is_employee = user_is_employee
90
110
self ._logged_in = logged_in
91
- self ._device_id = device_id
92
111
self ._oauth_client_id = oauth_client_id
93
112
self ._origin_service = origin_service
94
113
self ._cookie_created_timestamp = cookie_created_timestamp
@@ -100,11 +119,14 @@ def to_dict(self) -> Dict:
100
119
101
120
return {
102
121
"user_id" : self ._user_id ,
122
+ "device_id" : self ._device_id ,
123
+ "subreddit_id" : self ._subreddit_id ,
124
+ "ad_account_id" : self ._ad_account_id ,
125
+ "business_id" : self ._business_id ,
103
126
"country_code" : self ._country_code ,
104
127
"locale" : self ._locale ,
105
128
"user_is_employee" : self ._user_is_employee ,
106
129
"logged_in" : self ._logged_in ,
107
- "device_id" : self ._device_id ,
108
130
"oauth_client_id" : self ._oauth_client_id ,
109
131
"origin_service" : self ._origin_service ,
110
132
"cookie_created_timestamp" : self ._cookie_created_timestamp ,
@@ -145,6 +167,10 @@ def to_event_dict(self) -> Dict:
145
167
if self ._device_id :
146
168
platform_fields ["device_id" ] = self ._device_id
147
169
170
+ subreddit_fields = {}
171
+ if self ._subreddit :
172
+ subreddit_fields ["id" ] = self ._subreddit
173
+
148
174
return {
149
175
"user_id" : self ._user_id ,
150
176
"country_code" : self ._country_code ,
@@ -159,6 +185,7 @@ def to_event_dict(self) -> Dict:
159
185
"geo" : geo_fields ,
160
186
"request" : request_fields ,
161
187
"platform" : platform_fields ,
188
+ "subreddit" : subreddit_fields ,
162
189
** ef ,
163
190
}
164
191
@@ -175,6 +202,8 @@ class Decider:
175
202
It will automatically reload the cache when changed.
176
203
"""
177
204
205
+ T = TypeVar ("T" )
206
+
178
207
def __init__ (
179
208
self ,
180
209
decider_context : DeciderContext ,
0 commit comments