Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sustainable Web Design rating scale #207

Merged
merged 11 commits into from
May 27, 2024
Merged

Add Sustainable Web Design rating scale #207

merged 11 commits into from
May 27, 2024

Conversation

fershad
Copy link
Contributor

@fershad fershad commented May 9, 2024

Triage

Type of change

Please select any of the below items that are appropriate.

This pull request:

  • Adds a new carbon estimation model to CO2.js
  • Adds new functionality to an existing model
  • Fixes a bug with an existing model implementation
  • Add other new functionality to CO2.js
  • Add new data to CO2.js
  • Improves developer experience for contributors
  • Adds contributors to CO2.js
  • Does something not specified above

Related issue/s

Please list below any issues this pull request is related to.

Docs changes required

Do any changes made in this pull request require parts of the CO2.js documentation to be updated?

  • Yes
  • No
  • I don't know

If you answered "Yes", please create an corresponding issue in our Developer Documentation repository.

Related issue: thegreenwebfoundation/developer-docs#50

Describe the changes made in this pull request

As clearly as possible, describe the changes made in the pull request. You should at least detail "what changes have been made" and "what the results of these changes will be".

This change adds the Sustainable Web Design rating scale into CO2.js for developers using the Sustainable Web Design Model to estimate emissions.

The rating scale is "off" by default, but developers can opt-in to returning results with a carbon emissions total & a corresponding rating by setting rating: true when instantiating an instance of the Sustainable Web Design Model in CO2.js.

import { co2 } from '@tgwf/co2';

const model = new co2({ rating: true });

The rating system is based on the number of bytes passed into carbon emissions results calculated by the perByte, perVisit, perByteTrace, or perVisitTrace functions.

Currently the perByte and perVisit functions return a number representing the estimated CO2e calculated by those functions. When rating: true is set, these functions will now return an object with two keys - rating and total. For example:

import { co2 } from '@tgwf/co2';

const hasRating = new co2({ rating: true });
const noRating = new co2();

hasRating.perByte(1000);

/* Returns:
{ total: 0.0003936519, rating: 'A+' }
*/

noRating.perByte(1000)
/* Returns: 
0.0003936519
*/

@fershad fershad requested a review from mrchrisadams May 9, 2024 08:16
@fershad fershad added this to the 0.16 milestone May 9, 2024
@fershad fershad linked an issue May 9, 2024 that may be closed by this pull request
@fershad fershad changed the title Add swd rating scale Add Sustainable Web Design rating scale May 9, 2024
@fershad
Copy link
Contributor Author

fershad commented May 20, 2024

@mrchrisadams are you comfortable with this getting merged?

Copy link
Member

@mrchrisadams mrchrisadams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fershad - this looks great!

I have a query about using constants in place of some of the values, that only have explanation on external websites like the 0.95 figure referring to the fifth percentile of websites in the SWD model page, but otherwise I'm happy to merge it in.

Please merge in at your convenience.

src/sustainable-web-design.js Outdated Show resolved Hide resolved
src/sustainable-web-design.test.js Outdated Show resolved Hide resolved
src/co2.js Outdated Show resolved Hide resolved
@fershad fershad merged commit 142c041 into main May 27, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Sustainable Web Design digital carbon rating scale
2 participants