44import logging
55
66import yaml
7- from corporate import get_corporate_emissions
87from utils import get_fact_or_default , get_facts_from_sources , log_result , log_step
98from yaml .loader import SafeLoader
109
@@ -74,17 +73,17 @@ def getProductInfo(key: str, default: float | None, product: dict[str, float], d
7473
7574
7675def getCorporateEmissionsPerBidRequest (
77- corporateAllocation : float ,
76+ corporate_emissions_g : float ,
77+ corporate_allocation : float ,
7878 facts : dict [str , float ],
7979 defaults : dict [str , float ],
8080 depth : int ,
8181) -> float :
82- corporateEmissionsG = get_corporate_emissions (facts , defaults , depth - 1 ) * 1000000
8382 bidRequests = (
8483 get_fact_or_default ("bid requests processed billion per month" , facts , defaults , depth - 1 )
8584 * 1000000000
8685 )
87- corporateEmissionsPerBidRequest = corporateAllocation * corporateEmissionsG / bidRequests
86+ corporateEmissionsPerBidRequest = corporate_allocation * corporate_emissions_g / bidRequests
8887 log_result (
8988 "corporate emissions g per bid request" ,
9089 f"{ corporateEmissionsPerBidRequest } :.8f" ,
@@ -180,15 +179,12 @@ def getServerEmissionsPerBidRequest(
180179
181180
182181def getPrimaryEmissionsPerBidRequest (
182+ corporateEmissionsPerBidRequest : float ,
183183 serverAllocation : float ,
184- corporateAllocation : float ,
185184 facts : dict [str , float ],
186185 defaults : dict [str , float ],
187186 depth : int ,
188187) -> float :
189- corporateEmissionsPerBidRequest = getCorporateEmissionsPerBidRequest (
190- corporateAllocation , facts , defaults , depth - 1
191- )
192188 dataTransferEmissionsPerBidRequest = getDataTransferEmissionsPerBidRequest (
193189 facts , defaults , depth - 1
194190 )
@@ -299,8 +295,8 @@ def main():
299295 parser .add_argument (
300296 "-d" ,
301297 "--defaultsFile" ,
302- default = "defaults.yaml" ,
303- help = "Set the defaults file to use (overrides defaults.yaml)" ,
298+ default = "atp- defaults.yaml" ,
299+ help = "Set the defaults file to use (overrides atp- defaults.yaml)" ,
304300 )
305301 parser .add_argument ("-v" , "--verbose" , action = "store_true" , help = "Show derivation of output" )
306302 parser .add_argument (
@@ -312,6 +308,20 @@ def main():
312308 nargs = "?" ,
313309 help = "Simulate distribution partners" ,
314310 )
311+ parser .add_argument (
312+ "--corporateEmissionsG" ,
313+ const = 1 ,
314+ type = float ,
315+ nargs = "?" ,
316+ help = "Provide the corporate emissionsfor organization" ,
317+ )
318+ parser .add_argument (
319+ "--corporateEmissionsGPerImp" ,
320+ const = 1 ,
321+ type = float ,
322+ nargs = "?" ,
323+ help = "Provide the corporate emissions for organization per bid request" ,
324+ )
315325 parser .add_argument ("companyFile" , nargs = 1 , help = "The company file to parse in YAML format" )
316326 args = parser .parse_args ()
317327 if args .verbose :
@@ -332,6 +342,12 @@ def main():
332342 raise Exception ("No 'sources' field found in company file" )
333343 facts = get_facts_from_sources (document ["company" ]["sources" ])
334344
345+ corporate_emissions_g = args .corporateEmissionsG
346+ corporate_emissions_g_per_imp = args .corporateEmissionsGPerImp
347+
348+ if not corporate_emissions_g and not corporate_emissions_g_per_imp :
349+ raise Exception ("Must provide either --corporateEmissionsG or --corporateEmissionsGPerImp" )
350+
335351 depth = 4 if args .verbose else 0
336352 productModels = []
337353 for product in document ["company" ]["products" ]:
@@ -346,8 +362,15 @@ def main():
346362 if template not in defaultsDocument ["defaults" ]:
347363 raise Exception (f"Template { template } not found in defaults" )
348364 defaults = defaultsDocument ["defaults" ][template ]
365+
366+ corporate_emissions_per_bid_request = corporate_emissions_g_per_imp
367+ if corporate_emissions_g :
368+ corporate_emissions_per_bid_request = getCorporateEmissionsPerBidRequest (
369+ corporate_emissions_g , corporateAllocation , facts , defaults , depth - 1
370+ )
371+
349372 primaryEmissionsPerBidRequest = getPrimaryEmissionsPerBidRequest (
350- serverAllocation , corporateAllocation , facts , defaults , depth
373+ corporate_emissions_per_bid_request , serverAllocation , facts , defaults , depth
351374 )
352375 primaryEmissionsPerCookieSync = getPrimaryEmissionsPerCookieSync (
353376 serverAllocation , facts , defaults , depth
0 commit comments