Published
Edited
Apr 3, 2020
Importers
Insert cell
Insert cell
Insert cell
table(normalizedData.filter(item => item.date === date))
Insert cell
normalizedData = rawData.reduce((result, entry) => {
const date = new Date(entry.year, entry.month - 1, entry.day)
.toISOString()
.replace(/T.*/, '');
const country = matchCountry(entry.countriesAndTerritories);
const province = '';
const total = entry.cases;
let growth = 0;
const prevEntry = rawData.find(
_entry =>
_entry.year === entry.year &&
_entry.month === entry.month &&
_entry.day === entry.day - 1 &&
_entry.countriesAndTerritories === entry.countriesAndTerritories
);
if (prevEntry && prevEntry.cases > 0 && total > 0) {
growth = ((total - prevEntry.cases) / prevEntry.cases).toFixed(2);
}
return [
...result,
{
country,
province,
date,
growth,
total
}
];
}, [])
Insert cell
rawData = {
// const input = new Uint8Array(downloadedData || uploadedData || attachedData);
const input = new Uint8Array(downloadedData);
const wb = xlsx.read(input, { type: 'array' });
const ws = wb.Sheets[wb.SheetNames[0]];
return xlsx.utils.sheet_to_json(ws);
}
Insert cell
countries = rawData
.reduce((result, entry) => {
const country = matchCountry(entry.countriesAndTerritories);
if (!country || result.find(_country => _country === country)) {
return result;
}
return [...result, country];
}, [])
.sort()
Insert cell
dates = rawData
.reduce((result, entry) => {
const date = new Date(entry.year, entry.month - 1, entry.day)
.toISOString()
.replace(/T.*/, '');
if (result.find(_date => _date === date)) {
return result;
}
return [...result, date];
}, [])
.sort()
.reverse()
Insert cell
downloadedData = {
const date = new Date();
let attempts = 1;
async function tryFetch() {
if (attempts > 10) return attachedData;
attempts++;
const response = await fetch(
`//cors-anywhere.herokuapp.com/https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-${new Date(
date.setDate(date.getDate() - 1)
)
.toISOString()
.replace(/T.*/, '')}.xlsx`
);
if (response.ok) return response.arrayBuffer();
return tryFetch();
}

return tryFetch();
}
Insert cell
attachedData = FileAttachment(
'COVID-19-geographic-disbtribution-worldwide-2020-03-24.xlsx'
).arrayBuffer()
Insert cell
xlsx = require('//bundle.run/xlsx@0.14.1')
Insert cell
import { vl } from '@vega/vega-lite-api'
Insert cell
import { table } from '@gnestor/table'
Insert cell
import { matchCountry } from '@gnestor/countries'
Insert cell
import { file, select } from '@jashkenas/inputs'
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