@tgwf/co2 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.esbuild.browser.js +11 -0
- package/.esbuild.esm.js +25 -0
- package/.esbuild.node.js +16 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +33 -8
- package/README.md +28 -33
- package/dist/cjs/1byte.js +52 -0
- package/dist/cjs/1byte.js.map +7 -0
- package/dist/cjs/1byte.test.js +27 -0
- package/dist/cjs/1byte.test.js.map +7 -0
- package/dist/cjs/co2.js +116 -0
- package/dist/cjs/co2.js.map +7 -0
- package/dist/cjs/co2.test.js +244 -0
- package/dist/cjs/co2.test.js.map +7 -0
- package/dist/cjs/constants/file-size.js +27 -0
- package/dist/cjs/constants/file-size.js.map +7 -0
- package/dist/cjs/constants/index.js +27 -0
- package/dist/cjs/constants/index.js.map +7 -0
- package/dist/cjs/helpers/index.js +24 -0
- package/dist/cjs/helpers/index.js.map +7 -0
- package/dist/cjs/hosting-api.js +64 -0
- package/dist/cjs/hosting-api.js.map +7 -0
- package/dist/cjs/hosting-api.test.js +47 -0
- package/dist/cjs/hosting-api.test.js.map +7 -0
- package/dist/cjs/hosting-database.node.test.js +36 -0
- package/dist/cjs/hosting-database.node.test.js.map +7 -0
- package/dist/cjs/hosting-json.node.js +73 -0
- package/dist/cjs/hosting-json.node.js.map +7 -0
- package/dist/cjs/hosting-json.node.test.js +43 -0
- package/dist/cjs/hosting-json.node.test.js.map +7 -0
- package/dist/cjs/hosting-node.js +78 -0
- package/dist/cjs/hosting-node.js.map +7 -0
- package/dist/cjs/hosting.js +36 -0
- package/dist/cjs/hosting.js.map +7 -0
- package/dist/cjs/hosting.test.js +74 -0
- package/dist/cjs/hosting.test.js.map +7 -0
- package/dist/cjs/index-node.js +29 -0
- package/dist/cjs/index-node.js.map +7 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/sustainable-web-design.js +151 -0
- package/dist/cjs/sustainable-web-design.js.map +7 -0
- package/dist/cjs/sustainable-web-design.test.js +85 -0
- package/dist/cjs/sustainable-web-design.test.js.map +7 -0
- package/dist/esm/1byte.js +32 -0
- package/dist/esm/1byte.test.js +11 -0
- package/dist/esm/co2.js +93 -0
- package/dist/esm/co2.test.js +228 -0
- package/dist/esm/constants/file-size.js +7 -0
- package/dist/esm/constants/index.js +4 -0
- package/dist/esm/helpers/index.js +4 -0
- package/dist/esm/hosting-api.js +41 -0
- package/dist/esm/hosting-api.test.js +31 -0
- package/dist/esm/hosting-database.node.test.js +20 -0
- package/dist/esm/hosting-json.node.test.js +27 -0
- package/dist/esm/hosting.js +13 -0
- package/{src → dist/esm}/hosting.test.js +18 -38
- package/dist/esm/index.js +8 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/sustainable-web-design.js +128 -0
- package/dist/esm/sustainable-web-design.test.js +69 -0
- package/fixup +19 -0
- package/package.json +37 -16
- package/public/index.html +57 -0
- package/public/index.js +2 -0
- package/public/index.js.map +7 -0
- package/src/1byte.js +40 -6
- package/src/co2.js +24 -47
- package/src/constants/file-size.js +5 -0
- package/src/constants/index.js +3 -0
- package/src/helpers/index.js +3 -0
- package/src/hosting-api.js +23 -43
- package/src/{hosting-json.js → hosting-json.node.js} +9 -11
- package/src/hosting-node.js +94 -0
- package/src/hosting.js +6 -28
- package/src/index-node.js +4 -0
- package/src/index.js +4 -6
- package/src/readme.md +66 -0
- package/src/sustainable-web-design.js +292 -0
- package/.eslintrc.json +0 -21
- package/.github/workflows/unittests.yml +0 -26
- package/data/Lean-ICT-Materials-1byte-Model-2018.xlsx +0 -0
- package/data/Lean-ICT-Materials-Forecast-Model-2018.xlsx +0 -0
- package/data/fixtures/tgwf.har +0 -6107
- package/data/fixtures/url2green.test.db +0 -0
- package/data/fixtures/url2green.test.json +0 -1
- package/data/fixtures/url2green.test.json.gz +0 -0
- package/src/1byte.test.js +0 -16
- package/src/co2.test.js +0 -150
- package/src/green-byte.js +0 -26
- package/src/hosting-api.test.js +0 -37
- package/src/hosting-database.test.js +0 -31
- package/src/hosting-json.test.js +0 -44
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
["google.com","maxcdn.bootstrapcdn.com","thegreenwebfoundation.org","www.thegreenwebfoundation.org","fonts.googleapis.com","ajax.googleapis.com","assets.digitalclimatestrike.net","cdnjs.cloudflare.com","graphite.thegreenwebfoundation.org","analytics.thegreenwebfoundation.org","fonts.gstatic.com","api.thegreenwebfoundation.org"]
|
|
Binary file
|
package/src/1byte.test.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const oneByte = require("./1byte");
|
|
4
|
-
|
|
5
|
-
describe("onebyte", function () {
|
|
6
|
-
describe("perByte", function () {
|
|
7
|
-
it.only("returns a simple average of the different networks", function () {
|
|
8
|
-
// we limit this to 12 figures with toFixed(12), because
|
|
9
|
-
// we have a recurring 333333 afterwards
|
|
10
|
-
// 4.88e-10 is the same as 0.000000000488
|
|
11
|
-
const expected_val = (0.000000000488).toFixed(12);
|
|
12
|
-
|
|
13
|
-
expect(oneByte.KWH_PER_BYTE_FOR_NETWORK.toFixed(12)).toBe(expected_val);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/co2.test.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
const CO2 = require("./co2");
|
|
7
|
-
const pagexray = require("pagexray");
|
|
8
|
-
|
|
9
|
-
describe("co2", function () {
|
|
10
|
-
let har, co2;
|
|
11
|
-
const TGWF_GREY_VALUE = 0.20497;
|
|
12
|
-
const TGWF_GREEN_VALUE = 0.54704;
|
|
13
|
-
const TGWF_MIXED_VALUE = 0.16718;
|
|
14
|
-
|
|
15
|
-
const MILLION = 1000000;
|
|
16
|
-
const MILLION_GREY = 0.29081;
|
|
17
|
-
const MILLION_GREEN = 0.23196;
|
|
18
|
-
|
|
19
|
-
beforeEach(function () {
|
|
20
|
-
co2 = new CO2();
|
|
21
|
-
har = JSON.parse(
|
|
22
|
-
fs.readFileSync(
|
|
23
|
-
path.resolve(__dirname, "../data/fixtures/tgwf.har"),
|
|
24
|
-
"utf8"
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("perByte", function () {
|
|
30
|
-
it("returns a CO2 number for data transfer using 'grey' power", function () {
|
|
31
|
-
expect(co2.perByte(MILLION).toPrecision(5)).toBe(
|
|
32
|
-
MILLION_GREY.toPrecision(5)
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("returns a lower CO2 number for data transfer from domains using entirely 'green' power", function () {
|
|
37
|
-
expect(co2.perByte(MILLION, false).toPrecision(5)).toBe(
|
|
38
|
-
MILLION_GREY.toPrecision(5)
|
|
39
|
-
);
|
|
40
|
-
expect(co2.perByte(MILLION, true).toPrecision(5)).toBe(
|
|
41
|
-
MILLION_GREEN.toPrecision(5)
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe("perPage", function () {
|
|
47
|
-
it("returns CO2 for total transfer for page", function () {
|
|
48
|
-
const pages = pagexray.convert(har);
|
|
49
|
-
const pageXrayRun = pages[0];
|
|
50
|
-
|
|
51
|
-
expect(co2.perPage(pageXrayRun).toPrecision(5)).toBe(
|
|
52
|
-
TGWF_GREY_VALUE.toPrecision(5)
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
it("returns lower CO2 for page served from green site", function () {
|
|
56
|
-
const pages = pagexray.convert(har);
|
|
57
|
-
const pageXrayRun = pages[0];
|
|
58
|
-
let green = [
|
|
59
|
-
"www.thegreenwebfoundation.org",
|
|
60
|
-
"fonts.googleapis.com",
|
|
61
|
-
"ajax.googleapis.com",
|
|
62
|
-
"assets.digitalclimatestrike.net",
|
|
63
|
-
"cdnjs.cloudflare.com",
|
|
64
|
-
"graphite.thegreenwebfoundation.org",
|
|
65
|
-
"analytics.thegreenwebfoundation.org",
|
|
66
|
-
"fonts.gstatic.com",
|
|
67
|
-
"api.thegreenwebfoundation.org",
|
|
68
|
-
];
|
|
69
|
-
expect(co2.perPage(pageXrayRun, green)).toBeLessThan(TGWF_GREY_VALUE);
|
|
70
|
-
});
|
|
71
|
-
it("returns a lower CO2 number where *some* domains use green power", function () {
|
|
72
|
-
const pages = pagexray.convert(har);
|
|
73
|
-
const pageXrayRun = pages[0];
|
|
74
|
-
// green can be true, or a array containing entries
|
|
75
|
-
let green = [
|
|
76
|
-
"www.thegreenwebfoundation.org",
|
|
77
|
-
"fonts.googleapis.com",
|
|
78
|
-
"ajax.googleapis.com",
|
|
79
|
-
"assets.digitalclimatestrike.net",
|
|
80
|
-
"cdnjs.cloudflare.com",
|
|
81
|
-
"graphite.thegreenwebfoundation.org",
|
|
82
|
-
"analytics.thegreenwebfoundation.org",
|
|
83
|
-
"fonts.gstatic.com",
|
|
84
|
-
"api.thegreenwebfoundation.org",
|
|
85
|
-
];
|
|
86
|
-
expect(co2.perPage(pageXrayRun, green).toPrecision(5)).toBe(
|
|
87
|
-
TGWF_MIXED_VALUE.toPrecision(5)
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
describe("perDomain", function () {
|
|
92
|
-
it("shows object listing Co2 for each domain", function () {
|
|
93
|
-
const pages = pagexray.convert(har);
|
|
94
|
-
const pageXrayRun = pages[0];
|
|
95
|
-
const res = co2.perDomain(pageXrayRun);
|
|
96
|
-
|
|
97
|
-
const domains = [
|
|
98
|
-
"thegreenwebfoundation.org",
|
|
99
|
-
"www.thegreenwebfoundation.org",
|
|
100
|
-
"maxcdn.bootstrapcdn.com",
|
|
101
|
-
"fonts.googleapis.com",
|
|
102
|
-
"ajax.googleapis.com",
|
|
103
|
-
"assets.digitalclimatestrike.net",
|
|
104
|
-
"cdnjs.cloudflare.com",
|
|
105
|
-
"graphite.thegreenwebfoundation.org",
|
|
106
|
-
"analytics.thegreenwebfoundation.org",
|
|
107
|
-
"fonts.gstatic.com",
|
|
108
|
-
"api.thegreenwebfoundation.org",
|
|
109
|
-
];
|
|
110
|
-
|
|
111
|
-
for (let obj of res) {
|
|
112
|
-
expect(domains.indexOf(obj.domain)).toBeGreaterThan(-1);
|
|
113
|
-
expect(typeof obj.co2).toBe("number");
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
it("shows lower Co2 for green domains", function () {
|
|
117
|
-
const pages = pagexray.convert(har);
|
|
118
|
-
const pageXrayRun = pages[0];
|
|
119
|
-
|
|
120
|
-
const greenDomains = [
|
|
121
|
-
"www.thegreenwebfoundation.org",
|
|
122
|
-
"fonts.googleapis.com",
|
|
123
|
-
"ajax.googleapis.com",
|
|
124
|
-
"assets.digitalclimatestrike.net",
|
|
125
|
-
"cdnjs.cloudflare.com",
|
|
126
|
-
"graphite.thegreenwebfoundation.org",
|
|
127
|
-
"analytics.thegreenwebfoundation.org",
|
|
128
|
-
"fonts.gstatic.com",
|
|
129
|
-
"api.thegreenwebfoundation.org",
|
|
130
|
-
];
|
|
131
|
-
const res = co2.perDomain(pageXrayRun);
|
|
132
|
-
const resWithGreen = co2.perDomain(pageXrayRun, greenDomains);
|
|
133
|
-
|
|
134
|
-
for (let obj of res) {
|
|
135
|
-
expect(typeof obj.co2).toBe("number");
|
|
136
|
-
}
|
|
137
|
-
for (let obj of greenDomains) {
|
|
138
|
-
let index = 0;
|
|
139
|
-
expect(resWithGreen[index].co2).toBeLessThan(res[index].co2);
|
|
140
|
-
index++;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
// describe('perContentType', function () {
|
|
145
|
-
// test.skip('shows a breakdown of emissions by content type');
|
|
146
|
-
// });
|
|
147
|
-
// describe('dirtiestResources', function () {
|
|
148
|
-
// it.skip('shows the top 10 resources by CO2 emissions');
|
|
149
|
-
// });
|
|
150
|
-
});
|
package/src/green-byte.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// PLEASE DO NOT USE THIS MODEL YET FOR CALCS
|
|
2
|
-
|
|
3
|
-
const CO2_PER_KWH_IN_DC_GREY = 519;
|
|
4
|
-
|
|
5
|
-
// this subs in the IEA's recent figure in analyis from the carbon brief
|
|
6
|
-
// https://www.carbonbrief.org/factcheck-what-is-the-carbon-footprint-of-streaming-video-on-netflix
|
|
7
|
-
|
|
8
|
-
// datacentres
|
|
9
|
-
const KWH_PER_BYTE_IN_DC = 0.00000000007;
|
|
10
|
-
|
|
11
|
-
// networks
|
|
12
|
-
const KWH_PER_BYTE_FOR_NETWORK = 0.00000000058;
|
|
13
|
-
|
|
14
|
-
// the device used to access a site/app
|
|
15
|
-
const KWH_PER_BYTE_FOR_DEVICES = 0.00000000055;
|
|
16
|
-
|
|
17
|
-
// The device usage figure combines figures for:
|
|
18
|
-
// 1. the usage for devices (which is small proportion of the energy use)
|
|
19
|
-
// 2. the *making* the device, which is comparitively high.
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
KWH_PER_BYTE_IN_DC,
|
|
23
|
-
KWH_PER_BYTE_FOR_NETWORK,
|
|
24
|
-
KWH_PER_BYTE_FOR_DEVICES,
|
|
25
|
-
CO2_PER_KWH_IN_DC_GREY,
|
|
26
|
-
};
|
package/src/hosting-api.test.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const hosting = require("./hosting-api");
|
|
4
|
-
const nock = require("nock");
|
|
5
|
-
|
|
6
|
-
describe("hostingAPI", function () {
|
|
7
|
-
describe("checking a single domain with #check", function () {
|
|
8
|
-
it("using the API", async function () {
|
|
9
|
-
const scope = nock("https://api.thegreenwebfoundation.org/")
|
|
10
|
-
.get("/greencheck/google.com")
|
|
11
|
-
.reply(200, {
|
|
12
|
-
url: "google.com",
|
|
13
|
-
green: true,
|
|
14
|
-
});
|
|
15
|
-
const res = await hosting.check("google.com");
|
|
16
|
-
expect(res).toEqual(true);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe("implicitly checking multiple domains with #check", function () {
|
|
20
|
-
it("using the API", async function () {
|
|
21
|
-
const scope = nock("https://api.thegreenwebfoundation.org/")
|
|
22
|
-
.get("/v2/greencheckmulti/[%22google.com%22,%22kochindustries.com%22]")
|
|
23
|
-
.reply(200, {
|
|
24
|
-
"google.com": {
|
|
25
|
-
url: "google.com",
|
|
26
|
-
green: true,
|
|
27
|
-
},
|
|
28
|
-
"kochindustries.com": {
|
|
29
|
-
url: "kochindustries.com",
|
|
30
|
-
green: null,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
const res = await hosting.check(["google.com", "kochindustries.com"]);
|
|
34
|
-
expect(res).toContain("google.com");
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const log = require("debug")("tgwf:url2green:test");
|
|
4
|
-
const { hosting } = require("@tgwf/url2green");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
const dbPath = path.resolve(
|
|
8
|
-
__dirname,
|
|
9
|
-
"..",
|
|
10
|
-
"data",
|
|
11
|
-
"fixtures",
|
|
12
|
-
"url2green.test.db"
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
describe("hostingDatabase", function () {
|
|
16
|
-
describe("checking a single domain with #check", function () {
|
|
17
|
-
test("tries to use a local database if available ", async function () {
|
|
18
|
-
const res = await hosting.check("google.com", dbPath);
|
|
19
|
-
expect(res).toEqual(true);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe("implicitly checking multiple domains with #check", function () {
|
|
23
|
-
test("tries to use a local database if available", async function () {
|
|
24
|
-
const res = await hosting.check(
|
|
25
|
-
["google.com", "kochindustries.com"],
|
|
26
|
-
dbPath
|
|
27
|
-
);
|
|
28
|
-
expect(res).toContain("google.com");
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
package/src/hosting-json.test.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const hosting = require("./hosting-json");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
describe("hostingJSON", function () {
|
|
7
|
-
const jsonPath = path.resolve(
|
|
8
|
-
__dirname,
|
|
9
|
-
"..",
|
|
10
|
-
"data",
|
|
11
|
-
"fixtures",
|
|
12
|
-
"url2green.test.json"
|
|
13
|
-
);
|
|
14
|
-
const jsonPathGz = path.resolve(
|
|
15
|
-
__dirname,
|
|
16
|
-
"..",
|
|
17
|
-
"data",
|
|
18
|
-
"fixtures",
|
|
19
|
-
"url2green.test.json.gz"
|
|
20
|
-
);
|
|
21
|
-
describe("checking a single domain with #check", function () {
|
|
22
|
-
test("against the list of domains as JSON", async function () {
|
|
23
|
-
const db = await hosting.loadJSON(jsonPath);
|
|
24
|
-
const res = await hosting.check("google.com", db);
|
|
25
|
-
expect(res).toEqual(true);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe("checking a single domain with #check", function () {
|
|
29
|
-
test("against the list of domains as JSON loaded from a gzipped JSON", async function () {
|
|
30
|
-
const db = await hosting.loadJSON(jsonPathGz);
|
|
31
|
-
const res = await hosting.check("google.com", db);
|
|
32
|
-
expect(res).toEqual(true);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe("implicitly checking multiple domains with #check", function () {
|
|
36
|
-
test("against the list of domains as JSON", async function () {
|
|
37
|
-
const db = await hosting.loadJSON(jsonPath);
|
|
38
|
-
const domains = ["google.com", "kochindustries.com"];
|
|
39
|
-
|
|
40
|
-
const res = await hosting.check(domains, db);
|
|
41
|
-
expect(res).toContain("google.com");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|