From 1e453502da971151768d0de64aa76ea550defc94 Mon Sep 17 00:00:00 2001 From: Pierre Bresson Date: Wed, 4 Aug 2021 10:40:03 +0200 Subject: [PATCH] update electricity and add new countries --- README.md | 9 +-- package.json | 2 +- src/electricity/electricity.enum.ts | 8 +++ src/electricity/electricity.ts | 85 ++++++++++++++++++----------- 4 files changed, 67 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 55afa27..9f4da38 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,12 @@ Any Contribution is welcome! Please read [this](/CONTRIBUTING.md) if you want to contribute. -### Lint + typescript : +### Tests + Lint + typescript : -`npm run lint` -and : -`npm run format` +`yarn test` +`yarn lint` +`yarn tsc` +`yarn format` ## Workflow diff --git a/package.json b/package.json index b4546a2..411bbc1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "carbon-footprint", - "version": "1.5.4", + "version": "1.6.0", "description": "Calculate your carbon footprint. Food, transport, purchases, fashion, electricity and digital activities like streaming.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/electricity/electricity.enum.ts b/src/electricity/electricity.enum.ts index 0550553..d0e56e0 100644 --- a/src/electricity/electricity.enum.ts +++ b/src/electricity/electricity.enum.ts @@ -10,7 +10,9 @@ export enum ElectricityType { portugal = 'portugal', netherlands = 'netherlands', belgium = 'belgium', + //to be removed at some point danmark = 'danmark', + denmark = 'denmark', germany = 'germany', poland = 'poland', italy = 'italy', @@ -35,4 +37,10 @@ export enum ElectricityType { uruguay = 'uruguay', brazil = 'brazil', australia = 'australia', + russia = 'russia', + india = 'india', + nigeria = 'nigeria', + canada = 'canada', + iceland = 'iceland', + israel = 'israel', } diff --git a/src/electricity/electricity.ts b/src/electricity/electricity.ts index d160cdb..49bc111 100644 --- a/src/electricity/electricity.ts +++ b/src/electricity/electricity.ts @@ -1,50 +1,64 @@ /* Unit of exported constant : kgCO₂eq/J */ -/* source in kgCO₂eq/kWh : https://github.com/carbonalyser/Carbonalyser */ +/* source : https://github.com/carbonalyser/Carbonalyser - kgCO₂eq/kWh */ const europe = 0.276; const usa = 0.493; const china = 0.681; const world = 0.519; -/* Source : https://www.electricitymap.org - 28th of April 2020 */ +/* Source : https://www.electricitymap.org - 4th of August 2021 - kgCO₂eq/kWh */ -/* Europe in kgCO₂eq/kWh */ -const france = 0.031; -const uk = 0.231; -const ireland = 0.477; +/* Asia */ +const russia = (0.373 + 0.465) / 2; +const india = (0.643 + 0.473 + 0.097) / 3; +const israel = 0.58; +const turkey = 0.394; + +/* Africa */ +const nigeria = 0.49; + +/* North America */ +const canada = (0.04 + 0.506 + 0.02 + 0.03 + 0.509) / 5; +const iceland = 0.028; + +/* Europe */ +const france = 0.035; +const uk = 0.313; +const ireland = 0.472; const spain = 0.138; -const portugal = 0.105; -const netherlands = 0.434; -const belgium = 0.172; -const danmark = 0.226; -const germany = 0.33; -const poland = 0.66; -const italy = 0.386; -const turkey = 0.322; -const finland = 0.162; -const norway = 0.036; -const czechia = 0.446; -const austria = 0.153; -const serbia = 0.517; -const slovenia = 0.078; -const hungary = 0.177; -const slovakia = 0.234; -const ukraine = 0.213; -const romania = 0.184; +const portugal = 0.296; +const netherlands = 0.466; +const belgium = 0.09; +//to be removed at some point +const danmark = 0.192; +const denmark = 0.192; +const germany = 0.304; +const poland = 0.725; +const italy = (0.249 + 0.237 + 0.452 + 0.449 + 0.354 + 0.52) / 6; +const finland = 0.094; +const norway = (0.026 + 0.031 + 0.039 + 0.029 + 0.033) / 5; +const czechia = 0.406; +const austria = 0.096; +const serbia = 0.548; +const slovenia = 0.278; +const hungary = 0.217; +const slovakia = 0.226; +const ukraine = 0.242; +const romania = 0.275; const moldava = 0.667; -const estonia = 0.193; -const latvia = 0.243; -const lithuania = 0.183; +const estonia = 0.46; +const latvia = 0.44; +const lithuania = 0.361; /* South America in kgCO₂eq/kWh */ const peru = 0.026; -const bolivia = 0.512; -const argentina = 0.299; -const uruguay = 0.03; -const brazil = 0.086; +const bolivia = 0.377; +const argentina = 0.33; +const uruguay = 0.33; +const brazil = (0.282 + 0.196 + 0.261 + 0.276) / 4; /* Oceania in kgCO₂eq/kWh */ -const australia = 0.571; +const australia = (0.708 + 0.303 + 0.641 + 0.455 + 0.22) / 5; const toJoules = (x: number) => (x / 3.6) * Math.pow(10, -6); @@ -61,6 +75,7 @@ export default { netherlands: toJoules(netherlands), belgium: toJoules(belgium), danmark: toJoules(danmark), + denmark: toJoules(denmark), germany: toJoules(germany), poland: toJoules(poland), italy: toJoules(italy), @@ -85,4 +100,10 @@ export default { uruguay: toJoules(uruguay), brazil: toJoules(brazil), australia: toJoules(australia), + russia: toJoules(russia), + india: toJoules(india), + nigeria: toJoules(nigeria), + canada: toJoules(canada), + iceland: toJoules(iceland), + israel: toJoules(israel), };