planarnetwork / raptor

Implementation of the Route Based Public Transit Algorithm (Raptor)
80 stars 11 forks source link

Readme example doesn't work, argument mismatch? #19

Open Bela0 opened 4 months ago

Bela0 commented 4 months ago

Hello,

unfortunately I can't get the readme sample to work. Line 5 throws an error:

const raptor = RaptorAlgorithmFactory.create(trips, transfers, interchange, calendars);

Dates given in calendars cannot be parsed. Logging the arguments, calendars contains all the stops, not dates and times.

Checking the code, to my understanding loadGTFS() returns [trips, transfers, interchange, stops] while RaptorAlgorithmFactory.create() expects [trips, transfers, interchange, date].

Could you check if this is an error or if I'm misunderstanding anything?

Thank you for your work @linusnorton and @iamralpht !

Best regards!

(I tried multiple GTFS sources, e.g. the Google example feed)

linusnorton commented 4 months ago

Hi, yes, it appears the README.md is wrong. The method definition is:

public static create(
    trips: Trip[],
    transfers: TransfersByOrigin,
    interchange: Interchange,
    date?: Date
  )

Giving a date will filter any trips to ensure they are running on that date as a way of speeding up the actual journey plan.

The journey plan method definition is:

public scan(origins: StopTimes, date: number, dow: DayOfWeek)

The date there is a number (e.g. 20240422). In retrospect it is confusing to have one method accept a Date and the other use a number. It was a very, very minor performance improvement to the scan method.