thegreenwebfoundation / co2.js

An npm module for accessing the green web API, and estimating the carbon emissions from using digital services
Other
385 stars 48 forks source link

Small update to adjustable constants change #128

Closed fershad closed 1 year ago

fershad commented 1 year ago

This PR is a small update the recent adjustable constants in SWD PR #126.

In this PR there is one additional output, and one logic correction.

Additional Output

The bytes variable will also be returned as part of the perVisitTrace or perByteTrace results. This closes the loop, ensuring that all the inputs into the SWD formula are accounted for in the results.

{
    "co2": 0.00027030509999999996,
    "green": false,
    "variables": {
      "description": "Below are the variables used to calculate this CO2 estimate.",
      "bytes": 1000,
      "gridIntensity": {
        "description": "The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",
        "network": 442,
        "dataCenter": 442,
        "production": 442,
        "device": 442
      },
      "dataReloadRatio": 0.02,
      "firstVisitPercentage": 0.75,
      "returnVisitPercentage": 0.25
    }
  }

Logic correction

Now, when using perVisitTrace or perByteTrace, if the user sets the value for green as true then the calculation will us the renewable energy constant of 50 g/kWh in the calculation. This is regardless of if the user has also passed in a value for the dataCenter grid intensity separately.

For example: