Public
Edited
Oct 18, 2023
Insert cell
Insert cell
meta = fetch(
`https://api.targomo.com/statistics/collection/meta/79?key=${targomoKey()}`
).then((response) => response.json())
Insert cell
statsRequestConfig = (mode) => ({
statisticIds: [statistic.statistic_id], // all the statistics we want to include in the results
statisticCollectionId: 79,
edgeWeight: "time",
travelType: mode,
maxEdgeWeight: 900,
sources: [{ id: "Marker1", y: 43.7023349, x: 7.2559326 }],
serviceUrl: "https://api.targomo.com/westcentraleurope",
serviceKey: targomoKey()
})
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data = [
...Object.entries(bikeStats).map(([id, time]) => {
return {
id,
mode: "bike",
time
};
}),
...Object.entries(transitStats).map(([id, time]) => {
return {
id,
mode: "transit",
time
};
})
].reduce((acc, cur) => {
const match = acc.find((d) => d.id && d.id === cur.id);
if (match) {
match[cur.mode] = cur.time;
} else {
const obj = {
id: cur.id
};
obj[cur.mode] = cur.time;
acc.push(obj);
}
return acc;
}, [])
Insert cell
bikeStats = fetch(
`https://api.targomo.com/statistics/traveltimes?apiKey=${targomoKey()}&serviceUrl=https://api.targomo.com/westcentraleurope`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(statsRequestConfig("bike"))
}
).then((response) => response.json())
Insert cell
transitStats = fetch(
`https://api.targomo.com/statistics/traveltimes?apiKey=${targomoKey()}&serviceUrl=https://api.targomo.com/westcentraleurope`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(statsRequestConfig("transit"))
}
).then((response) => response.json())
Insert cell
Insert cell
Insert cell
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