Skip to content

Commit 51f4a66

Browse files
committed
journeys: remove collection of results
Reverts 7fd574f. See also #23 (comment) .
1 parent 5c05375 commit 51f4a66

File tree

4 files changed

+45
-69
lines changed

4 files changed

+45
-69
lines changed

index.js

+45-66
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const createClient = (profile, userAgent, opt = {}) => {
8282
return _stationBoard(station, 'ARR', profile.parseArrival, opt)
8383
}
8484

85-
const journeys = (from, to, opt = {}) => {
85+
const journeys = async (from, to, opt = {}) => {
8686
from = profile.formatLocation(profile, from, 'from')
8787
to = profile.formatLocation(profile, to, 'to')
8888

@@ -173,75 +173,54 @@ const createClient = (profile, userAgent, opt = {}) => {
173173
})
174174
}
175175

176-
// With protocol version `1.16`, the VBB endpoint *used to* fail with
177-
// `CGI_READ_FAILED` if you pass `numF`, the parameter for the number
178-
// of results. To circumvent this, we loop here, collecting journeys
179-
// until we have enough.
180-
// todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449
181-
const journeys = []
182-
let earlierRef = null, laterRef = null
183-
const more = (when, journeysRef) => {
184-
const query = {
185-
getPasslist: !!opt.stopovers,
186-
maxChg: opt.transfers,
187-
minChgTime: opt.transferTime,
188-
depLocL: [from],
189-
viaLocL: opt.via ? [{loc: opt.via}] : null,
190-
arrLocL: [to],
191-
jnyFltrL: filters,
192-
gisFltrL,
193-
getTariff: !!opt.tickets,
194-
// todo: this is actually "take additional stations nearby the given start and destination station into account"
195-
// see rest.exe docs
196-
ushrp: !!opt.startWithWalking,
197-
198-
getPT: true, // todo: what is this?
199-
getIV: false, // todo: walk & bike as alternatives?
200-
getPolyline: !!opt.polylines
201-
// todo: `getConGroups: false` what is this?
202-
// todo: what is getEco, fwrd?
203-
}
204-
if (journeysRef) query.ctxScr = journeysRef
205-
else {
206-
query.outDate = profile.formatDate(profile, when)
207-
query.outTime = profile.formatTime(profile, when)
208-
}
209-
if (profile.journeysNumF && opt.results !== null) query.numF = opt.results
210-
if (profile.journeysOutFrwd) query.outFrwd = outFrwd
211-
212-
return profile.request({profile, opt}, userAgent, {
213-
cfg: {polyEnc: 'GPA'},
214-
meth: 'TripSearch',
215-
req: profile.transformJourneysQuery({profile, opt}, query)
216-
})
217-
.then(({res, common}) => {
218-
if (!Array.isArray(res.outConL)) return []
219-
// todo: outConGrpL
220-
221-
const ctx = {profile, opt, common, res}
222-
223-
if (!earlierRef) earlierRef = res.outCtxScrB
176+
const query = {
177+
getPasslist: !!opt.stopovers,
178+
maxChg: opt.transfers,
179+
minChgTime: opt.transferTime,
180+
depLocL: [from],
181+
viaLocL: opt.via ? [{loc: opt.via}] : null,
182+
arrLocL: [to],
183+
jnyFltrL: filters,
184+
gisFltrL,
185+
getTariff: !!opt.tickets,
186+
// todo: this is actually "take additional stations nearby the given start and destination station into account"
187+
// see rest.exe docs
188+
ushrp: !!opt.startWithWalking,
189+
190+
getPT: true, // todo: what is this?
191+
getIV: false, // todo: walk & bike as alternatives?
192+
getPolyline: !!opt.polylines
193+
// todo: `getConGroups: false` what is this?
194+
// todo: what is getEco, fwrd?
195+
}
196+
if (journeysRef) query.ctxScr = journeysRef
197+
else {
198+
query.outDate = profile.formatDate(profile, when)
199+
query.outTime = profile.formatTime(profile, when)
200+
}
201+
if (profile.journeysNumF && opt.results !== null) query.numF = opt.results
202+
if (profile.journeysOutFrwd) query.outFrwd = outFrwd
203+
204+
const {
205+
res, common,
206+
} = await profile.request({profile, opt}, userAgent, {
207+
cfg: {polyEnc: 'GPA'},
208+
meth: 'TripSearch',
209+
req: profile.transformJourneysQuery({profile, opt}, query)
210+
})
224211

225-
let latestDep = -Infinity
226-
for (const rawJourney of res.outConL) {
227-
const journey = profile.parseJourney(ctx, rawJourney)
228-
journeys.push(journey)
212+
if (!Array.isArray(res.outConL)) return []
213+
// todo: outConGrpL
229214

230-
if (opt.results !== null && journeys.length >= opt.results) { // collected enough
231-
laterRef = res.outCtxScrF
232-
return {earlierRef, laterRef, journeys}
233-
}
234-
const dep = +new Date(journey.legs[0].departure) // todo
235-
if (dep > latestDep) latestDep = dep
236-
}
215+
const ctx = {profile, opt, common, res}
216+
const journeys = res.outConL
217+
.map(j => profile.parseJourney(ctx, j))
237218

238-
if (opt.results === null) return {earlierRef, laterRef, journeys}
239-
const when = new Date(latestDep)
240-
return more(when, res.outCtxScrF) // otherwise continue
241-
})
219+
return {
220+
earlierRef: res.outCtxScrB,
221+
laterRef: res.outCtxScrF,
222+
journeys,
242223
}
243-
244-
return more(when, journeysRef)
245224
}
246225

247226
const refreshJourney = (refreshToken, opt = {}) => {

lib/default-profile.js

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const defaultProfile = {
9898
formatRectangle,
9999
filters,
100100

101-
journeysNumF: true, // `journeys()` method: support for `numF` field?
102101
journeysOutFrwd: true, // `journeys()` method: support for `outFrwd` field?
103102
departuresGetPasslist: true, // `departures()` method: support for `getPasslist` field?
104103
departuresStbFltrEquiv: true, // `departures()` method: support for `stbFltrEquiv` field?

p/oebb/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const oebbProfile = {
7171
parseLocation: parseHook(_parseLocation, fixWeirdPOIs),
7272
parseMovement: parseHook(_parseMovement, fixMovement),
7373

74-
journeysNumF: false,
7574
trip: true,
7675
radar: true,
7776
reachableFrom: true

p/vbb/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ const vbbProfile = {
119119

120120
formatStation,
121121

122-
journeysNumF: true,
123122
journeysWalkingSpeed: true,
124123
trip: true,
125124
radar: true,

0 commit comments

Comments
 (0)