thegreenwebfoundation / co2.js

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

Switch default to use SWD model instead of older onebyte model #94

Closed mrchrisadams closed 2 years ago

mrchrisadams commented 2 years ago

Right now, while we have the Sustainable Web Design module, we default using to the earlier created 1byte model for CO2 calculations.

So when you do this:

import { CO2 } from '@tgwf/co2'

const calc = new CO2()

// calculate transfer
const basicTransferResult = calc.perbyte(TRANSFER_IN_BYTES)

...you're using the 1byte model from the Shift Project.

Making the change.

We need to change this code so default model is no longer the Onebyte one, and instead the SWD one:

class CO2 {
  constructor(options) {
    this.options = options;

    // default model
    this.model = new OneByte();

    if (options) {
      this.model = new options.model();
    }
  }

This would mean when we import the CO2 module, we can calculate web pages easily, not just do basis transfer calculations.

import { CO2 } from '@tgwf/co2'

const calc = new CO2()

// calculate transfer
const basicTransferResult = calc.perbyte(TRANSFER_IN_BYTES)

// new: calculate the result for a web page, including caching assumptions in the SWD model
const webPageResult = calc.energyPerVisit(WEBSITE_SIZE_IN_BYTES)

This will have the effect of increasing carbon numbers slightly but it also means we can get a breakdown of where the emissions are assumed to happen.

Todo

fershad commented 2 years ago

@mrchrisadams I'll assign this to myself and work on it this coming week.

fershad commented 2 years ago

CO2.js - Switch default to use SWD model instead of 1byte model

fershad commented 2 years ago

100 has been created to address this issue.

fershad commented 2 years ago

This issue was merged with #100.