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

Change values like PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD #109

Closed michael-voit closed 1 year ago

michael-voit commented 1 year ago

I have seen in the \src\sustainable-web-design.js that I can use a number for the carbon intensity instead of just true or false with perByte and perVisit. So I can get more accurate data if I know in which country a server resides, right? So if I know the server is not green and sits in Germany I would put in 367.52 (src: Ember) and get a more accurate result than if co2.js would use the global intensity of 442.

My tests look like that and I hope that is right.

Is there also a way to change the values for FIRST_TIME_VIEWING_PERCENTAGE, RETURNING_VISITOR_PERCENTAGE and PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD for perVisit? Because if I audit a website, I do know at least parts of these figures and so the calculation could also be more accurate.

Have I missed something?

Is something like that planned?

Most important, because that is measurable in an audit, would be PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD.

Thanks a lot,

Michael

fershad commented 1 year ago

@michael-voit this is definitely something we're looking to make possible. We'd like to create a nice API to make these adjustments possible while still providing sensible fallbacks.

It would probably be a two part job in terms of implementation. Allowing some of the Sustainable Web Design assumptions (like PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD) would probably be where we'll start. After that we'd look at providing a way for developers to easily pass in their own grid intensity figures. Ideally we'd like to provide a way for people to use the marginal/average intensity data that was added in v0.11 (#97 & #69).

Open to suggestions on how this might look API-wise.

fershad commented 1 year ago

@michael-voit have a look in the PR above. I've made a first pass at implementing an API for this, feedback welcome.

fershad commented 1 year ago

This is now possible using new functions perVisitTrace and perByteTrace in #126.