Skip to content

Instantly share code, notes, and snippets.

@thibaudcolas
Created January 23, 2025 13:07
  • Select an option

Select an option

Revisions

  1. thibaudcolas created this gist Jan 23, 2025.
    34 changes: 34 additions & 0 deletions carbon-ratings-swdm-v4-co2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import { co2 } from "@tgwf/co2";

    const swdmV4 = new co2({ model: "swd", version: 4 });

    // Figures as of 2025-01-23
    // https://sustainablewebdesign.org/digital-carbon-ratings/
    const ratings = {
    "A+": 272.51,
    A: 531.15,
    B: 975.85,
    C: 1410.39,
    D: 1875.01,
    E: 2419.56,
    F: 2419.57,
    };

    /**
    * Re-calculate the Digital Carbon Rating Scale thresholds for each percentile transfer size,
    * to compare with official figures.
    */
    Object.entries(ratings).forEach(([rating, ratingValue]) => {
    const estimate = swdmV4.perVisitTrace(ratingValue * 1000, false, {
    gridIntensity: {
    device: 494,
    dataCenter: 494,
    networks: 494,
    },
    firstVisitPercentage: 1,
    returnVisitPercentage: 0,
    dataReloadRatio: 0,
    });

    console.log(`${rating}: ${estimate.co2}`);
    });