Public
Edited
May 7
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",
statisticCollectionId: 198,
statisticsIds: [49],
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

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