public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DB: support "best price search"

derhuerst opened this issue · comments

Both the Deutsche Bahn (DB) website as well as their app have a feature called "best price search" or "Bestpreissuche", which works just like the regular journeys() (TripSearch in HAFAS), except that it returns the lowest-price journeys for each time bracket.

The details of this BestPriceSearch call are documented at juliuste/db-prices#33 (comment) . It's response data looks like the one of a TripSearch call, but it also has a field res.outDaySegL that groups the journeys in res.outConL[] into time brackets.

Not sure how this functionality should be exposed:

  • We could let journeys() always parse & expose a grouping/bracketing of journeys as soon as the HAFAS response contains it. A DB-specific opt.bestPriceSearch option would use BestPriceSearch and outTime: "000000".
  • Within the DB profile, we could implement it as an entirely separate hafas-client method. It would have to share much of the logic with journeys(). Currently, we don't have a mechanism to let profiles add methods though.

pyhafas equivalent Issue: FahrplanDatenGarten/pyhafas#26

@TheRealMurmel FYI: Implementing the "best price search" feature here in hafas-client, as described above, would be quite straightforward, as most of the response structure is already supported.

@derhuerst I would really like to provide more help, but I'm note quite sure when I will have time to contribute here.

@derhuerst I built a small Python-based project to replay the relevant API requests, this might help someone else to re-implement the requests into hafas-client:

https://github.com/TheRealMurmel/py-bahn-api

BTW, if you're more comfortable tinkering with Python instead of JS, adding support for "best price search" to pyhafas would also be an option! We can then port the code over to hafas-client.

I'll give it a try!

@bergmannjg has built an "MVP" implementation of this.

It's nothing more than replacing

meth: "TripSearch"

with

meth: "BestPriceSearch"

in the corresponding HAFAS request.

It works.

@derhuerst said

Not sure how this functionality should be exposed:

  • We could let journeys() always parse & expose a grouping/bracketing of journeys as soon as the HAFAS response contains it. A DB-specific opt.bestPriceSearch option would use BestPriceSearch and outTime: "000000".
  • Within the DB profile, we could implement it as an entirely separate hafas-client method. It would have to share much of the logic with journeys(). Currently, we don't have a mechanism to let profiles add methods though.

I would propose to add an new method to the hafas-client API because the bestprice search options are only a subset of the journey search options and the results are different.

Here is my (not yet complete) implementation

  • there is a new bestPrices method, which is only valid for the db profile
  • the parsed value of the res.outDaySegL array is the result of bestPrices
  • a first unit test is in db-bestprice.js

Is this planned to be merged? / worked on?

Here is my (not yet complete) implementation

I am running this for a few days already without problems, just added the date as a parameter.