Public
Edited
Jul 9, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
tripsData = fetch("https://dc-streetcar_vehicles-worker.jmuyskens.workers.dev/").then(d => d.json())
Insert cell
trips
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
trips = tripsData.map(location => {
const time = new Date(location.time)
const stale = Date.now() - time
const schAdhMinutes = location.schAdhSecs/60
return {
...location, time, stale, schAdhMinutes
}
})
Insert cell
latestLocation = [...Object.entries(tripsData)].reduce(
(acc, tripObj) => {
const [tripId, trip] = tripObj
const {id, direction, serviceDate, locations} = trip
const location = locations[locations.length - 1]
const time = new Date(location.time * 1000)
location.stale = Date.now() - time
if (location.stale < (10 * 60 * 1000)) {
acc.push({
id, direction, serviceDate, ...location, time
})
}

return acc
},
[]
)
Insert cell
Insert cell
Insert cell
Insert cell
data = fetch("https://dc-streetcar_predictions-worker.jmuyskens.workers.dev").then((response) => response.json())
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