Public
Edited
May 2, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
tgwf = import("https://cdn.skypack.dev/@tgwf/co2")
Insert cell
Insert cell
function estimateEmissions(bytes) {
// Without passing in a model, 1byte is the default
const oneByte = new tgwf.co2({ model: '1byte' })
const oneByteEstimate = oneByte.perByte(bytes).toFixed(5)

// Notice here that we pass in a model parameter.
const swd = new tgwf.co2({ model: 'swd' })

/*
The Sustainable Web Design (SWD) model has two methods:
- perByte(): Which returns a value for raw data transfer.
- perView(): Which returns a value for data transfer taking into account
the assumptions the SWD model makes for website caching & return visitors.
*/
const swdPerByteEstimate = swd.perByte(bytes).toFixed(5)
const swdPerVisitEstimate = swd.perVisit(bytes).toFixed(5)

return [
{oneByteEstimate,
swdPerByteEstimate,
swdPerVisitEstimate }
]
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
emissions = estimateEmissions(input)
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more