async function getData(city, nPoints, nRegions, nVehiclesPerRegion) {
const url = `https://m4aqpzp5ah6n7ilzunwyo5ma2u0ezqcc.lambda-url.us-east-2.on.aws/?region=${city}&number=${nPoints}&vehicles=${
nRegions * nVehiclesPerRegion
}&type=darp`;
const response = await fetch(url);
const json = await response.json();
const locations = [];
const nResidentialPoints = Math.floor(nPoints * RESIDENTIAL_PERCENT);
const nCommercialPoints = Math.floor(nPoints * COMMERCIAL_PERCENT);
const points = json.pointsArray.map((point) => [
parseFloat(point.pickup_longitude),
parseFloat(point.pickup_latitude)
]);
const regions = getRegions(points, nRegions);
json.pointsArray.forEach((point, pointIdx) => {
const locationType =
pointIdx < nResidentialPoints
? "residential"
: pointIdx < nResidentialPoints + nCommercialPoints
? "commercial"
: "medical";
for (const [regionId, region] of regions.entries()) {
const pt = [
parseFloat(point.pickup_longitude),
parseFloat(point.pickup_latitude)
];
if (turf.inside(turf.point(pt), region.polygon)) {
const solid = Math.random() < 0.5;
const organic = Math.random() < 0.5;
let _skills = [];
if (solid) _skills.push(skills.solid);
if (organic) _skills.push(skills.organic);
if (locationType === "medical") _skills.push(skills.medical);
locations.push({
name: locationType === "residential" ? point.name : point.business,
regionId,
point: pt,
type: locationType,
skills: _skills
});
break;
}
}
});
let vehicles = [];
let veh_idx = 0;
regions.forEach((r, r_idx) => {
vehicles.push({
name: `Truck ${veh_idx}`,
id: veh_idx,
license: json.vehicleArray.at(veh_idx++).license,
region: r_idx,
skills: [2]
});
for (let i = 0; i < inputs.nVehiclesPerRegion - 1; i++) {
let skills = [];
const randn = Math.floor(Math.random() * 3);
if (randn === 0) skills = [0];
else if (randn === 1) skills = [1];
else skills = [0, 1];
vehicles.push({
name: `Truck ${veh_idx}`,
id: veh_idx,
license: json.vehicleArray.at(veh_idx++)?.license,
region: r_idx,
skills
});
1;
}
});
return {
locations,
vehicles,
regions
};
}