-
-
Notifications
You must be signed in to change notification settings - Fork 616
feat(sustainable) : added countryCode option for country specific CO₂ calculations #4583
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
base: main
Are you sure you want to change the base?
feat(sustainable) : added countryCode option for country specific CO₂ calculations #4583
Conversation
|
Hi @Harsh-Git39 ah cool, I'll have a look and test it this weekend! |
|
Hi @soulgalore! I've fixed all the linting errors. The CRUX test is failing due to a missing API key in the CI configuration (--crux.key is empty), which appears to be unrelated to my changes. All other tests are passed . Could you please review? |
|
Hi @soulgalore is this solution as expected or I'm happy to make further corrections if needed. |
soulgalore
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about also showing on the result page which country code that was used? That makes it easier to remember what you actually used.
I haven't tried the actual functionality on c02, so if I just switch between two different country codes I can verify that it works?
| example:- | ||
| ```bash | ||
| sitespeed.io https://example.com \ | ||
| --plugins.add sustainable \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the rest of the documentation we use --sustainable.enable, I think we should use that here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense I can update the result page to also show which countryCode was used, so it’s clear what configuration the CO₂ calculation is based on and for documentation I will make a update shortly.
| super({ name: 'sustainable', options, context, queue }); | ||
| } | ||
|
|
||
| static getCliOptions() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? I think the options for now could be moved to lib/cli/cli.js where the rest of the sustainable options is today, to keep it consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works I have tested it locally switching between two different country codes shows different result in different CO2 values and I will move and test it on cli.js to ensure consistency and get back to you shorty
Makes users to calculate CO₂ emissions using a country-specific electricity grid mix via electricitymaps (through
@tgwf/co2).Implementation
Added
sustainable.countryCodeas a plugin CLI option.Passed the value into the CO₂ model configuration when creating the
co2instance.Updated the sustainable plugin documentation with a implementation example .
Testing and observations
I tested it with different country codes (IN, DE, NO). On very small pages (example.com) the difference is tiny due to rounding, but on larger pages like wikipedia.org the CO₂ values do change (for example, India ≈ 0.03730 vs Norway ≈ 0.03710), which shows the country-specific electricity mix is being used.
On lightweight pages (like example.com / wikipedia), the differences in CO₂ values are small, but they are consistently visible across runs, which suggests the country-specific electricity mix is being applied correctly. Heavier pages should make the differences more noticeable.
Thanks a lot for opportunity!!