feat: adjust API route trip-updates-by-agency-day and trip-updates-by-route-day

This commit is contained in:
dancingCycle 2024-01-03 09:20:39 +01:00
parent 217fc57918
commit 75055f004c
2 changed files with 24 additions and 4 deletions

View File

@ -11,7 +11,18 @@ async function get(agencyid = 0, day = '2023-12-27') {
const schema = process.env.DB_SCHEMA || 'schema';
const query = `SELECT agency_name, agency_id, route_id, route_short_name, count(service_id) AS service_id, count(trip_id) AS trip_id, count(trip_short_name) AS trip_short_name, count(trip_headsign) AS trip_headsign, max(timestamp_pgsql) AS timestamp_pgsql FROM ` + schema + `.vw_join_gncy_rts_trps_srvcs_pdts WHERE dates like '%${day}%' AND agency_id = '${agencyid}' AND (timestamp_pgsql > '${day}' OR timestamp_pgsql IS NULL) GROUP BY route_id, route_short_name, agency_id, agency_name ORDER BY timestamp_pgsql, route_short_name ASC;`
const tomorrow = new Date(day);
//console.log('tomorrow UTC: ' + tomorrow.toUTCString());
tomorrow.setUTCDate(tomorrow.getUTCDate() + 1);
//console.log('tomorrow UTC: ' + tomorrow.toUTCString());
//console.log('tomorrow ISO: ' + tomorrow.toISOString());
//console.log('tomorrow ISO substring: ' + tomorrow.toISOString().substring(0, 10));
const query = `SELECT agency_name, agency_id, route_id, route_short_name, count(service_id) AS service_id, count(trip_id) AS trip_id, count(trip_short_name) AS trip_short_name, count(trip_headsign) AS trip_headsign, max(timestamp_pgsql) AS timestamp_pgsql FROM `
+ schema
+ `.vw_join_gncy_rts_trps_srvcs_pdts WHERE dates like '%${day}%' AND agency_id = '${agencyid}' AND ((timestamp_pgsql >= '${day}' AND timestamp_pgsql < '`
+ tomorrow.toISOString().substring(0, 10)
+ `') OR timestamp_pgsql IS NULL) GROUP BY route_id, route_short_name, agency_id, agency_name ORDER BY timestamp_pgsql, route_short_name ASC;`
return await db.query(query);
};

View File

@ -11,9 +11,18 @@ async function get(routeid = 0, day = '2023-12-16') {
const schema = process.env.DB_SCHEMA || 'schema';
//TODO Sort by timestamp!
const query = `SELECT agency_name, agency_id, route_id, route_short_name, service_id, trip_id, trip_short_name, trip_headsign, timestamp_pgsql FROM ` + schema + `.vw_join_gncy_rts_trps_srvcs_pdts WHERE dates like '%${day}%' AND route_id = '${routeid}' AND (timestamp_pgsql > '${day}' OR timestamp_pgsql IS NULL) ORDER BY timestamp_pgsql, route_short_name ASC;`
console.log('query: ' + query);
const tomorrow = new Date(day);
//console.log('tomorrow UTC: ' + tomorrow.toUTCString());
tomorrow.setUTCDate(tomorrow.getUTCDate() + 1);
//console.log('tomorrow UTC: ' + tomorrow.toUTCString());
//console.log('tomorrow ISO: ' + tomorrow.toISOString());
//console.log('tomorrow ISO substring: ' + tomorrow.toISOString().substring(0, 10));
const query = `SELECT agency_name, agency_id, route_id, route_short_name, service_id, trip_id, trip_short_name, trip_headsign, timestamp_pgsql FROM `
+ schema
+ `.vw_join_gncy_rts_trps_srvcs_pdts WHERE dates like '%${day}%' AND route_id = '${routeid}' AND ((timestamp_pgsql >= '${day}' AND timestamp_pgsql < '`
+ tomorrow.toISOString().substring(0, 10)
+ `') OR timestamp_pgsql IS NULL) ORDER BY timestamp_pgsql, route_short_name ASC;`
return await db.query(query);
};