Published
Edited
May 15, 2020
Insert cell
md`# Probe disco`
Insert cell
rawDiscos = await FileAttachment("probe_disco_33782_2@1.json").json()
Insert cell
discoIntervals = rawDiscos
.map(p => ({ type: p.event, date: new Date(p.timestamp * 1000) }))
.reduce((acc, e, i, discos) => {
const from = e.date
const to = discos[i+1] && discos[i+1].date || new Date()
acc.push({
from: from,
to: to,
event: e.type,
duration: luxon.Duration.fromMillis(to - from).as("seconds")
});
return acc
}, [])
Insert cell
discoIntervals[discoIntervals.length - 1]
Insert cell
d3TimeDays = discoIntervals.reduce((acc, e) => {
const d = acc.find(de => de.date.toDateString() === e.from.toDateString());
if (d) {
d.details.push({ date: e.from, value: e.duration, name: e.event });
}
else {
acc.push({ date: e.from, details: [{ date: e.from, value: e.duration, name: e.event }]});
}
return acc
}, [])
Insert cell
luxon = import("luxon")
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