-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bahn.de boards #12
bahn.de boards #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is looking great already!
However, we definitely need to preserve the regio-guide endpoint for the db
profile (among others since it's still the only endpoint that supports querying more than 1 hour). In #3, I had proposed to introduce a new profile, e.g. dbweb
where one could move all implementations of the bahn.de endpoints. If you have another idea, that's also fine.
For the stop/station parsing, I'm fine with all three options, however, as I've commented below, the station enrichment should still work, i.e. you should not return early from parseLocation
. One of the other two options probably makes this easier (and whole, unrelated objects are passed in many places, even though I agree it's ugly :) This could also resolve the int test issue, if you set enrichStations: true
in db.js#L85 (or rather, in dbweb.js
or sth) (but this may lead to race conditions, since the station index is loaded asynchronously, so maybe we will need another solution, not sure).
Regarding vias, one could also employ enrichStations
for that (based on name matching), but this is probably quite ugly. So while I'm trying to avoid any divergence from hafas-client, I think in this case it is fine how you did it.
Thanks for the thorough review!
Long term, this is probably the best idea. I'll attempt to implement that
I wasn't aware of station enrichment at all and will toy around with it
A rather naive question, but why would race conditions be an issue here? Are there multiple stations with the same station index?
I'll try to see how well things work with name matching. If it turns out to work well, I'd be in favor of doing it the dirty way if that helps making this library a better drop in replacement of hafas-client 🤔 |
If you don't want to invest the time, I can also have a look at it.
Maybe race conditions is the wrong term. Tests might be toggling, because sometimes, the station index will have loaded in time before the respective tests execute and sometimes the test will execute first, making them fail (since station details are missing). But I haven't actually tested it, maybe it just works.
Yup sounds good, the guys from this issue would surely be happy about it I guess. |
I'd be happy to try that myself. Thanks for the offer!
Thanks for the useful hints 🙏 |
What I tried doesn't seem to work for older node versions, hold on... |
Haven't looked at it in detail, what's the reason you're doing this dynamic stuff? Can't you just import stuff from other profiles and the default profile in |
The idea would be, that we have a single source of truth (dynamicProfileData.json in this case) for which profile endpoint uses which profile. Otherwise, if we wanted to change the preferred profile, we'd have to ensure that the imports are consistent with the base urls. Here's a longer explanation I have prepared: This adds the However, apparently, older node versions have a problem with synchronously importing an es module with |
What you could do is just import everything in But I'm currently not sure whether this setup actually simplifies anything, although I agree that without it one does have to make sure that the base urls match the imports (but one could also import/reuse the base urls from the profiles and at least don't have to hardcode the urls twice, i.e. still not needing a What would be interesting is to be able to switch to another profile on the fly (e.g. by passing a parameter to the REST API). However, I don't really see that the (Thinking about it, it may be best to implement on-the-fly profile switching downstream e.g. in db-rest and just instantiate multiple Apart from that, the splitting into |
Thinking about it, I will resort to the simplest option of statically importing just the necessary stuff and putting the functions/endpoint bases into the profile one by one. If something goes wrong here, this should be caught by the |
I think this should be good. I'll implement the rest of this pr later today |
The changes from 73a71e0 to the dbweb arrival fixture show that removing all non-digits greatly improves the results ^^ |
That was indeed a problem. Right now I make the tests repeatedly call the corresponding board function every four seconds until the station objects can be enriched. Otherwise, the test just timeouts. This is unbelievably ugly, but I couldn't come up with a better solution. Can you think of a better solution here? |
…tations when only name is known
The code for adding the stopovers in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes so if we decide switch over db
from bahn.de to DB Navigator (see comment), we should definitely verify again that not too much stuff changes (as far as I see, there is no test/fixture anymore that does that rn).
For the enrichStations test hack, one could benefit from being able to optionally pass the station index into the client (idea in the context of on-the-fly profile switching). For the time being, I think we can leave it like you have done it and replace it as soon as we've implemented this, which I intend to do soon anyways.
I think this is it. Let me know if you notice some more issues |
Cool, thanks a lot! Will hopefully come around to create a release tomorrow (that is, today). |
resolves #3
Some notes/uncertainties:
parseLocation()
. Other options I am aware of would have been the creation of thestation
object withinparseArrOrDep()
, which would not have been too elegant and passing the whole object toparseLocation()
, which I didn't really like either, as there is a higher risk of accidentally parsing completely unrelated values.name
of astation
to exist. How should we deal with this? Is setting this property to an empty string an option?vias
option users can set the amount of displayed vias with. I am aware of thestopovers
option from hafas-client, but decided against using it for two reasons:stopovers
served the purpose of returning the next/previous stopovers asstation
objects, but here, we only get the names, so the expected functionality would not have been satisfied. Also, by lettingvias
be a number instead of just a bool, we can expose themaxVias
query from the api to users