Skip to content

Commit

Permalink
Use base 10 (1000) vs base 2 (1024) for network calcs
Browse files Browse the repository at this point in the history
Update our constants and tests to use idiomatic numbers for transfer, not for storage.
  • Loading branch information
mrchrisadams committed Aug 1, 2022
1 parent 80c0148 commit 929949a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/co2.test.js
Expand Up @@ -152,12 +152,12 @@ describe("co2", () => {
// we include more of the system in calculations for the
// same levels of data transfer
const MILLION = 1000000;
const MILLION_GREY = 0.33343;
const MILLION_GREEN = 0.28908;
const MILLION_GREY = 0.35802;
const MILLION_GREEN = 0.31039;

const TGWF_GREY_VALUE = 0.23501;
const TGWF_GREY_VALUE = 0.25234;
const TGWF_GREEN_VALUE = 0.54704;
const TGWF_MIXED_VALUE = 0.20652;
const TGWF_MIXED_VALUE = 0.22175;

beforeEach(() => {
co2 = new CO2({ model: swd });
Expand Down
2 changes: 1 addition & 1 deletion src/constants/file-size.js
@@ -1,4 +1,4 @@
const GIGABYTE = 1024 * 1024 * 1024;
const GIGABYTE = 1000 * 1000 * 1000;

export default {
GIGABYTE,
Expand Down
20 changes: 10 additions & 10 deletions src/sustainable-web-design.test.js
Expand Up @@ -8,17 +8,17 @@ describe("sustainable web design model", () => {
it("should return a object with numbers for each system component", () => {
const groupedEnergy = swd.energyPerByteByComponent(averageWebsiteInBytes);

expect(groupedEnergy.consumerDeviceEnergy).toBeCloseTo(0.00088564, 8);
expect(groupedEnergy.networkEnergy).toBeCloseTo(0.00023844, 8);
expect(groupedEnergy.productionEnergy).toBeCloseTo(0.0003236, 8);
expect(groupedEnergy.dataCenterEnergy).toBeCloseTo(0.00025547, 8);
expect(groupedEnergy.consumerDeviceEnergy).toBeCloseTo(0.00095095, 8);
expect(groupedEnergy.networkEnergy).toBeCloseTo(0.00025602, 7);
expect(groupedEnergy.productionEnergy).toBeCloseTo(0.0003475, 7);
expect(groupedEnergy.dataCenterEnergy).toBeCloseTo(0.00027431, 8);
});
});

describe("energyPerByte", () => {
it("should return a number in kilowatt hours for the given data transfer in bytes", () => {
const energyForTransfer = swd.energyPerByte(averageWebsiteInBytes);
expect(energyForTransfer).toBeCloseTo(0.00170316, 7);
expect(energyForTransfer).toBeCloseTo(0.00182874, 7);
});
});

Expand All @@ -35,7 +35,7 @@ describe("sustainable web design model", () => {

it("should calculate the correct energy", () => {
expect(swd.energyPerVisit(averageWebsiteInBytes)).toBe(
0.001285882415771485
0.0013807057305600004
);
});

Expand All @@ -49,20 +49,20 @@ describe("sustainable web design model", () => {

// with the constants switched around so the first view is 0.75, now 0.25
// we should we the page come back at 0.57g not 0.2
expect(swd.emissionsPerVisitInGrams(v9currentEnergyCalc)).toEqual(0.57);
expect(swd.emissionsPerVisitInGrams(v8VersionEnergyCalc)).toEqual(0.2);
expect(swd.emissionsPerVisitInGrams(v9currentEnergyCalc)).toEqual(0.61);
expect(swd.emissionsPerVisitInGrams(v8VersionEnergyCalc)).toEqual(0.21);
});
});

describe("emissionsPerVisitInGrams", () => {
it("should calculate the correct co2 per visit", () => {
const energy = swd.energyPerVisit(averageWebsiteInBytes);
expect(swd.emissionsPerVisitInGrams(energy)).toEqual(0.57);
expect(swd.emissionsPerVisitInGrams(energy)).toEqual(0.61);
});

it("should accept a dynamic KwH value", () => {
const energy = swd.energyPerVisit(averageWebsiteInBytes);
expect(swd.emissionsPerVisitInGrams(energy, 245)).toEqual(0.32);
expect(swd.emissionsPerVisitInGrams(energy, 245)).toEqual(0.34);
});
});

Expand Down

0 comments on commit 929949a

Please sign in to comment.