-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const mariadb = require('mariadb') | ||
const config = require('../config') | ||
async function getCloserFutureTrain (origin, destination, type) { | ||
this.pool = mariadb.createPool({ | ||
host: config.mariadb.host, | ||
user: config.mariadb.user, | ||
password: config.mariadb.password, | ||
connectionLimit: 5, | ||
database: config.mariadb.db, | ||
}) | ||
|
||
let conn | ||
try { | ||
conn = await this.pool.getConnection(); | ||
const rows = await conn.query(`SELECT A.departure_time departure, A.stop_name origin_stop, B.stop_name destination_stop, B.arrival_time arrival FROM | ||
(SELECT ST.trip_id , S.stop_name, ST.stop_id, ST.stop_sequence, ST.departure_time | ||
from stop_times ST | ||
inner join stops S ON S.stop_id = ST.stop_id | ||
WHERE | ||
S.stop_name LIKE '%${origin}%' and | ||
ST.pickup_type = 0 | ||
) AS A | ||
INNER JOIN | ||
(SELECT ST.trip_id, ST.stop_id, ST.stop_sequence, S.stop_name, ST.arrival_time | ||
from stop_times ST | ||
inner join stops S ON S.stop_id = ST.stop_id | ||
WHERE | ||
S.stop_name LIKE '%${destination}%' and | ||
ST.drop_off_type = 0 | ||
) AS B | ||
ON A.trip_id = B.trip_id | ||
inner join trips T ON T.trip_id = A.trip_id | ||
inner join routes R ON R.route_id = T.route_id | ||
left join calendar C ON C.service_id = T.service_id | ||
WHERE A.stop_sequence < B.stop_sequence | ||
AND (C.start_date IS NULL OR C.start_date <= DATE_ADD(CURDATE(), INTERVAL 1 HOUR )) | ||
and (C.end_date IS NULL OR C.end_date >= DATE_ADD(CURDATE(), INTERVAL 1 HOUR )) | ||
AND T.service_id NOT IN (SELECT CD.service_id FROM calendar_dates CD | ||
where CD.date = DATE_ADD(CURDATE(), INTERVAL 1 HOUR ) ) | ||
AND route_short_name = '${type}' | ||
AND A.departure_time > TIME(DATE_ADD(CURDATE(), INTERVAL 1 HOUR )) | ||
ORDER BY ABS( TIMEDIFF(A.departure_time, TIME(DATE_ADD(CURDATE(), INTERVAL 1 HOUR ))) ) | ||
LIMIT 1`) | ||
if (conn) await conn.end() | ||
return rows[0] | ||
|
||
} catch (err) { | ||
console.log(err) | ||
} | ||
} | ||
|
||
module.exports = { | ||
getCloserFutureTrain | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,13 +318,23 @@ | |
klona "^2.0.4" | ||
tslib "^2.0.3" | ||
|
||
"@types/geojson@^7946.0.10": | ||
version "7946.0.14" | ||
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.14.tgz#319b63ad6df705ee2a65a73ef042c8271e696613" | ||
integrity sha512-WCfD5Ht3ZesJUsONdhvm84dmzWOiOzOAqOncN0++w0lBw1o8OuDNJF2McvvCef/yBqb/HYRahp1BYtODFQ8bRg== | ||
|
||
"@types/node@*": | ||
version "20.11.16" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.16.tgz#4411f79411514eb8e2926f036c86c9f0e4ec6708" | ||
integrity sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ== | ||
dependencies: | ||
undici-types "~5.26.4" | ||
|
||
"@types/node@^17.0.45": | ||
version "17.0.45" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.45.tgz#2c0fafd78705e7a18b7906b5201a522719dc5190" | ||
integrity sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw== | ||
|
||
"@types/tmi.js@^1.7.1": | ||
version "1.8.6" | ||
resolved "https://registry.yarnpkg.com/@types/tmi.js/-/tmi.js-1.8.6.tgz#f95a397d20398d0e1333a2eb8b7c3c494ce96b55" | ||
|
@@ -737,6 +747,11 @@ delayed-stream@~1.0.0: | |
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" | ||
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== | ||
|
||
denque@^2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/denque/-/denque-2.1.0.tgz#e93e1a6569fb5e66f16a3c2a2964617d349d6ab1" | ||
integrity sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw== | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" | ||
|
@@ -1575,6 +1590,11 @@ lodash@^4.17.15: | |
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" | ||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== | ||
|
||
lru-cache@^10.0.1: | ||
version "10.2.0" | ||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" | ||
integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q== | ||
|
||
lru-cache@^6.0.0: | ||
version "6.0.0" | ||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" | ||
|
@@ -1587,6 +1607,17 @@ lru-cache@^7.14.1: | |
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.18.3.tgz#f793896e0fd0e954a59dfdd82f0773808df6aa89" | ||
integrity sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA== | ||
|
||
mariadb@^3.2.3: | ||
version "3.2.3" | ||
resolved "https://registry.yarnpkg.com/mariadb/-/mariadb-3.2.3.tgz#29ae69e678a25b355f4af0605b99b112c5ba7c5b" | ||
integrity sha512-Hyc1ehdUJwzvvzcLU2juZS528wJ6oE8pUlpgY0BAOdpKWcdN1motuugi5lC3jkpCkFpyNknHG7Yg66KASl3aPg== | ||
dependencies: | ||
"@types/geojson" "^7946.0.10" | ||
"@types/node" "^17.0.45" | ||
denque "^2.1.0" | ||
iconv-lite "^0.6.3" | ||
lru-cache "^10.0.1" | ||
|
||
mathjs@^12.3.1: | ||
version "12.3.1" | ||
resolved "https://registry.yarnpkg.com/mathjs/-/mathjs-12.3.1.tgz#afbdde32cd6026b8aa3bb303538be06d82b36e11" | ||
|