feat: add API route trip-updates-by-agency-day
This commit is contained in:
parent
150348a63d
commit
2d4a48f254
11
src/main.js
11
src/main.js
|
@ -118,10 +118,6 @@ const datesServiceRemoved=require('./route/dates-service-removed');
|
|||
//get trip_headsign from trip_short_name
|
||||
const TRIPHEADSIGNROUTER = require('./route/trip-headsign');
|
||||
|
||||
/*SELECT trip_id,trip_short_name,trip_headsign,routes.route_id,routes.route_short_name,routes.route_type,agency.agency_id,agency.agency_name,agency.agency_url FROM agency,routes,trips WHERE trip_short_name ='1944027' AND trips.route_id = routes.route_id AND routes.agency_id = agency.agency_id;*/
|
||||
//get pt info by trip_short_name from IVU radio interface location message
|
||||
const ptByIfleet = require('./route/pt-by-ifleet');
|
||||
|
||||
//get all trips that belong to a certain route_short_name
|
||||
const TRIPSROUTER = require('./route/trips');
|
||||
|
||||
|
@ -134,6 +130,9 @@ const tripsByRouteDay = require('./route/trips-by-route-day');
|
|||
//get trip updates by route_id and day YYY-M(M)-D(D)
|
||||
const tripUpdatesByRouteDay = require('./route/trip-updates-by-route-day');
|
||||
|
||||
//get trip updates by agency_id and day YYY-M(M)-D(D)
|
||||
const tripUpdatesByAgencyDay = require('./route/trip-updates-by-agency-day');
|
||||
|
||||
//get overall trip counts for calendar dates that belong to the specified route_id
|
||||
const tripCalendarByRouteId = require('./route/trip-calendar-by-route-id');
|
||||
|
||||
|
@ -225,7 +224,6 @@ app.use('/number-of-trips', numberOfTrips);
|
|||
//get route_short-name by providing trip_short_name
|
||||
app.use('/route-short-name', ROUTESHORTNAME);
|
||||
|
||||
app.use('/pt-by-ifleet', ptByIfleet);
|
||||
//trips
|
||||
app.use('/trip-headsign', TRIPHEADSIGNROUTER);
|
||||
app.use('/trips', TRIPSROUTER);
|
||||
|
@ -235,8 +233,11 @@ app.use('/trip-count-day-route', tripCountDayRoute);
|
|||
app.use('/trip-calendar-by-agency-id', tripCalendarByAgencyId);
|
||||
app.use('/trip-calendar-by-route-id', tripCalendarByRouteId);
|
||||
app.use('/trips-by-route-day', tripsByRouteDay);
|
||||
|
||||
//trip updates
|
||||
app.use('/trip-updates-by-route-day', tripUpdatesByRouteDay);
|
||||
app.use('/trip-updates-by-agency-day', tripUpdatesByAgencyDay);
|
||||
|
||||
//service
|
||||
app.use('/service', ROUTESERVICE);
|
||||
/** TODO Disable this route as it is not working!
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
const debug=require('debug')('pt-by-ifleet');
|
||||
debug('pt-by-ifleet start...');
|
||||
|
||||
const EXPRESS = require('express');
|
||||
const ROUTER = EXPRESS.Router();
|
||||
const ptByIfleet = require('../service/pt-by-ifleet');
|
||||
const UTILS=require('../utils');
|
||||
|
||||
//GET listing
|
||||
ROUTER.get('/', async function(req, res, next) {
|
||||
try {
|
||||
//console.log('req.query.tripshortname:'+req.query.tripshortname);
|
||||
res.json(await ptByIfleet.get(req.query.tripshortname));
|
||||
} catch (err) {
|
||||
console.error(`Error while getting pt into by Ifleet, msg: `, err.message);
|
||||
res.status(err.statusCode || 500).json(UTILS.MSGS.error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ROUTER;
|
||||
debug('pt-by-ifleet done.');
|
|
@ -0,0 +1,16 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tripUpdatesByAgencyDay = require('../service/trip-updates-by-agency-day');
|
||||
const utils=require('../utils');
|
||||
|
||||
router.get('/', async function(req, res, next) {
|
||||
try {
|
||||
res.json(await tripUpdatesByAgencyDay.get(req.query.agencyid, req.query.day));
|
||||
} catch (err) {
|
||||
console.error(`Error while getting trip updates by agency_id and day, msg: `, err.message);
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -1,21 +0,0 @@
|
|||
const debug=require('debug')('debug');
|
||||
debug('pt-by-ifleet start...');
|
||||
|
||||
const db = require('./db');
|
||||
|
||||
async function get(tripshortname = 0) {
|
||||
//debug('tripshortname: '+tripshortname);
|
||||
|
||||
const QUERY=`SELECT trip_id,trip_short_name,trip_headsign,routes.route_id,routes.route_short_name,routes.route_type,agency.agency_id,agency.agency_name,agency.agency_url FROM agency,routes,trips WHERE trip_short_name ='${tripshortname}' AND trips.route_id = routes.route_id AND routes.agency_id = agency.agency_id;`;
|
||||
//debug('QUERY: '+QUERY);
|
||||
const resp = await db.query(QUERY);
|
||||
//debug('resp: '+resp);
|
||||
//debug('resp: '+JSON.stringify(resp[0]));
|
||||
/*TODO Handle respnse array where records differ in service_id.*/
|
||||
return resp[0];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
}
|
||||
debug('pt-by-ifleet done.');
|
|
@ -0,0 +1,21 @@
|
|||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
|
||||
/**
|
||||
* Get trips that belong to the certain agency_id and day
|
||||
*
|
||||
* @return Array of trips
|
||||
*/
|
||||
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}' GROUP BY route_id, route_short_name, agency_id, agency_name ORDER BY timestamp_pgsql, route_short_name ASC;`
|
||||
|
||||
return await db.query(query);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
};
|
|
@ -12,7 +12,7 @@ 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}';`
|
||||
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}' ORDER BY timestamp_pgsql, route_short_name ASC;`
|
||||
|
||||
return await db.query(query);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue