Public
Edited
Jan 17, 2024
1 fork
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
simpleCriteria = {
return {
nightClubs: {
type: "poiCoverageCount",
osmTypes: [
{
key: "group",
value: "nightclub"
}
],
maxEdgeWeight: maxEdgeWeight * 60,
edgeWeight: "time",
travelMode: travel,
coreServiceUrl: "https://api.targomo.com/westcentraleurope"
}
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
simpleResponse = {
let response = await fetch(
`https://api.targomo.com/quality/v1/scores?showDetails=true&apiKey=${targomoKey()}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ locations, criteria: { ...simpleCriteria } }),
mode: "cors"
}
).then((response) => {
if (!response.ok) {
console.log(response);
throw new Error(response.status);
}
return response.json();
});
return response["data"];
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
statisticsCriteria = {
return {
youngPopulation: {
type: "statisticsSum",
statisticGroupId: 100,
statisticsIds: [3],
referenceStatisticsIds: [],
maxEdgeWeight: maxEdgeWeight * 60,
edgeWeight: "time",
travelMode: travel,
coreServiceUrl: "https://api.targomo.com/westcentraleurope"
}
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
complexCriteria = {
return {
nightClubVSyoungPopulation: {
type: "mathAggregation",
mathExpression: "{nightClubs}/max(1,{youngPopulation})", // Be careful: we don't want to divide by 0
criterionParameters: {
youngPopulation: {
type: "statisticsDistance",
statisticGroupId: 100,
statisticsIds: [3],
referenceStatisticsIds: [],
maxEdgeWeight: maxEdgeWeight * 60,
edgeWeight: "time",
travelMode: travel,
coreServiceUrl: "https://api.targomo.com/westcentraleurope"
},
nightClubs: {
type: "poiCoverageCount",
osmTypes: [
{
key: "group",
value: "nightclub"
}
],
maxEdgeWeight: maxEdgeWeight * 60,
edgeWeight: "time",
travelMode: travel,
coreServiceUrl: "https://api.targomo.com/westcentraleurope"
}
}
}
};
}
Insert cell
Insert cell
Insert cell
Insert cell
normalizedNightClubs = {
let newObj = copyObject(simpleResponse);
let [min, max] = getMinMaxFrom(simpleResponse);

Object.values(newObj).map((e) => {
e.scores["nightClubsNormalized"] =
(e.scores["nightClubs"] - min) / (max - min); // Simple normalization formula: = (value - min) / (max - min)
});
return newObj;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
combinedResult = {
let result = {};
let [youngPopulationWeight, nightClubsWeight] = getWeights();

Object.keys(normalizedNightClubs).map((key) => {
let nightClubValue = normalizedNightClubs[key].scores.nightClubsNormalized;
let youngPopulationValue =
normalizedYoungPopulation[key].scores.youngPopulationNormalized;

result[key] = {
scores: {
weightedAverage:
(nightClubValue * nightClubsWeight +
youngPopulationValue * youngPopulationWeight) /
(nightClubsWeight + youngPopulationWeight)
}
};
});
return result;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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