Compare commits
5 Commits
main
...
trip-calen
Author | SHA1 | Date |
---|---|---|
dancingCycle | a6a621c9c1 | |
dancingCycle | c47daae386 | |
renovate[bot] | 7b2b674ea2 | |
dancingCycle | ef01e80333 | |
dancingCycle | 608f6d58db |
|
@ -33,7 +33,7 @@ npm i
|
|||
|
||||
* run the following instruction to start the service in development mode
|
||||
```
|
||||
DEBUG=debug,table-calendar-dates-count,table-agency-count,table-routes-count,table-shapes-count,table-trips-count,table-calendar-count,table-frequencies-count,table-levels-count,table-names,table-count,trip-count,service-overview,gtfs,date,servicedays,service,agency-url,agency-name,route-short-name,trip-headsign,routes,frequencies,stops,index,root npm run dev
|
||||
DEBUG=debug,trip-count-day-agency,trip-count-day-route,table-calendar-dates-count,table-agency-count,table-routes-count,table-shapes-count,table-trips-count,table-calendar-count,table-frequencies-count,table-levels-count,table-names,table-count,trip-count,service-overview,gtfs,date,servicedays,service,agency-url,agency-name,route-short-name,trip-headsign,routes,frequencies,stops,index,root npm run dev
|
||||
```
|
||||
|
||||
## Production setup
|
||||
|
|
10
app/app.js
10
app/app.js
|
@ -106,12 +106,16 @@ const TRIPSROUTER = require('./route/trips');
|
|||
//get all trips that belong to the specified route_id
|
||||
const tripsByRouteId = require('./route/trips-by-route-id');
|
||||
|
||||
//get all trip counts for calendar dates that belong to the specified route_id
|
||||
//get overall trip counts for calendar dates that belong to the specified route_id
|
||||
const tripCalendarByRouteId = require('./route/trip-calendar-by-route-id');
|
||||
|
||||
//get all trip counts for calendar dates that belong to the specified agency_id
|
||||
//get overall trip counts for calendar dates that belong to the specified agency_id
|
||||
const tripCalendarByAgencyId = require('./route/trip-calendar-by-agency-id');
|
||||
|
||||
//get overall trip count that belong to a calendar date
|
||||
const tripCountDayAgency = require('./route/trip-count-day-agency');
|
||||
const tripCountDayRoute = require('./route/trip-count-day-route');
|
||||
|
||||
//get all services that belong to the specified route_id
|
||||
const servicesByRouteId = require('./route/services-by-route-id');
|
||||
|
||||
|
@ -187,6 +191,8 @@ APP.use('/route-short-name', ROUTESHORTNAME);
|
|||
APP.use('/trip-headsign', TRIPHEADSIGNROUTER);
|
||||
APP.use('/trips', TRIPSROUTER);
|
||||
APP.use('/trips-by-route-id', tripsByRouteId);
|
||||
APP.use('/trip-count-day-agency', tripCountDayAgency);
|
||||
APP.use('/trip-count-day-route', tripCountDayRoute);
|
||||
APP.use('/trip-calendar-by-agency-id', tripCalendarByAgencyId);
|
||||
APP.use('/trip-calendar-by-route-id', tripCalendarByRouteId);
|
||||
//service
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
const debug=require('debug')('trip-count-day-agency');
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const tripCountDayAgency = require('../service/trip-count-day-agency');
|
||||
const utils=require('../utils');
|
||||
router.get('/', async function(req, res, next) {
|
||||
//debug('trip-count-day-agency start...');
|
||||
const agencyId=req.query.agencyid;
|
||||
//debug(`trip-count-day-agency agency id: ${agencyId}`);
|
||||
const day=req.query.day;
|
||||
//debug(`trip-count-day-agency day: ${day}`);
|
||||
try {
|
||||
res.json(await tripCountDayAgency.get(agencyId, day));
|
||||
} catch (err) {
|
||||
console.error(`Error while getting trip calendar by agency_id, msg: `, err.message);
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
//debug('trip-count-day-agency done.');
|
||||
});
|
||||
module.exports = router;
|
|
@ -0,0 +1,21 @@
|
|||
const debug=require('debug')('trip-count-day-route');
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const tripCountDayRoute = require('../service/trip-count-day-route');
|
||||
const utils=require('../utils');
|
||||
router.get('/', async function(req, res, next) {
|
||||
//debug('trip-count-day-route start...');
|
||||
const routeId=req.query.routeid;
|
||||
//debug(`trip-count-day-route routeId: ${routeId}`);
|
||||
const day=req.query.day;
|
||||
//debug(`trip-count-day-route day: ${day}`);
|
||||
try {
|
||||
res.json(await tripCountDayRoute.get(routeId, day));
|
||||
} catch (err) {
|
||||
console.error(`Error while getting trip calendar by route_id, msg: `, err.message);k
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
//debug('trip-count-day-route done.');
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -0,0 +1,30 @@
|
|||
const debug=require('debug')('trip-count-day-agency');
|
||||
const routesByAgencyId=require('./routes-by-agency-id');
|
||||
const tripCountDayRoute =require('./trip-count-day-route');
|
||||
async function get(agencyId = 0, day = 0) {
|
||||
//debug('trip-count-day-agency start...');
|
||||
//debug('trip-count-day-agency agencyId: '+agencyId);
|
||||
//debug('trip-count-day-agency day: '+day);
|
||||
|
||||
//get routes array
|
||||
const aryRoutes=await routesByAgencyId.get(agencyId);
|
||||
//debug('trip-count-day-agency aryRoutes.length: '+aryRoutes.length);
|
||||
|
||||
//compute trip count
|
||||
let tripCount=0;
|
||||
//iterate over routes
|
||||
for(var i=0;i<aryRoutes.length;i++){
|
||||
const routeId=aryRoutes[i].route_id;
|
||||
//debug('trip-count-day-agency routeId: '+routeId);
|
||||
const trips=await tripCountDayRoute.get(routeId,day);
|
||||
//debug('trip-count-day-agency trips: '+trips);
|
||||
tripCount=tripCount+trips;
|
||||
//debug('trip-count-day-agency tripCount: '+tripCount);
|
||||
}
|
||||
//debug('trip-count-day-agency tripCount: '+tripCount);
|
||||
//debug('trip-count-day-agency done.');
|
||||
return tripCount;
|
||||
};
|
||||
module.exports = {
|
||||
get
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
const debug=require('debug')('trip-count-day-route');
|
||||
const tripsByRouteId=require('./trips-by-route-id');
|
||||
const serviceAvailability=require('./service-availability');
|
||||
|
||||
//remote time from a Date object
|
||||
function removeTime(date = new Date()) {
|
||||
return new Date(
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate()
|
||||
);
|
||||
};
|
||||
|
||||
/*
|
||||
* Compute number of trips belonging to a route provided that day
|
||||
* @param routeId id for the route to be considered
|
||||
* @param day the day to be considered
|
||||
* @return number of trips
|
||||
*/
|
||||
async function get(routeId = 0, day = 0) {
|
||||
//debug('trip-count-day-route start...');
|
||||
//debug('trip-count-day-route routeId: '+routeId);
|
||||
//debug('trip-count-day-route day ts: '+day);
|
||||
|
||||
//convert day into date without timestamp
|
||||
const dayMs = day * 1000;
|
||||
const dayDate = new Date(dayMs);
|
||||
const dayDateNoTime = removeTime(dayDate);
|
||||
const dayDateNoTimeTs = dayDateNoTime.getTime();
|
||||
//debug('trip-count-day-route day as dateNoTimeTs: '+dayDateNoTimeTs);
|
||||
|
||||
//get trips array
|
||||
const aryTrips=await tripsByRouteId.get(routeId);
|
||||
//debug('trip-count-day-route aryTrips.length: '+aryTrips.length);
|
||||
//debug('trip-count-day-route aryTrips: '+JSON.stringify(aryTrips));
|
||||
|
||||
//init services map
|
||||
const mapServices=new Map();
|
||||
//debug('trip-count-day-route mapServices.size: '+mapServices.size);
|
||||
|
||||
//compute trip count
|
||||
let tripCount=0;
|
||||
//iterate over trips
|
||||
for(var i=0;i<aryTrips.length;i++){
|
||||
//debug('trip-count-day-route i: '+i);
|
||||
const tripId=aryTrips[i].trip_id;
|
||||
//debug('trip-count-day-route tripId: '+tripId);
|
||||
const serviceId=aryTrips[i].service_id;
|
||||
//debug('trip-count-day-route serviceId: '+serviceId);
|
||||
|
||||
//get service
|
||||
let service=[];
|
||||
if(!mapServices.has(serviceId)){
|
||||
service=await serviceAvailability.get(serviceId);
|
||||
mapServices.set(serviceId,service);
|
||||
}else{
|
||||
service=mapServices.get(serviceId);
|
||||
}
|
||||
//debug('trip-count-day-route service.length: '+service.length);
|
||||
|
||||
//iterate over service availabiltiy
|
||||
for(var j=0;j<service.length;j++){
|
||||
//debug('trip-count-day-route service j: '+j);
|
||||
//debug('trip-count-day-route service[j]: '+service[j]);
|
||||
//debug('trip-count-day-route dayDateNoTimeTs: '+dayDateNoTimeTs);
|
||||
if(service[j]===dayDateNoTimeTs){
|
||||
tripCount++;
|
||||
//debug('trip-count-day-route tripCount: '+tripCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
//debug('trip-count-day-route tripCount: '+tripCount);
|
||||
//debug('trip-count-day-route done.');
|
||||
return tripCount;
|
||||
};
|
||||
module.exports = {
|
||||
get
|
||||
}
|
|
@ -1,4 +1,17 @@
|
|||
const debug=require('debug')('debug');
|
||||
function getDayMap(day){
|
||||
debug('calendar:getDayMap() start...');
|
||||
debug('calendar:getDayMap() day: '+day);
|
||||
|
||||
//get date of today without hours
|
||||
const todayNoHours=new Date(new Date().toDateString());
|
||||
debug('calendar:todayNoHours: '+todayNoHours);
|
||||
|
||||
const todayNoHoursTs=todayNoHours.getTime();
|
||||
debug('calendar:todayNoHoursTs: '+todayNoHoursTs);
|
||||
debug('calendar:getDayMap() done.');
|
||||
}
|
||||
|
||||
function getCalendarMap(){
|
||||
//debug('calendar start...');
|
||||
//get date of today without hours
|
||||
|
@ -49,5 +62,6 @@ function getCalendarMap(){
|
|||
return mapCalendar;
|
||||
};
|
||||
module.exports = {
|
||||
getCalendarMap
|
||||
getCalendarMap,
|
||||
getDayMap
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
"fs": "0.0.1-security",
|
||||
"helmet": "5.1.1",
|
||||
"https": "1.0.0",
|
||||
"pg": "8.7.3"
|
||||
"pg": "8.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.19"
|
||||
|
@ -878,14 +878,14 @@
|
|||
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ=="
|
||||
},
|
||||
"node_modules/pg": {
|
||||
"version": "8.7.3",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.7.3.tgz",
|
||||
"integrity": "sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==",
|
||||
"version": "8.8.0",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.8.0.tgz",
|
||||
"integrity": "sha512-UXYN0ziKj+AeNNP7VDMwrehpACThH7LUl/p8TDFpEUuSejCUIwGSfxpHsPvtM6/WXFy6SU4E5RG4IJV/TZAGjw==",
|
||||
"dependencies": {
|
||||
"buffer-writer": "2.0.0",
|
||||
"packet-reader": "1.0.0",
|
||||
"pg-connection-string": "^2.5.0",
|
||||
"pg-pool": "^3.5.1",
|
||||
"pg-pool": "^3.5.2",
|
||||
"pg-protocol": "^1.5.0",
|
||||
"pg-types": "^2.1.0",
|
||||
"pgpass": "1.x"
|
||||
|
@ -894,7 +894,7 @@
|
|||
"node": ">= 8.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pg-native": ">=2.0.0"
|
||||
"pg-native": ">=3.0.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"pg-native": {
|
||||
|
@ -916,9 +916,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/pg-pool": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.1.tgz",
|
||||
"integrity": "sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==",
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.2.tgz",
|
||||
"integrity": "sha512-His3Fh17Z4eg7oANLob6ZvH8xIVen3phEZh2QuyrIl4dQSDVEabNducv6ysROKpDNPSD+12tONZVWfSgMvDD9w==",
|
||||
"peerDependencies": {
|
||||
"pg": ">=8.0"
|
||||
}
|
||||
|
@ -1929,14 +1929,14 @@
|
|||
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ=="
|
||||
},
|
||||
"pg": {
|
||||
"version": "8.7.3",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.7.3.tgz",
|
||||
"integrity": "sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==",
|
||||
"version": "8.8.0",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.8.0.tgz",
|
||||
"integrity": "sha512-UXYN0ziKj+AeNNP7VDMwrehpACThH7LUl/p8TDFpEUuSejCUIwGSfxpHsPvtM6/WXFy6SU4E5RG4IJV/TZAGjw==",
|
||||
"requires": {
|
||||
"buffer-writer": "2.0.0",
|
||||
"packet-reader": "1.0.0",
|
||||
"pg-connection-string": "^2.5.0",
|
||||
"pg-pool": "^3.5.1",
|
||||
"pg-pool": "^3.5.2",
|
||||
"pg-protocol": "^1.5.0",
|
||||
"pg-types": "^2.1.0",
|
||||
"pgpass": "1.x"
|
||||
|
@ -1953,9 +1953,9 @@
|
|||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
|
||||
},
|
||||
"pg-pool": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.1.tgz",
|
||||
"integrity": "sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==",
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.2.tgz",
|
||||
"integrity": "sha512-His3Fh17Z4eg7oANLob6ZvH8xIVen3phEZh2QuyrIl4dQSDVEabNducv6ysROKpDNPSD+12tONZVWfSgMvDD9w==",
|
||||
"requires": {}
|
||||
},
|
||||
"pg-protocol": {
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"fs": "0.0.1-security",
|
||||
"helmet": "5.1.1",
|
||||
"https": "1.0.0",
|
||||
"pg": "8.7.3"
|
||||
"pg": "8.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.19"
|
||||
|
|
Loading…
Reference in New Issue