2020from baseplate .lib .events import DebugLogger
2121from baseplate .lib .events import EventLogger
2222from baseplate .lib .file_watcher import FileWatcher
23- from baseplate .lib .file_watcher import T
2423from baseplate .lib .file_watcher import WatchedFileNotAvailableError
2524from reddit_edgecontext import ValidatedAuthenticationToken
2625from rust_decider import Decider as RustDecider
@@ -62,33 +61,53 @@ class ExperimentConfig:
6261
6362
6463class DeciderContext :
65- """DeciderContext() is used to contain all fields necessary for
64+ """:code:` DeciderContext` is used to contain all fields necessary for
6665 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
6883 """
6984
70- T = TypeVar ("T" )
71-
7285 def __init__ (
7386 self ,
7487 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 ,
7592 country_code : Optional [str ] = None ,
7693 locale : Optional [str ] = None ,
7794 user_is_employee : Optional [bool ] = None ,
7895 logged_in : Optional [bool ] = None ,
79- device_id : Optional [str ] = None ,
8096 oauth_client_id : Optional [str ] = None ,
8197 origin_service : Optional [str ] = None ,
8298 cookie_created_timestamp : Optional [float ] = None ,
8399 loid_created_timestamp : Optional [float ] = None ,
84100 extracted_fields : Optional [dict ] = None ,
85101 ):
86102 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
87107 self ._country_code = country_code
88108 self ._locale = locale
89109 self ._user_is_employee = user_is_employee
90110 self ._logged_in = logged_in
91- self ._device_id = device_id
92111 self ._oauth_client_id = oauth_client_id
93112 self ._origin_service = origin_service
94113 self ._cookie_created_timestamp = cookie_created_timestamp
@@ -100,11 +119,14 @@ def to_dict(self) -> Dict:
100119
101120 return {
102121 "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 ,
103126 "country_code" : self ._country_code ,
104127 "locale" : self ._locale ,
105128 "user_is_employee" : self ._user_is_employee ,
106129 "logged_in" : self ._logged_in ,
107- "device_id" : self ._device_id ,
108130 "oauth_client_id" : self ._oauth_client_id ,
109131 "origin_service" : self ._origin_service ,
110132 "cookie_created_timestamp" : self ._cookie_created_timestamp ,
@@ -145,6 +167,10 @@ def to_event_dict(self) -> Dict:
145167 if self ._device_id :
146168 platform_fields ["device_id" ] = self ._device_id
147169
170+ subreddit_fields = {}
171+ if self ._subreddit_id :
172+ subreddit_fields ["id" ] = self ._subreddit_id
173+
148174 return {
149175 "user_id" : self ._user_id ,
150176 "country_code" : self ._country_code ,
@@ -159,6 +185,7 @@ def to_event_dict(self) -> Dict:
159185 "geo" : geo_fields ,
160186 "request" : request_fields ,
161187 "platform" : platform_fields ,
188+ "subreddit" : subreddit_fields ,
162189 ** ef ,
163190 }
164191
@@ -175,6 +202,8 @@ class Decider:
175202 It will automatically reload the cache when changed.
176203 """
177204
205+ T = TypeVar ("T" )
206+
178207 def __init__ (
179208 self ,
180209 decider_context : DeciderContext ,
0 commit comments