Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions .github/workflows/defaults_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,37 @@ jobs:
poetry install
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Generate Defaults File
- name: Generate Defaults Files
run: python ./scope3_methodology/compute_defaults.py
- name: Upload Defaults Files to Release
id: upload_defaults_files
- name: Upload ATP Defaults File to Release
id: upload_atp_defaults_files
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: defaults.yaml
asset_name: methodology_model_defaults.yaml
asset_path: atp-defaults.yaml
asset_name: methodology_atp_defaults.yaml
asset_content_type: text/plain
- name: Upload Organization Defaults File to Release
id: upload_org_defaults_files
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: organization-defaults.yaml
asset_name: methodology_organization_defaults.yaml
asset_content_type: text/plain
- name: Upload Property Defaults Files to Release
id: upload_prop_defaults_files
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: property-defaults.yaml
asset_name: methodology_property_defaults.yaml
asset_content_type: text/plain
- name: Publish Release
uses: eregon/publish-release@v1
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Output files
defaults.yaml
atp-defaults.yaml
organization-defaults.yaml
property-defaults.yaml

# git
*.swp
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,21 @@ To write defaults from latest sources:
./scope3_methodology/compute_defaults.py
```

To compute the corporate emissions, pass in its YAML file:

```sh
./scope3_methodology/corporate.py --verbose [--publisher] [--adTechPlatform] [your_model.yaml]
```

To compute the emissions for an ad tech company, pass in its YAML file:

```sh
./scope3_methodology/adtech_model.py -v sources/companies/criteo/data.yaml
./scope3_methodology/adtech_model.py -v [--corporateEmissionsG] [--corporateEmissionsGPerRequest] sources/companies/criteo/data.yaml
```

To compute the emissions for publisher, pass in its YAML file:

```sh
./scope3_methodology/publisher.py -vsources/companies/theguardian/data.yaml
./scope3_methodology/publisher.py -v [--corporateEmissionsG] [--corporateEmissionsGPerImp] sources/companies/theguardian/data.yaml

```
2 changes: 1 addition & 1 deletion docs/adTechModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The file must have:

To model emissions, make sure defaults have been computed. Then run:
```sh
./scope3_methodology/adtech_model.py --verbose [your_model.yaml]
./scope3_methodology/adtech_model.py --verbose [--corporateEmissionsG] [--corporateEmissionsGPerRequest] [your_model.yaml]
```

If you want to see how the secondary emissions would be modeled, pass in `-p N` where N is the number of partners to simulate.
Expand Down
25 changes: 25 additions & 0 deletions docs/corporate.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,28 @@ Includes home office emissions


## Increased detail in financial data


# Usage
Create a YAML file that describes the company you would like to model. The YAML file should look like this:
```
company:
name: Criteo
products:
- product:
name: Criteo
template: network
identifier: criteo.com
sources:
- source:
facts:
- fact:
employees: 2810
```
The file must have:
- Some number of facts, with `employees` required at a minimum unless you provide full corporate emissions data

To model emissions, make sure defaults have been computed. Then run:
```sh
./scope3_methodology/corporate.py --verbose [--publisher] [--adTechPlatform] [your_model.yaml]
```
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pyyaml==6.0 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293 \
--hash=sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b \
--hash=sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57 \
--hash=sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b \
--hash=sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4 \
--hash=sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07 \
--hash=sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba \
--hash=sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9 \
--hash=sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287 \
--hash=sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513 \
--hash=sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0 \
--hash=sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0 \
--hash=sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92 \
--hash=sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f \
--hash=sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2 \
--hash=sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc \
--hash=sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c \
--hash=sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86 \
--hash=sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4 \
--hash=sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c \
--hash=sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34 \
--hash=sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b \
--hash=sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c \
--hash=sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb \
--hash=sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737 \
--hash=sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3 \
--hash=sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d \
--hash=sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53 \
--hash=sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78 \
--hash=sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803 \
--hash=sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a \
--hash=sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174 \
--hash=sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5
45 changes: 34 additions & 11 deletions scope3_methodology/adtech_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging

import yaml
from corporate import get_corporate_emissions
from utils import get_fact_or_default, get_facts_from_sources, log_result, log_step
from yaml.loader import SafeLoader

Expand Down Expand Up @@ -74,17 +73,17 @@ def getProductInfo(key: str, default: float | None, product: dict[str, float], d


def getCorporateEmissionsPerBidRequest(
corporateAllocation: float,
corporate_emissions_g: float,
corporate_allocation: float,
facts: dict[str, float],
defaults: dict[str, float],
depth: int,
) -> float:
corporateEmissionsG = get_corporate_emissions(facts, defaults, depth - 1) * 1000000
bidRequests = (
get_fact_or_default("bid requests processed billion per month", facts, defaults, depth - 1)
* 1000000000
)
corporateEmissionsPerBidRequest = corporateAllocation * corporateEmissionsG / bidRequests
corporateEmissionsPerBidRequest = corporate_allocation * corporate_emissions_g / bidRequests
log_result(
"corporate emissions g per bid request",
f"{corporateEmissionsPerBidRequest}:.8f",
Expand Down Expand Up @@ -180,15 +179,12 @@ def getServerEmissionsPerBidRequest(


def getPrimaryEmissionsPerBidRequest(
corporateEmissionsPerBidRequest: float,
serverAllocation: float,
corporateAllocation: float,
facts: dict[str, float],
defaults: dict[str, float],
depth: int,
) -> float:
corporateEmissionsPerBidRequest = getCorporateEmissionsPerBidRequest(
corporateAllocation, facts, defaults, depth - 1
)
dataTransferEmissionsPerBidRequest = getDataTransferEmissionsPerBidRequest(
facts, defaults, depth - 1
)
Expand Down Expand Up @@ -299,8 +295,8 @@ def main():
parser.add_argument(
"-d",
"--defaultsFile",
default="defaults.yaml",
help="Set the defaults file to use (overrides defaults.yaml)",
default="atp-defaults.yaml",
help="Set the defaults file to use (overrides atp-defaults.yaml)",
)
parser.add_argument("-v", "--verbose", action="store_true", help="Show derivation of output")
parser.add_argument(
Expand All @@ -312,6 +308,20 @@ def main():
nargs="?",
help="Simulate distribution partners",
)
parser.add_argument(
"--corporateEmissionsG",
const=1,
type=float,
nargs="?",
help="Provide the corporate emissionsfor organization",
)
parser.add_argument(
"--corporateEmissionsGPerImp",
const=1,
type=float,
nargs="?",
help="Provide the corporate emissions for organization per bid request",
)
parser.add_argument("companyFile", nargs=1, help="The company file to parse in YAML format")
args = parser.parse_args()
if args.verbose:
Expand All @@ -332,6 +342,12 @@ def main():
raise Exception("No 'sources' field found in company file")
facts = get_facts_from_sources(document["company"]["sources"])

corporate_emissions_g = args.corporateEmissionsG
corporate_emissions_g_per_imp = args.corporateEmissionsGPerImp

if not corporate_emissions_g and not corporate_emissions_g_per_imp:
raise Exception("Must provide either --corporateEmissionsG or --corporateEmissionsGPerImp")

depth = 4 if args.verbose else 0
productModels = []
for product in document["company"]["products"]:
Expand All @@ -346,8 +362,15 @@ def main():
if template not in defaultsDocument["defaults"]:
raise Exception(f"Template {template} not found in defaults")
defaults = defaultsDocument["defaults"][template]

corporate_emissions_per_bid_request = corporate_emissions_g_per_imp
if corporate_emissions_g:
corporate_emissions_per_bid_request = getCorporateEmissionsPerBidRequest(
corporate_emissions_g, corporateAllocation, facts, defaults, depth - 1
)

primaryEmissionsPerBidRequest = getPrimaryEmissionsPerBidRequest(
serverAllocation, corporateAllocation, facts, defaults, depth
corporate_emissions_per_bid_request, serverAllocation, facts, defaults, depth
)
primaryEmissionsPerCookieSync = getPrimaryEmissionsPerCookieSync(
serverAllocation, facts, defaults, depth
Expand Down
Loading