OpendataCH / Transport

Swiss public transport API
http://transport.opendata.ch/
MIT License
241 stars 50 forks source link

Negative number of transfers: "-1" ; does this have any physical meaning? #205

Closed swiss-knight closed 4 years ago

swiss-knight commented 4 years ago

Hi,

I'm trying to learn how to to use the Transport API, but I see strange data such as this -1 for the number of transfer for a small bus journey:

image

What does this mean? To me, a 0 transfer journey is a single trip with a single vehicle. 1 transfer means you have to change to take a second vehicle during the journey, and so one.

Does -1 means you don't have to take any vehicle because nothing is available and you must go by your own means, e.g. by foot basically?

Thanks.

helbling commented 4 years ago

Please report an URL or at least your search parameters, where this problem exists. Thanks!

swiss-knight commented 4 years ago

Yes, here are some randomly picked, I hope it can help;

https://transport.opendata.ch/v1/connections?from=8501008&to=Genève%2C+Rue+du+Commerce+3&via=&date=2020-04-16&time=10%3A31&isArrivalTime=0&limit=8&page=&direct=0&sleeper=0&couchette=0&bike=0&accessibility=

https://transport.opendata.ch/v1/connections?from=8592801&to=Gen%C3%A8ve%2C+Rue+du+Commerce+3&via=&date=2020-04-16&time=10%3A31&isArrivalTime=0&limit=8&page=&direct=0&sleeper=0&couchette=0&bike=0&accessibility=

https://transport.opendata.ch/v1/connections?from=8530008&to=Neuch%C3%A2tel%2C+Faubourg+de+l%27H%C3%B4pital+35&via=&date=2020-04-16&time=10%3A40&isArrivalTime=0&limit=8&page=&direct=0&sleeper=0&couchette=0&bike=0&accessibility=

https://transport.opendata.ch/v1/connections?from=8571357&to=Bern%2C+Amselweg+5&via=&date=2020-04-16&time=10%3A43&isArrivalTime=0&limit=8&page=&direct=0&sleeper=0&couchette=0&bike=0&accessibility=

...

fabian commented 4 years ago

I initially thought this data was coming directly from timetable.search.ch but I've noticed now that it's actually a calculated property, see also #169:

https://github.com/OpendataCH/Transport/blob/6394429c82e0c6cc3f34b92f104a0e8199428c62/lib/Transport/Entity/Schedule/Connection.php#L159-L165

It looks like it ends up with -1 if the connection is only a walk. I think adding this should solve the problem:

        $obj->transfers = max($numberOfVehicles - 1, 0);
fabian commented 4 years ago

Fixed, thanks for reporting it! ☺️