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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more