Public
Edited
Jan 24, 2023
Insert cell
Insert cell
Insert cell
targetStatistics = [
{ id: 0, desc: "total population" },
{ id: 1, desc: "population 0-10" },
{ id: 2, desc: "population 10-19" },
{ id: 3, desc: "population 20-29" },
{ id: 4, desc: "population 30-39" },
{ id: 5, desc: "population 40-49" },
{ id: 6, desc: "population 50-59" },
{ id: 7, desc: "population 60-69" },
{ id: 8, desc: "population 70-79" },
{ id: 9, desc: "population 80+" }
]
Insert cell
Insert cell
config = ({
statisticIds: targetStatistics.map((s) => s.id), // mapping to array of numbers
serviceUrl: "https://api.targomo.com/westcentraleurope",
statisticCollectionId: 100, // Germany: Destatis 2018
edgeWeight: "time",
travelType: "bike",
bikeSpeed: 25, // bike speed overrides go here
bikeUphill: 2,
bikeDownhill: -2,
maxEdgeWeight: 600, // 10 minutes max routing. We can make a single request, since the results are divided into bands
// omitIndividualStatistics: true, // since only requesting for an individual location, we don't need this extra separation of results
sources: [
{
id: "DE_MUC_SCHW",
y: 48.16686999898724,
x: 11.585899997309724
}
]
})
Insert cell
Insert cell
data = {
const response = await fetch(
"https://api.targomo.com/statistics/charts/dependent?serviceUrl=https://api.targomo.com/westcentraleurope",
{
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({ ...config, ...{ serviceKey: targomoKey() } })
}
);
const responseJson = await response.json();
return responseJson;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function sumToMax(maxTime, statsObject) {
return Object.keys(statsObject)
.filter((s) => s <= maxTime)
.map((s) => statsObject[s])
.reduce((acc, val) => acc + val, 0);
}
Insert cell
Insert cell
statsTotals = Object.keys(data.statistics).map((k) => ({
statistic: targetStatistics.find((s) => s.id === +k).desc,
total_5min: sumToMax(300, data.statistics[k]),
total_10min: sumToMax(600, data.statistics[k])
}))
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