feat: DISABLE route Service as it is not working!

This commit is contained in:
dancingCycle 2023-11-17 11:16:02 +01:00
parent 7364405d73
commit 5815ff3008
5 changed files with 34 additions and 21 deletions

View File

@ -82,7 +82,9 @@ const ROUTESHORTNAME = require('./route/route-short-name');
const ROUTESERVICE = require('./route/service');
//get all service days that belong to a certain route_short_name
/** TODO Disable this route as it is not working!
const ROUTESERVICEDAYS = require('./route/servicedays');
*/
//get all service with counts of routes
const ROUTESERVICEOVERVIEW = require('./route/service-overview');
@ -222,7 +224,9 @@ APP.use('/trip-calendar-by-agency-id', tripCalendarByAgencyId);
APP.use('/trip-calendar-by-route-id', tripCalendarByRouteId);
//service
APP.use('/service', ROUTESERVICE);
/** TODO Disable this route as it is not working!
APP.use('/servicedays', ROUTESERVICEDAYS);
*/
APP.use('/service-overview', ROUTESERVICEOVERVIEW);
APP.use('/dates-service-available',datesServiceAvailable);
APP.use('/dates-service-added',datesServiceAdded);

View File

@ -1,34 +1,40 @@
const debug=require('debug')('servicedays');
const date=require('../utils/date');
const gtfs=require('../utils/gtfs');
const mapping=require('../utils/mapping');
debug('servicedays start...');
const db = require('./db');
require('dotenv').config();
async function getServiceDays(routeshortname = 0) {
const schema = process.env.DB_SCHEMA || 'schema';
debug('schema: ' + schema );
debug('routeshortname: '+routeshortname);
const queryTrips=`select agency.agency_name, routes.route_short_name, routes.agency_id, trips.route_id, trips.service_id, trips.trip_id, trips.trip_short_name from agency, trips, routes where agency.agency_id=routes.agency_id and trips.route_id=routes.route_id and routes.route_short_name='${routeshortname}';`
const queryTrips=`SELECT agency.agency_name, routes.route_short_name, routes.agency_id, trips.route_id, trips.service_id, trips.trip_id, trips.trip_short_name FROM ` + schema + `.agency, ` + schema + `.trips, ` + schema + `.routes WHERE agency.agency_id = routes.agency_id and trips.route_id = routes.route_id and routes.route_short_name = '${routeshortname}';`
////debug('queryTrips: '+queryTrips);
const dataTrips = await db.query(queryTrips);
const len=dataTrips.length;
//debug('trips len: '+len);
debug('trips len: '+len);
const map=new Map();
for(var i=0;i<len;i++){
const tripId=dataTrips[i].trip_id;
////debug('tripId: %s',tripId);
debug('tripId: %s',tripId);
const tripShortName=dataTrips[i].trip_short_name;
////debug('tripShortName: %s',tripShortName);
debug('tripShortName: %s',tripShortName);
const serviceId=dataTrips[i].service_id;
////debug('serviceId: %s',serviceId);
debug('serviceId: %s',serviceId);
const queryServices=`SELECT * FROM ` + schema + `.calendar WHERE service_id = '${serviceId}';`
debug('queryServices: '+queryServices);
const queryServices=`select * from calendar where service_id='${serviceId}';`
////debug('queryServices: '+queryServices);
const dataServices = await db.query(queryServices);
////debug('dataServices: '+dataServices[0].service_id);
debug('dataServices: '+dataServices[0].service_id);
const monday=dataServices[0].monday;
const tuesday=dataServices[0].tuesday;
@ -40,13 +46,15 @@ async function getServiceDays(routeshortname = 0) {
const saturday=dataServices[0].saturday;
const sunday=dataServices[0].sunday;
const start_date=dataServices[0].start_date;
const dateStart=gtfs.gtfsDate2NodeDate(start_date);
////debug('dateStart: '+dateStart);
debug('start: '+start_date);
const dateStart=gtfs.gtfsDate2NodeDate(start_date.toString());
debug('dateStart: '+dateStart);
const end_date=dataServices[0].end_date;
const dateEnd=gtfs.gtfsDate2NodeDate(end_date);
////debug('dateEnd: '+dateEnd);
debug('end: '+end_date);
const dateEnd=gtfs.gtfsDate2NodeDate(end_date.toString());
debug('dateEnd: '+dateEnd);
let dateNext=new Date(dateStart);
////debug('dateNext: '+dateNext);
debug('dateNext: '+dateNext);
while(dateNext.getTime()<=dateEnd.getTime()){
let weekday=dateNext.getDay();
@ -72,4 +80,3 @@ async function getServiceDays(routeshortname = 0) {
module.exports = {
getServiceDays
}
debug('servicedays done.');

View File

@ -5,26 +5,28 @@ function getDatesFromCalendarDates(value){
return gtfsDate2NodeDate(value.date);
}
function findSubStr(str, start, end) {
debug('str: ' + str + ', start: ' + start + ', end: ' + end + ', str.length: ' + str.length);
var index = str.slice(start, end);
//debug('index: '+index);
return index;
}
function gtfsDate2NodeDate(date){
debug('date: ' + date );
let start = 0;
let end = 4;
let year=findSubStr(date, start, end);
//debug('year: '+year);
debug('year: '+year);
start=4;
end=6;
let month=findSubStr(date, start, end);
//debug('month: '+month);
debug('month: '+month);
start=6;
end=8;
let day=findSubStr(date, start, end);
//debug('day: '+day);
let nodeDate = new Date(year, month - 1, day);
//debug('nodeDate: '+nodeDate);
debug('nodeDate: '+nodeDate);
return nodeDate;
}

2
package-lock.json generated
View File

@ -23,7 +23,7 @@
"nodemon": "2.0.22"
},
"engines": {
"node": ">=10"
"node": "<=10.24.0"
}
},
"node_modules/abbrev": {

View File

@ -11,7 +11,7 @@
"bugs": "https://git.wtf-eg.de/dancesWithCycles/gtfs-display/issues",
"license": "GPL-3.0-or-later",
"engines": {
"node": ">=10"
"node": "<=10.24.0"
},
"scripts": {
"dev": "nodemon index.js",