Z7XOXXDJ7T6E4ZCP2AK5YSXWE6TCDCLZEXAZPZZVLOY4WCFVZPHAC
TQZJC7K5WOURWCLEFW3OP2SBWE3IGMCXBBLNVDKAPQS7NEHSLRJAC
JAAJEH57DRFXCZGAPOQLI4MN7N57OG52E7TQCC4FFJSOPDX4M65QC
7RKEQK2KPXJ2MEHPVSY7ROMHW6FTTKCXSMZV5MEXPFZKESZQYUUAC
WYTMZJFYVKHR4QH7AV5JUNWXT6NAC5NNQNPZCQSDI6LGI7DVXFYAC
2FPZGFF5PCGNV45HOB6TROMJFPURHPXM7YSPWNXCHFJS7EICVKQAC
2ZHTBPOJQI4FS3OQJXUDBD62HVFPGSKI633IXXKAGPGQLURMKVPAC
4WREYORZT3SWUXADWHSS6B4PQSP3QSLH77CGNKRH6IRKUMX4TARAC
63VXWIHIAKGK7J4VTNRUAG2V32N2QUSWFELB6GD34S54FGRWAPCQC
DCYC55MAVFDM43TEEUMAHLPOHNQ3EJ5PEVCA7H6ZTKNQHJZK7XJAC
Q3A33UTWKXZATZKX3LQ42MUAWFTWDZDMNVMLKWGC3QF6L6HBLUQAC
BPHFBV52V4OA6WLKXGFK7Q4IM5EUS2SKAW5ZGSA6K3NJFJJVATIAC
let hints = Promise.all([
request(`http://127.0.0.1:5000/nearest/v1/fuck/${location.lng},${location.lat}`).then(x => JSON.parse(x).waypoints[0].hint),
request(`http://127.0.0.1:5001/nearest/v1/fuck/${location.lng},${location.lat}`).then(x => JSON.parse(x).waypoints[0].hint)
]);
insert into store (name, URL, address, address2, city, region, country, postal_code, longitude, latitude, timezone)
values ($1, $2, $3, $4, $5, $6, $7, $8, $${params.push(location.lng)}, $${params.push(location.lat)}, $${params.push(tz)})
insert into store (
name,
url,
address,
address2,
city,
region,
country,
postal_code,
delivery,
pickup,
prepayment,
phone,
longitude,
latitude,
osrm_hint_foot,
osrm_hint_car,
timezone
) values (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12,
$${params.push(location.lng)},
$${params.push(location.lat)},
$${params.push(hints[0])},
$${params.push(hints[1])},
$${params.push(tz)}
)
case 'stores'://wait for postgis to land before implementing
//todo: parameters(lat, long, radius, open now or open + closed, (pickup, delivery) for future)), or by province, city, country
//https://postgis.net/docs/ST_DWithin.html vs http://postgis.net/docs/geometry_distance_knn.html
//what are the tradeoffs? I want to use geography I think since I don't want to deal with projections, but are we sure google maps coordinates are correct
//what is the spheroid to use?
let stores = (await pool.query(`select distinct on(store_id) store_id as id, name, type = 'physical', store_image.url from store left outer join store_image using (store_id)`)).rows;
//ws.subscribe('store/#'); maybe this doesn't make sense? with the filters at least, hard to be dynamic. would be cool as a store opens, it shows up
case 'stores': {
let stores = (await pool.query(`select distinct on(store_id) store_id, name, longitude, latitude, store_image.url from store left outer join store_image using (store_id)`)).rows;
ws.subscribe('store');
break;
break; }
case 'store_distance': {
let stores = (await pool.query('select store_id, longitude, latitude, osrm_hint_foot, osrm_hint_car from store where longitude is not null and latitude is not null')).rows;
let longlats = stores.map(x => `${x.longitude},${x.latitude}`).join(';');
let [foot, car] = await Promise.all([
request(`http://127.0.0.1:5000/table/v1/fuck/${parameters.longitude},${parameters.latitude};${longlats}?annotations=duration,distance&skip_waypoints=true&sources=0&hints=;${stores.map(x => x.osrm_hint_foot).join(';')}`).then(JSON.parse),
request(`http://127.0.0.1:5001/table/v1/fuck/${parameters.longitude},${parameters.latitude};${longlats}?annotations=duration,distance&skip_waypoints=true&sources=0&hints=;${stores.map(x => x.osrm_hint_car).join(';')}`).then(JSON.parse)
]);
if(foot.code === 'Ok' && car.code === 'Ok') {
for(let i = stores.length - 1; i >= 0; --i) {
delete stores[i].longitude;
delete stores[i].latitude;
delete stores[i].osrm_hint_foot;
delete stores[i].osrm_hint_car;
if(foot.durations[0][i + 1] === null && car.durations[0][i + 1] === null) {
stores.splice(i, 1);
} else if(foot.durations[0][i + 1] === null) {
stores[i].distance = car.distances[0][i + 1];
} else if(car.durations[0][i + 1] === null || foot.durations[0][i + 1] <= car.durations[0][i + 1] + 300) {// + 5 minutes to make more likely to choose foot to account for things like parking, traffic
stores[i].distance = foot.distances[0][i + 1];
} else {
stores[i].distance = car.distances[0][i + 1];
}
}
ws.send(JSON.stringify({
response_ID: request_ID,
data: stores
}));
} else {
console.log(foot, car);
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'could not compute routes'
}));
}
break;}