Public
Edited
Oct 5, 2023
Insert cell
Insert cell
Insert cell
Insert cell
meta = fetch(
`https://api.targomo.com/statistics/collection/meta/79?key=${targomoKey()}`
).then((response) => response.json())
Insert cell
statsRequestConfig = ({
statisticIds: [statistic.statistic_id], // all the statistics we want to include in the results
statisticCollectionId: 79,
edgeWeight: "time",
travelType: "bike",
maxEdgeWeight: 900,
sources: [s1, s2],
serviceUrl: "https://api.targomo.com/westcentraleurope",
serviceKey: targomoKey()
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dependent = fetch(
`https://api.targomo.com/statistics/charts/dependent?apiKey=${targomoKey()}&serviceUrl=${
statsRequestConfig.serviceUrl
}`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(statsRequestConfig)
}
).then((response) => response.json())
Insert cell
independent = fetch(
`https://api.targomo.com/statistics/charts/independent?apiKey=${targomoKey()}&serviceUrl=${
statsRequestConfig.serviceUrl
}`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(statsRequestConfig)
}
).then((response) => response.json())
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sourceDependent = ({
s1: Math.round(
Object.values(
dependent.individualStatistics.s1.statistics[statistic.statistic_id]
).reduce((acc, cur) => {
return acc + cur;
}, 0)
),
s2: Math.round(
Object.values(
dependent.individualStatistics.s2.statistics[statistic.statistic_id]
).reduce((acc, cur) => {
return acc + cur;
}, 0)
)
})
Insert cell
Insert cell
Insert cell
data = fetch("https://api.weather.gov/gridpoints/OKX/33,37/forecast").then((response) => response.json())
Insert cell
MapSources = new mapSources([
{ lng: 2.350838, lat: 48.861653, id: "s1" },
{ lng: 2.362131, lat: 48.858889, id: "s2" }
])
Insert cell
class mapSources {
sources = [];
constructor(sources) {
this.sources = sources;
}
getSource(id) {
return this.sources.find((d) => d.id === id);
}
getCenter() {
const lng =
this.sources.reduce((acc, cur) => {
acc += cur.lng;
return acc;
}, 0) / this.sources.length;
const lat =
this.sources.reduce((acc, cur) => {
acc += cur.lat;
return acc;
}, 0) / this.sources.length;

return { lng, lat };
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more