Published
Edited
Apr 29, 2021
3 stars
Also listed in…
COVID
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
regions = [...new Set(map(k => k.region)(probes).filter(k => k))].sort()
Insert cell
Insert cell
r = d3.json("https://data.rivm.nl/covid-19/COVID-19_reproductiegetal.json")
Insert cell
R = r.map(k => ({date: new Date(k.Date), value: k.Rt_avg ? k.Rt_avg - 1: NaN}))
Insert cell
Insert cell
Insert cell
// takes probes and region
// returns TimeChart for specified region with proper title
strip = curry(
(probes, region) =>
timeChart(
pipe(
select(probes),
totals,
)(region),
{title: region}
)
)
Insert cell
strip(probes, "Utrecht")
Insert cell
// takes a region (name)
// returns list of probes for that region
select = curry(
(probes, region) =>
probes.filter(k => (k.region === region))
)
Insert cell
select(probes, "Utrecht")
Insert cell
// takes a list of probes for a region that may have multiple reports for same date (per municipality)
// returns a list of probes with sum of reports per unique date
totals = (list) => {
const d = new InternMap()
list.forEach((item) => d.set(item.date, (d.get(item.date) ?? 0) + item.value))
return timeChartify([...d])
}
Insert cell
pipe(select(probes), totals)("Utrecht")
Insert cell
// takes list of arrays with two entries: date and value
// returns list of objects with date and value as properties
timeChartify = map(
([date, value]) =>
({date, value})
)
Insert cell
// Setting defaults
timeChart = TimeChart.defaults({
...timeChartConfig,
dateFormat: "%m/%d/%Y",
marginTop: 2,
scheme: "reds",
})
Insert cell
// uses probes
// returns object with some data-specific configuration to drive TimeChart
timeChartConfig = {
const [start, stop] = d3.extent(probes, x => x.date)
return ({
interval: d3.utcDay,
start,
stop,
width,
})
}
Insert cell
formatDate = d => d.toLocaleString(undefined, {
weekday: "short",
month: "short",
day: "numeric",
year: "numeric",
})
Insert cell
Insert cell
// performance: for/reduce/ramda = 2.4/3.2/9.7 ms: ramda is 2-4 times slower than plain js
{
return md`Comment the \`return\` out to get performance data in console`

console.time("for")
let s = 0
for (let i = 0, n = probes.length; i < n; ++i) s += probes[i].value
console.timeEnd("for")

console.time("reduce")
const r = probes.reduce((p, d) => p + d.value, 0)
console.timeEnd("reduce")
console.time("ramda")
const t = reduce((p, d) => p + d.value, 0)(probes)
console.timeEnd("ramda")

return [s, r, t]
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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