// derived from https://sustainablewebdesign.org/estimating-digital-emissions/ const GRID = 494; // in gCO2e/kWh // operational energy intensity (kWh/GB) const OP = { dc: 0.055, net: 0.059, ud: 0.08 }; // embodied energy intensity (kWh/GB) const EM = { dc: 0.012, net: 0.013, ud: 0.081 }; // this function uses some defaults from the spec. // green hosting factor is prob the most important // one to change here function estimateEmissions( bytes: number, { greenHostingFactor = 1, returnVisitorRatio = 0, dataCacheRatio = 0.02, } = {}, ) { const newVisitorRatio = 1 - returnVisitorRatio; const gb = bytes / 1e9; // operational emissions data centers const OPDC = gb * OP.dc * GRID * (1 - greenHostingFactor); // embodied emissions data centers const EMDC = gb * EM.dc * GRID; // operational emissions networks const OPN = gb * OP.net * GRID; // embodied emissions networks const EMN = gb * EM.net * GRID; // operational emissions user devices const OPUD = gb * OP.ud * GRID; // embodied emissions user devices const EMUD = gb * EM.ud * GRID; const perVisit = OPDC + EMDC + OPN + EMN + OPUD + EMUD; return ( perVisit * newVisitorRatio + perVisit * returnVisitorRatio * (1 - dataCacheRatio) ); }