fix: UPDATE route trip-calendar-by-agency-id
This commit is contained in:
parent
bb9e2ca050
commit
d59c998ad7
|
@ -1,20 +1,27 @@
|
|||
const debug=require('debug')('debug');
|
||||
//debug('datesServiceAdded start...');
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
const date=require('../utils/date');
|
||||
const gtfs=require('../utils/gtfs');
|
||||
|
||||
async function get(serviceId = 0) {
|
||||
//debug('datesServiceAdded serviceId: '+serviceId);
|
||||
const query=`SELECT calendar_dates.date,calendar_dates.exception_type FROM calendar,calendar_dates WHERE calendar.service_id=calendar_dates.service_id AND calendar.service_id='${serviceId}' and calendar_dates.exception_type='1';`;
|
||||
//debug('datesServiceAdded query: '+query);
|
||||
debug('datesServiceAdded serviceId: '+serviceId);
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
debug('schema: ' + schema );
|
||||
|
||||
const query=`SELECT calendar_dates.date, calendar_dates.exception_type FROM ` + schema + `.calendar, ` + schema + `.calendar_dates WHERE calendar.service_id = calendar_dates.service_id AND calendar.service_id = '${serviceId}' and calendar_dates.exception_type = '1';`;
|
||||
debug('datesServiceAdded query: '+query);
|
||||
const data = await db.query(query);
|
||||
//debug('datesServiceAdded data.length: '+data.length);
|
||||
//debug('datesServiceAdded [0]: '+JSON.stringify(data[0]));
|
||||
const dates=data.map(value=>gtfs.getDatesFromCalendarDates(value).getTime());
|
||||
//debug('datesServiceAdded dates.length: '+dates.length);
|
||||
debug('datesServiceAdded data.length: '+data.length);
|
||||
debug('datesServiceAdded [0]: '+JSON.stringify(data[0]));
|
||||
//TODO NOT working const dates=data.map(value=>gtfs.getDatesFromCalendarDates(value).getTime());
|
||||
const dates = data;
|
||||
debug('datesServiceAdded dates.length: '+dates.length);
|
||||
return dates;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
}
|
||||
debug('datesServiceAdded done.');
|
||||
};
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
const debug=require('debug')('debug');
|
||||
//debug('datesServiceAvailable start...');
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
const date=require('../utils/date');
|
||||
const gtfs=require('../utils/gtfs');
|
||||
const mapping=require('../utils/mapping');
|
||||
|
||||
async function get(serviceId = 0) {
|
||||
//debug('datesServiceAvailable serviceId: '+serviceId);
|
||||
const query=`SELECT * FROM calendar WHERE service_id='${serviceId}';`;
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
debug('schema: ' + schema );
|
||||
|
||||
const query=`SELECT * FROM ` + schema + `.calendar WHERE service_id = '${serviceId}';`;
|
||||
//debug('datesServiceAvailable query: '+query);
|
||||
const dataService = await db.query(query);
|
||||
//debug('datesServiceAvailable dataService.length: '+dataService.length);
|
||||
|
@ -26,15 +32,21 @@ async function get(serviceId = 0) {
|
|||
const sunday=dataService[0].sunday;
|
||||
//debug('datesServiceAvailable sunday: '+sunday);
|
||||
const start_date=dataService[0].start_date;
|
||||
//debug('start_date: '+start_date);
|
||||
const dateStart=gtfs.gtfsDate2NodeDate(start_date);
|
||||
//debug('dateStart: '+dateStart);
|
||||
debug('start_date: '+start_date);
|
||||
/**
|
||||
//TODO NOT working const dateStart=gtfs.gtfsDate2NodeDate(start_date.toString());
|
||||
*/
|
||||
const dateStart = start_date;
|
||||
debug('dateStart: '+dateStart);
|
||||
const end_date=dataService[0].end_date;
|
||||
//debug('end_date: '+end_date);
|
||||
const dateEnd=gtfs.gtfsDate2NodeDate(end_date);
|
||||
//debug('dateEnd: '+dateEnd);
|
||||
debug('end_date: '+end_date);
|
||||
/**
|
||||
//TODO NOT working const dateEnd=gtfs.gtfsDate2NodeDate(end_date.toString());
|
||||
*/
|
||||
const dateEnd = end_date;
|
||||
debug('dateEnd: '+dateEnd);
|
||||
let dateNext=new Date(dateStart);
|
||||
//debug('dateNext: '+dateNext);
|
||||
debug('dateNext: '+dateNext);
|
||||
const datesServiceAvailable=new Set();
|
||||
while(dateNext.getTime()<=dateEnd.getTime()){
|
||||
let weekday=dateNext.getDay();
|
||||
|
@ -49,10 +61,10 @@ async function get(serviceId = 0) {
|
|||
}
|
||||
dateNext=new Date(dateNext.setDate(dateNext.getDate()+1));
|
||||
}
|
||||
//debug('datesServiceAvailable size: '+datesServiceAvailable.size);
|
||||
debug('datesServiceAvailable size: '+datesServiceAvailable.size);
|
||||
return mapping.set2Array(datesServiceAvailable);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
}
|
||||
debug('datesServiceAvailable done.');
|
||||
};
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
const debug=require('debug')('debug');
|
||||
//debug('datesServiceRemoved start...');
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
const date=require('../utils/date');
|
||||
const gtfs=require('../utils/gtfs');
|
||||
|
||||
async function get(serviceId = 0) {
|
||||
//debug('datesServiceRemoved serviceId: '+serviceId);
|
||||
const query=`SELECT calendar_dates.date,calendar_dates.exception_type FROM calendar,calendar_dates WHERE calendar.service_id=calendar_dates.service_id AND calendar.service_id='${serviceId}' and calendar_dates.exception_type='2';`;
|
||||
//debug('datesServiceRemoved query: '+query);
|
||||
debug('datesServiceRemoved serviceId: '+serviceId);
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
debug('schema: ' + schema );
|
||||
|
||||
const query=`SELECT calendar_dates.date, calendar_dates.exception_type FROM ` + schema + `.calendar, ` + schema + `.calendar_dates WHERE calendar.service_id = calendar_dates.service_id AND calendar.service_id = '${serviceId}' and calendar_dates.exception_type = '2';`;
|
||||
debug('datesServiceRemoved query: '+query);
|
||||
const data = await db.query(query);
|
||||
//debug('datesServiceRemoved data.length: '+data.length);
|
||||
//debug('datesServiceRemoved [0]: '+JSON.stringify(data[0]));
|
||||
const dates=data.map(value=>gtfs.getDatesFromCalendarDates(value).getTime());
|
||||
//debug('datesServiceRemoved dates.length: '+dates.length);
|
||||
debug('datesServiceRemoved data.length: '+data.length);
|
||||
debug('datesServiceRemoved [0]: '+JSON.stringify(data[0]));
|
||||
//TODO NOT working const dates=data.map(value=>gtfs.getDatesFromCalendarDates(value).getTime());
|
||||
const dates = data;
|
||||
debug('datesServiceRemoved dates.length: '+dates.length);
|
||||
return dates;
|
||||
}
|
||||
module.exports = {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
const debug=require('debug')('debug');
|
||||
const db = require('./db');
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
|
||||
async function get() {
|
||||
debug('number-of-routes start...');
|
||||
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
const debug=require('debug')('debug');
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
|
||||
async function get(agencyId = 0) {
|
||||
//debug('routes-by-agency-id start...');
|
||||
//debug('agencyId: '+agencyId);
|
||||
const QUERY=`SELECT routes.route_id FROM routes WHERE agency_id='${agencyId}';`
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
debug('schema: ' + schema );
|
||||
|
||||
const QUERY=`SELECT routes.route_id FROM ` + schema + `.routes WHERE agency_id='${agencyId}';`
|
||||
//debug('QUERY: '+QUERY);
|
||||
const res=await db.query(QUERY);
|
||||
//debug('routes-by-agency-id done.');
|
||||
|
|
|
@ -1,35 +1,43 @@
|
|||
const debug=require('debug')('debug');
|
||||
//debug('serviceAvailability start...');
|
||||
|
||||
const db = require('./db');
|
||||
const date=require('../utils/date');
|
||||
const gtfs=require('../utils/gtfs');
|
||||
//TODO CLEANUP const mapping=require('../utils/mapping');
|
||||
const datesServiceAvailable=require('./dates-service-available');
|
||||
const datesServiceAdded=require('./dates-service-added');
|
||||
const datesServiceRemoved=require('./dates-service-removed');
|
||||
const mapping=require('../utils/mapping');
|
||||
|
||||
async function get(serviceId = 0) {
|
||||
//debug('serviceAvailability serviceId: '+serviceId);
|
||||
const available=datesServiceAvailable.get(serviceId);
|
||||
//debug('serviceAvailability available: '+available.length);
|
||||
const added=datesServiceAdded.get(serviceId);
|
||||
const removed=datesServiceRemoved.get(serviceId);
|
||||
//debug('serviceAvailability removed: '+removed.length);
|
||||
debug('serviceAvailability available: '+available.length);
|
||||
|
||||
const added = await datesServiceAdded.get(serviceId);
|
||||
debug('serviceAvailability added: ' + added.length);
|
||||
|
||||
const removed = await datesServiceRemoved.get(serviceId);
|
||||
debug('serviceAvailability removed: ' + removed.length);
|
||||
|
||||
//TODO ?
|
||||
//const setAvail=new Set(available);
|
||||
//debug('serviceAvailability setAvail: '+setAvail.size);
|
||||
|
||||
const datesAll=await Promise.all([available,added,removed]);
|
||||
//debug('serviceAvailability datesAll.length: '+datesAll.length);
|
||||
debug('serviceAvailability datesAll.length: '+datesAll.length);
|
||||
const setAvail=new Set(datesAll[0]);
|
||||
//debug('serviceAvailability setAvail.size: '+setAvail.size);
|
||||
debug('serviceAvailability setAvail.size: '+setAvail.size);
|
||||
|
||||
//remove dates from service
|
||||
datesAll[2].forEach(rmEntry=>setAvail.delete(rmEntry));
|
||||
//debug('serviceAvailability setAvailWithRmed.size: '+setAvail.size);
|
||||
debug('serviceAvailability setAvailWithRmed.size: '+setAvail.size);
|
||||
|
||||
//add dates to service
|
||||
const setAvailWithAdded = new Set([...setAvail, ...new Set(datesAll[1])]);
|
||||
//debug('serviceAvailability size: '+setAvailWithAdded.size);
|
||||
debug('serviceAvailability size: '+setAvailWithAdded.size);
|
||||
return mapping.set2Array(setAvailWithAdded);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
}
|
||||
//debug('serviceAvailability done.');
|
||||
};
|
||||
|
|
|
@ -47,11 +47,17 @@ async function getServiceDays(routeshortname = 0) {
|
|||
const sunday=dataServices[0].sunday;
|
||||
const start_date=dataServices[0].start_date;
|
||||
debug('start: '+start_date);
|
||||
const dateStart=gtfs.gtfsDate2NodeDate(start_date.toString());
|
||||
/**
|
||||
//TODO NOT working const dateStart=gtfs.gtfsDate2NodeDate(start_date.toString());
|
||||
*/
|
||||
const dateStart = start_date;
|
||||
debug('dateStart: '+dateStart);
|
||||
const end_date=dataServices[0].end_date;
|
||||
debug('end: '+end_date);
|
||||
const dateEnd=gtfs.gtfsDate2NodeDate(end_date.toString());
|
||||
/**
|
||||
//TODO NOT working const dateEnd=gtfs.gtfsDate2NodeDate(end_date.toString());
|
||||
*/
|
||||
const dateEnd = end_date;
|
||||
debug('dateEnd: '+dateEnd);
|
||||
let dateNext=new Date(dateStart);
|
||||
debug('dateNext: '+dateNext);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
const debug=require('debug')('debug');
|
||||
|
||||
const db = require('./db');
|
||||
const routesByAgencyId=require('./routes-by-agency-id');
|
||||
const tripCalendarByRouteId=require('./trip-calendar-by-route-id');
|
||||
const mapping=require('../utils/mapping');
|
||||
const calendar=require('../utils/calendar');
|
||||
|
||||
async function get(agencyId = 0) {
|
||||
//debug('trip-calendar-by-agency-id start...');
|
||||
//debug('trip-calendar-by-agency-id agencyId: '+agencyId);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
const debug=require('debug')('debug');
|
||||
|
||||
const db = require('./db');
|
||||
const tripsByRouteId=require('./trips-by-route-id');
|
||||
const serviceAvailability=require('./service-availability');
|
||||
const mapping=require('../utils/mapping');
|
||||
const calendar=require('../utils/calendar');
|
||||
|
||||
async function get(routeId = 0) {
|
||||
//debug('trip-calendar-by-route-id start...');
|
||||
//debug('trip-calendar-by-route-id routeId: '+routeId);
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
const debug=require('debug')('debug');
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
|
||||
async function get(routeid = 0) {
|
||||
//debug('trips-by-route-id start...');
|
||||
//debug('routeid: '+routeid);
|
||||
const QUERY=`SELECT trips.service_id,trips.trip_id FROM trips WHERE trips.route_id='${routeid}';`
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
debug('schema: ' + schema );
|
||||
|
||||
const QUERY=`SELECT trips.service_id, trips.trip_id FROM ` + schema + `.trips WHERE trips.route_id = '${routeid}';`
|
||||
//debug('QUERY: '+QUERY);
|
||||
const trips = await db.query(QUERY);
|
||||
//debug('trips-by-route-id trips.length: '+trips.length);
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
const debug=require('debug')('gtfs');
|
||||
|
||||
/** TODO NOT working
|
||||
function getDatesFromCalendarDates(value){
|
||||
//debug('getDatesFromCalendarDates value: '+JSON.stringify(value));
|
||||
return gtfsDate2NodeDate(value.date);
|
||||
}
|
||||
*/
|
||||
|
||||
/** TODO NOT working
|
||||
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;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/** TODO NOT working
|
||||
function gtfsDate2NodeDate(date){
|
||||
debug('date: ' + date );
|
||||
let start = 0;
|
||||
|
@ -24,13 +30,14 @@ function gtfsDate2NodeDate(date){
|
|||
start=6;
|
||||
end=8;
|
||||
let day=findSubStr(date, start, end);
|
||||
//debug('day: '+day);
|
||||
debug('day: '+day);
|
||||
let nodeDate = new Date(year, month - 1, day);
|
||||
debug('nodeDate: '+nodeDate);
|
||||
return nodeDate;
|
||||
}
|
||||
*/
|
||||
|
||||
module.exports={
|
||||
gtfsDate2NodeDate,
|
||||
getDatesFromCalendarDates
|
||||
// TODO NOT working gtfsDate2NodeDate,
|
||||
// TODO NOT working getDatesFromCalendarDates
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const debug=require('debug')('debug');
|
||||
|
||||
function updateMap(time,tripId,tripShortName,map){
|
||||
//debug('time: '+time);
|
||||
//time map empty
|
||||
|
@ -35,11 +36,11 @@ function updateMap(time,tripId,tripShortName,map){
|
|||
createEntry(mapTrips,tripId,tripShortName);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function createEntry(map, key, value){
|
||||
map.set(key,value);
|
||||
}
|
||||
};
|
||||
|
||||
function times2Array(map){
|
||||
let array=[];
|
||||
|
@ -49,7 +50,7 @@ function times2Array(map){
|
|||
//debug('array: '+array);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
};
|
||||
|
||||
//TODO make function generic
|
||||
function times2Obj(map){
|
||||
|
@ -63,20 +64,20 @@ function times2Obj(map){
|
|||
return result;
|
||||
}, {});
|
||||
return objSorted;
|
||||
}
|
||||
};
|
||||
|
||||
//TODO make function generic
|
||||
function trips2Array(map){
|
||||
let array=Array.from(map.values());
|
||||
//debug('array: '+array);
|
||||
return array;
|
||||
}
|
||||
};
|
||||
|
||||
function set2Array(set){
|
||||
let array=Array.from(set.values());
|
||||
//debug('set2Array() array.length: '+array.length);
|
||||
return array;
|
||||
}
|
||||
};
|
||||
|
||||
//transform map to object
|
||||
function map2Obj(map){
|
||||
|
@ -85,7 +86,7 @@ function map2Obj(map){
|
|||
object[key]=value;
|
||||
});
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
//TODO make function generic: use map2Obj() instead
|
||||
function trips2Obj(map){
|
||||
|
@ -96,7 +97,7 @@ function trips2Obj(map){
|
|||
});
|
||||
//debug('JSON stringify object: '+JSON.stringify(object));
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports={
|
||||
updateMap,
|
||||
|
|
Loading…
Reference in New Issue