query journeys

This commit is contained in:
Jannis R 2017-11-12 20:02:32 +01:00
parent c20fd35c67
commit 2c2826217e
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 55 additions and 4 deletions

View file

@ -28,9 +28,7 @@ const createClient = (profile) => {
time: profile.formatTime(profile, opt.when),
stbLoc: profile.formatStation(station),
dirLoc: dir,
jnyFltrL: [
profile.formatProducts(opt.products) // todo
],
jnyFltrL: [products],
dur: opt.duration,
getPasslist: false
}
@ -42,7 +40,58 @@ const createClient = (profile) => {
})
}
return {departures}
const journeys = (from, to, opt = {}) => {
from = profile.formatLocation(profile, from)
to = profile.formatLocation(profile, to)
opt = Object.assign({
results: 5, // how many journeys?
via: null, // let journeys pass this station?
passedStations: false, // return stations on the way?
transfers: 5, // maximum of 5 transfers
transferTime: 0, // minimum time for a single transfer in minutes
// todo: does this work with every endpoint?
accessibility: 'none', // 'none', 'partial' or 'complete'
bike: false, // only bike-friendly journeys
}, opt)
if (opt.via) opt.via = profile.formatLocation(profile, opt.via)
opt.when = opt.when || new Date()
const products = profile.formatProducts(opt.products || {})
const query = profile.transformJourneysQuery({
outDate: profile.formatDate(profile, opt.when),
outTime: profile.formatTime(profile, opt.when),
numF: opt.results,
getPasslist: !!opt.passedStations,
maxChg: opt.transfers,
minChgTime: opt.transferTime,
depLocL: [from],
viaLocL: opt.via ? [opt.via] : null,
arrLocL: [to],
jnyFltrL: [products],
// todo: what is req.gisFltrL?
// todo: what are all these for?
getPT: true,
outFrwd: true,
getTariff: false,
getIV: false, // walk & bike as alternatives?
getPolyline: false // shape for displaying on a map?
}, opt)
return request(profile, {
cfg: {polyEnc: 'GPA'},
meth: 'TripSearch',
req: query
})
.then((d) => {
if (!Array.isArray(d.outConL)) return []
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
return d.outConL.map(parse)
})
}
return {departures, journeys}
}
module.exports = createClient

View file

@ -28,6 +28,8 @@ const defaultProfile = {
transformReqBody: id,
transformReq: id,
transformJourneysQuery: id,
parseDateTime,
parseDeparture,
parseJourney,