Published
Edited
Jun 25, 2021
1 star
Insert cell
Insert cell
md`*A final version of this notebook can be viewed on my blog [here](https://www.robinlinacre.com/offsetting_renewables/).*`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { get_sources } from "@robinl/magic-energy-usage-and-carbon-emissions-converter"
Insert cell
Insert cell
gbp_xrs = {
return {
USD: 1.39
};
}
Insert cell
eu = require("@robinl/energy_usage@0.1.6")
Insert cell
per = eu.convert.per
Insert cell
fmt_per = function(to_over_from) {
return fmt_num(eu.convert.per(to_over_from))
}
Insert cell
d3 = require("d3-format")
Insert cell
fmt_num = function(d) {return d3.format(",.2r")(d)}
Insert cell
Insert cell
Insert cell
xr_string = function(amount, in_currency = "USD", out_currency = "GBP") {
let gbp;
if (in_currency == "GBP") {
let converted = amount * gbp_xrs[out_currency];
return `${format_currency(amount)} = ${format_currency(converted, out_currency)}`;
}
if (out_currency == "GBP") {
gbp = amount / gbp_xrs[in_currency];
return `${format_currency(gbp)} = ${format_currency(amount, in_currency)}`;
}
}
Insert cell
xr_string(10.1, "EUR")
Insert cell
xr_string(10.1, "GBP", "USD")
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