Skip to content

Commit

Permalink
Fix the figures to use averages, not wifi
Browse files Browse the repository at this point in the history
Previously we were using the figure for wifi for bandwidth.

Switch to using average of all the three kinds, to give an idea.

We should make this a weight average in future.
  • Loading branch information
mrchrisadams committed Feb 28, 2020
1 parent e014054 commit 8751a2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/1byte.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ const CO2_PER_KWH_IN_DC_GREY = 519;
// 2. the *making* the device, which is comparitively high.

const KWH_PER_BYTE_IN_DC = 0.00000000072;

// this is probably best left as something users can define, or
// a weighted average based on total usage.
// Pull requests gratefully accepted
const KWH_PER_BYTE_FOR_NETWORK = 0.00000000488;

const KWH_PER_BYTE_FOR_DEVICES = 0.00000000013
module.export = {
module.exports = {
KWH_PER_BYTE_IN_DC,
KWH_PER_BYTE_FOR_NETWORK,
KWH_PER_BYTE_FOR_DEVICES,
CO2_PER_KWH_NETWORK_GREY
CO2_PER_KWH_IN_DC_GREY
}
10 changes: 5 additions & 5 deletions src/co2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const pagexray = require('pagexray');
describe('sustainableWeb', function () {
describe('co2', function () {
let har;
const TGWF_GREY_VALUE = 0.8193815884799998;
const TGWF_GREY_VALUE = 2.0484539712;
const TGWF_GREEN_VALUE = 0.54704300112;
const TGWF_MIXED_VALUE = 0.57128033088;
const TGWF_MIXED_VALUE = 1.7485750598399998;

const MILLION = 1000000;
const MILLION_GREY = 1.1625599999999998;
const MILLION_GREEN = 0.77616;
const MILLION_GREY = 2.9064;
const MILLION_GREEN = 2.4393599999999998;

beforeEach(function () {
har = JSON.parse(fs
Expand All @@ -31,7 +31,7 @@ describe('sustainableWeb', function () {
});

it("returns a lower CO2 number for data transfer from domains using entirely 'green' power", function () {
expect(co2.perByte(MILLION, false)).toBe(1.1625599999999998);
expect(co2.perByte(MILLION, false)).toBe(MILLION_GREY);
expect(co2.perByte(MILLION, true)).toBe(MILLION_GREEN);
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/hosting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('hosting', function () {
har = JSON.parse(fs
.readFileSync(path.resolve(__dirname, '../data/fixtures/tgwf.har'), 'utf8'))
});
describe('checking all domains on a page object with #checkPage ', async function () {
describe('checking all domains on a page object with #checkPage ', function () {
it('it returns a list of green domains, when passed a page object', async function () {
const pages = pagexray.convert(har);
const pageXrayRun = pages[0];
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('hosting', function () {
// 'it returns an empty list, when passed a page object with no green domains'
// );
});
describe('checking a single domain with #check', async function () {
describe('checking a single domain with #check', function () {
it("tries to use a local database if available ", async function () {
const res = await hosting.check("google.com", "../url2green.test.db")
expect(res).toEqual(true)
Expand All @@ -57,7 +57,7 @@ describe('hosting', function () {
})

})
describe('implicitly checking multiple domains with #check', async function () {
describe('implicitly checking multiple domains with #check', function () {
it("tries to use a local database if available", async function () {
const res = await hosting.check(["google.com", "kochindustries.com"], "../url2green.test.db")
expect(res).toContain("google.com")
Expand All @@ -67,7 +67,7 @@ describe('hosting', function () {
expect(res).toContain("google.com")
})
})
describe('explicitly checking multiple domains with #checkMulti', async function () {
describe('explicitly checking multiple domains with #checkMulti', function () {
it("tries to use a local database if available", async function () {
const res = await hosting.checkMulti(["google.com", "kochindustries.com"])
expect(res).toContain("google.com")
Expand Down

0 comments on commit 8751a2a

Please sign in to comment.