Public
Edited
Sep 18, 2023
Insert cell
Insert cell
fetch(
"https://api-v3.mbta.com/predictions?filter[stop]=70020&sort=arrival_time&include=vehicle.stop"
)
.then((response) => response.json())
.then(({ data, included }) => foo(data, included))
Insert cell
foo = (data, included) => {
const vehiclesById = Object.fromEntries(
included.filter(({ type }) => type === "vehicle").map((v) => [v.id, v])
);

const stopsById = Object.fromEntries(
included.filter(({ type }) => type === "stop").map((s) => [s.id, s])
);

const vehicleId = data[0].relationships.vehicle.data.id;
const nextVehicle = vehiclesById[vehicleId];

const nextStopId = nextVehicle.relationships.stop.data.id;
const nextStopName = stopsById[nextStopId];
return nextStopName;

return md`${nextVehicle.attributes.current_status} `;

return nextVehicle.relationships.stop;
return nextVehicle.attributes.carriages;
}
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