feat(axios-get-trip): extend index and add utils
This commit is contained in:
parent
d7de2b1736
commit
0b4d85da7b
|
@ -1,5 +1,6 @@
|
|||
require('dotenv').config();
|
||||
const axios = require('axios');
|
||||
const utils=require('./utils');
|
||||
const axios=require('axios');
|
||||
const debug=require('debug')('trips');
|
||||
|
||||
const URL=process.env.URL;
|
||||
|
@ -29,47 +30,68 @@ async function run() {
|
|||
debug('dataGet.data[0].route_short_name: %s',dataGet.data[0].route_short_name);
|
||||
debug('dataGet.data[0].agency_id: %s',dataGet.data[0].agency_id);
|
||||
debug('dataGet.data[0].route_id: %s',dataGet.data[0].route_id);
|
||||
|
||||
/*
|
||||
const service_id=dataGet.data[0].service_id;
|
||||
debug('service_id: %s',service_id);
|
||||
|
||||
debug('dataGet.data[0].service_id: %s',dataGet.data[0].service_id);
|
||||
debug('dataGet.data[0].trip_id: %s',dataGet.data[0].trip_id);
|
||||
|
||||
const queryService=`http://localhost:65534/service?serviceid=${service_id}`;
|
||||
debug('queryService: '+queryService);
|
||||
let dataService = await axios.get(queryService);
|
||||
const trip_id=dataGet.data[0].trip_id;
|
||||
debug('trip_id: %s',trip_id);
|
||||
*/
|
||||
for(var i = 0; i < 2; i++)
|
||||
{
|
||||
const tripId=dataGet.data[i].trip_id;
|
||||
debug('tripId: %s',tripId);
|
||||
const serviceId=dataGet.data[0].service_id;
|
||||
debug('serviceId: %s',serviceId);
|
||||
|
||||
debug('dataService received via GET');
|
||||
debug('dataService: %s',dataService);
|
||||
debug('dataService.data.length: %s',dataService.data.length);
|
||||
debug('dataService.data: %s',dataService.data);
|
||||
const queryService=`http://localhost:65534/service?serviceid=${serviceId}`;
|
||||
debug('queryService: '+queryService);
|
||||
let dataService = await axios.get(queryService);
|
||||
|
||||
const monday=dataService.data[0].monday;
|
||||
debug('monday: %s',monday);
|
||||
const monday=dataService.data[0].monday;
|
||||
const tuesday=dataService.data[0].tuesday;
|
||||
const wednesday=dataService.data[0].wednesday;
|
||||
const thursday=dataService.data[0].thursday;
|
||||
const friday=dataService.data[0].friday;
|
||||
const saturday=dataService.data[0].saturday;
|
||||
const sunday=dataService.data[0].sunday;
|
||||
const start_date=dataService.data[0].start_date;
|
||||
const end_date=dataService.data[0].end_date;
|
||||
const mapTime=new Map();
|
||||
const timeStart=utils.gtfsDate2NodeDate(start_date).getTime();
|
||||
debug('timeStart: '+timeStart);
|
||||
debug('mapTime size: '+mapTime.size);
|
||||
debug('mapTime has timeStart: '+mapTime.has(timeStart));
|
||||
mapTime.set(timeStart,tripId);
|
||||
debug('mapTime size: '+mapTime.size);
|
||||
debug('mapTime has timeStart: '+mapTime.has(timeStart));
|
||||
}
|
||||
/*
|
||||
const map=new Map();
|
||||
|
||||
const tuesday=dataService.data[0].tuesday;
|
||||
debug('tuesday: %s',tuesday);
|
||||
debug('map size: '+map.size);
|
||||
debug('map has start_date: '+map.has(start_date));
|
||||
map.set(start_date,trip_id);
|
||||
debug('map size: '+map.size);
|
||||
debug('map has start_date: '+map.has(start_date));
|
||||
|
||||
const wednesday=dataService.data[0].wednesday;
|
||||
debug('wednesday: %s',wednesday);
|
||||
debug('map has end_date: '+map.has(end_date));
|
||||
map.set(end_date,trip_id);
|
||||
debug('map size: '+map.size);
|
||||
debug('map has end_date: '+map.has(end_date));
|
||||
|
||||
const thursday=dataService.data[0].thursday;
|
||||
debug('thursday: %s',thursday);
|
||||
|
||||
const friday=dataService.data[0].friday;
|
||||
debug('friday: %s',friday);
|
||||
|
||||
const saturday=dataService.data[0].saturday;
|
||||
debug('saturday: %s',saturday);
|
||||
|
||||
const sunday=dataService.data[0].sunday;
|
||||
debug('sunday: %s',sunday);
|
||||
|
||||
const start_date=dataService.data[0].start_date;
|
||||
debug('start_date: %s',start_date);
|
||||
|
||||
const end_date=dataService.data[0].end_date;
|
||||
debug('end_date: %s',end_date);
|
||||
const mapDate=new Map();
|
||||
const nodeDateStart=utils.gtfsDate2NodeDate(start_date);
|
||||
debug('nodeDateStart: '+nodeDateStart);
|
||||
|
||||
debug('mapDate size: '+mapDate.size);
|
||||
debug('mapDate has nodeDateStart: '+mapDate.has(nodeDateStart));
|
||||
mapDate.set(nodeDateStart,trip_id);
|
||||
debug('mapDate size: '+mapDate.size);
|
||||
debug('mapDate has nodeDateStart: '+mapDate.has(nodeDateStart));
|
||||
const nodeDateStartCopy=new Date(nodeDateStart);
|
||||
debug('mapDate has nodeDateStartCopy: '+mapDate.has(nodeDateStartCopy));
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
const debug=require('debug')('utils');
|
||||
|
||||
function findSubStr(str, start, end) {
|
||||
var index = str.slice(start, end);
|
||||
debug('index: '+index);
|
||||
return index;
|
||||
}
|
||||
|
||||
function gtfsDate2NodeDate(date){
|
||||
let start = 0;
|
||||
let end = 4;
|
||||
let year=findSubStr(date, start, end);
|
||||
debug('year: '+year);
|
||||
start=4;
|
||||
end=6;
|
||||
let month=findSubStr(date, start, end);
|
||||
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.toDateString());
|
||||
return nodeDate;
|
||||
}
|
||||
|
||||
module.exports={
|
||||
gtfsDate2NodeDate
|
||||
};
|
Loading…
Reference in New Issue