ahoicloud / co2
Package for laravel calculating Co2 emission based on Sustainable Web Design (SWD) model
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-09 04:09:24 UTC
README
Every byte of data that’s uploaded or downloaded produces CO2. By being able to calculate these emissions, developers can enabled themself and their users to create more efficient, lower carbon decisions. Here are a few examples:
- Create a carbon budget for your site
- Inform the user when they uploading or downloading carbon intensive files
The package uses the Sustainable Web Design (SWD) model. The yearly average grid intensity data comes from Ember, as well as marginal intensity data from the UNFCCC (United Nations Framework Convention on Climate Change).
The package is build for Laravel and is based on the great work done by The Green Web Foundation in the CO2.js package.
Installation
You can install the package via composer:
composer require ahoicloud/co2
Optional
You can publish the config file with:
php artisan vendor:publish --tag="co2-config"
This is the contents of the published config file:
return [ 'KWH_PER_GB' => 0.81, 'END_USER_DEVICE_ENERGY' => 0.52, 'NETWORK_ENERGY' => 0.14, 'DATACENTER_ENERGY' => 0.15, 'PRODUCTION_ENERGY' => 0.19, 'GLOBAL_GRID_INTENSITY' => 442, 'RENEWABLES_GRID_INTENSITY' => 50, 'FIRST_TIME_VIEWING_PERCENTAGE' => 0.75, 'RETURNING_VISITOR_PERCENTAGE' => 0.25, 'PERCENTAGE_OF_DATA_LOADED_ON_SUBSEQUENT_LOAD' => 0.02, ];
Usage
Total energy use by each corresponding system component in kilowatt hours
$co2 = new Ahoicloud\Co2(); echo $co2->energyPerByteByComponent($byte);
Or as a facade
use Ahoicloud\Co2\Facades\Co2; echo Co2::energyPerByteByComponent($byte);
Total co2 figures key by the each component
$co2 = new Ahoicloud\Co2(); echo $co2->co2byComponent($byte);
Or as a facade
use Ahoicloud\Co2\Facades\Co2; echo Co2::co2byComponent($byte);
Total co2 figures key by the each component
$co2 = new Ahoicloud\Co2(); echo $co2->perByte($byte);
Or as a facade
use Ahoicloud\Co2\Facades\Co2; echo Co2::perByte($byte);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
The code for thegreenwebfoundation/co2.js is licensed Apache 2.0. (What does this mean?)
The average carbon intensity data from Ember is published under the Creative Commons ShareAlike Attribution Licence (CC BY-SA 4.0). (What does this mean?)
The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence (CC BY-SA 4.0). (What does this mean?)
See LICENCE for more.