5.0.0 • Published 3 months ago

hafas-discover-stations v5.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
3 months ago

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.

npm version ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

Installing

npm install hafas-discover-stations

Usage

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 discovered
  • stats: an object with the following keys: - stopsAndStations: the number of stops/stations discovered - edges: the number of edges discovered - totalReqs: the number of requests sent - avgReqDuration: the average duration of the last 30 requests - queuedReqs: the number of queued requests
  • edge: a connection between two stops/stations, with the following keys: - source: a Friendly Public Transport Format 1.2.0 stop/station object - target: a Friendly Public Transport Format 1.2.0 stop/station object - duration: time to travel, in milliseconds - line: a Friendly Public Transport Format 1.2.0 line object

API

walk(stationId, [opt])

opt may have the following keys. It will be passed into queue().

  • concurrency: number of requests run in parallel – default: 2
  • timeout: timeout for a single job in milliseconds – default: 10000
  • parseStationId: an optional function to process station IDs – default: id => id
  • stationLines: Query lines of stops/stations? – default: false
  • shouldQueryDeparturesAt(stopId, nrOfHops): Should departures be queries from this stopId, 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.

5.0.0

3 months ago

4.2.2

3 months ago

4.2.1

2 years ago

4.2.0

2 years ago

4.1.0

3 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago