hafas-discover-stations
v5.0.0
Published
Pass in a HAFAS client, discover stations by querying departures.
Maintainers
Readme
hafas-discover-stations
Pass in a HAFAS client, discover stops/stations by querying departures. It tries to find all stops/stations that all trains known by the endpoint stop at.
Installing
npm install hafas-discover-stationsUsage
import {createWalkAndDiscoverStations as createWalk} from 'hafas-discover-stations'
import {createClient as createHafas} from 'hafas-client'
import {profile as dbProfile} from 'hafas-client/p/db/index.js'
const hafas = createHafas(dbProfile, 'my-awesome-program')
const walk = createWalk(hafas)
const berlinFriedrichstr = '8011306' // where to start
for await (const stopOrStation of walk(berlinFriedrichstr)) {
console.log(stopOrStation)
}walk() returns a readable stream in object mode. It emits the following events:
data: a new stop/station that has been discoveredstats: an object with the following keys:stopsAndStations: the number of stops/stations discoverededges: the number of edges discoveredtotalReqs: the number of requests sentavgReqDuration: the average duration of the last 30 requestsqueuedReqs: the number of queued requests
edge: a connection between two stops/stations, with the following keys:source: a Friendly Public Transport Format1.2.0stop/stationobjecttarget: a Friendly Public Transport Format1.2.0stop/stationobjectduration: time to travel, in millisecondsline: a Friendly Public Transport Format1.2.0lineobject
API
walk(stationId, [opt])opt may have the following keys. It will be passed into queue().
concurrency: number of requests run in parallel – default:2timeout: timeout for a single job in milliseconds – default:10000parseStationId: an optional function to process station IDs – default:id => idstationLines: Query lines of stops/stations? – default:falseshouldQueryDeparturesAt(stopId, nrOfHops): Should departures be queries from thisstopId, effectively continuing the graph search? – default:() => true
Contributing
If you have a question or need support using hafas-discover-stations, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.
