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 prevEntry = result.find(
_entry => _entry['Country/Region'] === entry['Country/Region']
);
if (prevEntry) {
Object.entries(entry)
.filter(([key, value]) => key.match(/\d+\/\d+\/\d+/))
.forEach(([key, value]) => {
prevEntry[key] =
(parseInt(prevEntry[key]) || 0) + (parseInt(value) || 0);
});
prevEntry['Province/States'] = '';
return [
...result.filter(
_entry => _entry['Country/Region'] !== entry['Country/Region']
),
prevEntry
];
}
return [...result, entry];
}, [])
.reduce((result, entry) => {
const country = matchCountry(entry['Country/Region']);
const province = entry['Province/States'];
let prevTotal = 0;
const entries = Object.entries(entry)
.filter(([key, value]) => key.match(/\d+\/\d+\/\d+/))
.sort((a, b) => new Date(a[0]) - new Date(b[0]))
.map(([key, value]) => {
const date = new Date(key).toISOString().replace(/T.+/, '');
const total = parseInt(value) || 0;
let growth = 0;
if (total > 0) {
growth = ((total - prevTotal) / total).toFixed(2);
prevTotal = total;
} else {
prevTotal = 0;
}
return {
country,
province,
date,
growth,
total
};
});
return [...result, ...entries];
}, [])
Insert cell
rawData = await d3.csv(
'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/who_covid_19_situation_reports/who_covid_19_sit_rep_time_series/who_covid_19_sit_rep_time_series.csv'
)
Insert cell
countries = rawData
.reduce((result, entry) => {
const country = matchCountry(entry['Country/Region']);
if (!country || result.find(_country => _country === country)) {
return result;
}
return [...result, country];
}, [])
.sort()
Insert cell
dates = Object.keys(rawData[0])
.filter(key => key.match(/\d+\/\d+\/\d+/))
.map(key => new Date(key).toISOString().replace(/T.+/, ''))
.sort()
.reverse()
Insert cell
import {table} from '@gnestor/table'
Insert cell
import { matchCountry } from '@gnestor/countries'
Insert cell
import {select} from '@jashkenas/inputs'
Insert cell
d3 = require('d3')
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