journeys: remove collection of results

Reverts 7fd574f.
See also https://github.com/public-transport/hafas-client/pull/23#issuecomment-370246163 .
This commit is contained in:
Jannis R 2020-07-19 22:58:12 +02:00
parent 5c05375650
commit 51f4a66bd8
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
4 changed files with 46 additions and 70 deletions

113
index.js
View file

@ -82,7 +82,7 @@ const createClient = (profile, userAgent, opt = {}) => {
return _stationBoard(station, 'ARR', profile.parseArrival, opt) return _stationBoard(station, 'ARR', profile.parseArrival, opt)
} }
const journeys = (from, to, opt = {}) => { const journeys = async (from, to, opt = {}) => {
from = profile.formatLocation(profile, from, 'from') from = profile.formatLocation(profile, from, 'from')
to = profile.formatLocation(profile, to, 'to') to = profile.formatLocation(profile, to, 'to')
@ -173,75 +173,54 @@ const createClient = (profile, userAgent, opt = {}) => {
}) })
} }
// With protocol version `1.16`, the VBB endpoint *used to* fail with const query = {
// `CGI_READ_FAILED` if you pass `numF`, the parameter for the number getPasslist: !!opt.stopovers,
// of results. To circumvent this, we loop here, collecting journeys maxChg: opt.transfers,
// until we have enough. minChgTime: opt.transferTime,
// todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449 depLocL: [from],
const journeys = [] viaLocL: opt.via ? [{loc: opt.via}] : null,
let earlierRef = null, laterRef = null arrLocL: [to],
const more = (when, journeysRef) => { jnyFltrL: filters,
const query = { gisFltrL,
getPasslist: !!opt.stopovers, getTariff: !!opt.tickets,
maxChg: opt.transfers, // todo: this is actually "take additional stations nearby the given start and destination station into account"
minChgTime: opt.transferTime, // see rest.exe docs
depLocL: [from], ushrp: !!opt.startWithWalking,
viaLocL: opt.via ? [{loc: opt.via}] : null,
arrLocL: [to],
jnyFltrL: filters,
gisFltrL,
getTariff: !!opt.tickets,
// todo: this is actually "take additional stations nearby the given start and destination station into account"
// see rest.exe docs
ushrp: !!opt.startWithWalking,
getPT: true, // todo: what is this? getPT: true, // todo: what is this?
getIV: false, // todo: walk & bike as alternatives? getIV: false, // todo: walk & bike as alternatives?
getPolyline: !!opt.polylines getPolyline: !!opt.polylines
// todo: `getConGroups: false` what is this? // todo: `getConGroups: false` what is this?
// todo: what is getEco, fwrd? // todo: what is getEco, fwrd?
}
if (journeysRef) query.ctxScr = journeysRef
else {
query.outDate = profile.formatDate(profile, when)
query.outTime = profile.formatTime(profile, when)
}
if (profile.journeysNumF && opt.results !== null) query.numF = opt.results
if (profile.journeysOutFrwd) query.outFrwd = outFrwd
return profile.request({profile, opt}, userAgent, {
cfg: {polyEnc: 'GPA'},
meth: 'TripSearch',
req: profile.transformJourneysQuery({profile, opt}, query)
})
.then(({res, common}) => {
if (!Array.isArray(res.outConL)) return []
// todo: outConGrpL
const ctx = {profile, opt, common, res}
if (!earlierRef) earlierRef = res.outCtxScrB
let latestDep = -Infinity
for (const rawJourney of res.outConL) {
const journey = profile.parseJourney(ctx, rawJourney)
journeys.push(journey)
if (opt.results !== null && journeys.length >= opt.results) { // collected enough
laterRef = res.outCtxScrF
return {earlierRef, laterRef, journeys}
}
const dep = +new Date(journey.legs[0].departure) // todo
if (dep > latestDep) latestDep = dep
}
if (opt.results === null) return {earlierRef, laterRef, journeys}
const when = new Date(latestDep)
return more(when, res.outCtxScrF) // otherwise continue
})
} }
if (journeysRef) query.ctxScr = journeysRef
else {
query.outDate = profile.formatDate(profile, when)
query.outTime = profile.formatTime(profile, when)
}
if (profile.journeysNumF && opt.results !== null) query.numF = opt.results
if (profile.journeysOutFrwd) query.outFrwd = outFrwd
return more(when, journeysRef) const {
res, common,
} = await profile.request({profile, opt}, userAgent, {
cfg: {polyEnc: 'GPA'},
meth: 'TripSearch',
req: profile.transformJourneysQuery({profile, opt}, query)
})
if (!Array.isArray(res.outConL)) return []
// todo: outConGrpL
const ctx = {profile, opt, common, res}
const journeys = res.outConL
.map(j => profile.parseJourney(ctx, j))
return {
earlierRef: res.outCtxScrB,
laterRef: res.outCtxScrF,
journeys,
}
} }
const refreshJourney = (refreshToken, opt = {}) => { const refreshJourney = (refreshToken, opt = {}) => {

View file

@ -98,7 +98,6 @@ const defaultProfile = {
formatRectangle, formatRectangle,
filters, filters,
journeysNumF: true, // `journeys()` method: support for `numF` field?
journeysOutFrwd: true, // `journeys()` method: support for `outFrwd` field? journeysOutFrwd: true, // `journeys()` method: support for `outFrwd` field?
departuresGetPasslist: true, // `departures()` method: support for `getPasslist` field? departuresGetPasslist: true, // `departures()` method: support for `getPasslist` field?
departuresStbFltrEquiv: true, // `departures()` method: support for `stbFltrEquiv` field? departuresStbFltrEquiv: true, // `departures()` method: support for `stbFltrEquiv` field?

View file

@ -71,7 +71,6 @@ const oebbProfile = {
parseLocation: parseHook(_parseLocation, fixWeirdPOIs), parseLocation: parseHook(_parseLocation, fixWeirdPOIs),
parseMovement: parseHook(_parseMovement, fixMovement), parseMovement: parseHook(_parseMovement, fixMovement),
journeysNumF: false,
trip: true, trip: true,
radar: true, radar: true,
reachableFrom: true reachableFrom: true

View file

@ -119,7 +119,6 @@ const vbbProfile = {
formatStation, formatStation,
journeysNumF: true,
journeysWalkingSpeed: true, journeysWalkingSpeed: true,
trip: true, trip: true,
radar: true, radar: true,