Published
Edited
Jun 14, 2022
Insert cell
Insert cell
input = ({
variables: {
"3512": {
years: [1983, 1985, 1985],
entities: [99, 45, 204],
values: [5.5, 4.2, 12.6],
id: 3512,
name: "Prevalence of wasting, weight for height (% of children under 5)",
unit: "% of children under 5",
description: "Prevalence of...",
shortUnit: "%",
display: {
name: "Some Display Name",
},
source: {
id: 2174,
name: "World Bank - WDI: Prevalence of wasting, weight for height (% of children under 5)",
link: "http://data.worldbank.org/data-catalog/world-development-indicators",
},
},
},
entityKey: {
45: { name: "Cape Verde", code: "CPV", id: 45 },
99: { name: "Papua New Guinea", code: "PNG", id: 99 },
204: { name: "Kiribati", code: "KIR", id: 204 },
},
})
Insert cell
convert = (i) => {
const varData = [];
for (const [id, entry] of Object.entries(i.variables)) {
const data = {
entities: entry.entities,
values: entry.values,
years: entry.years
};
const metadata = _.omit(entry, ["entities", "values", "years"]);
metadata.dimensions = {};
metadata.dimensions.entities = {};
metadata.dimensions.entities.values = Object.values(input.entityKey);
metadata.dimensions.years = {};
metadata.dimensions.years.values = _.uniq(data.years).map((year) => ({
id: year
}));
varData.push([parseInt(id), { data, metadata }]);
}
return varData;
}
Insert cell
output = convert(input)
Insert cell
"const legacyVariableConfig: MultipleOwidVariableDataDimensionsMap = new Map(" +
JSON.stringify(output, null, 2) +
")"
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