derhuerst / vbb-rest

An HTTP API for Berlin & Brandenburg public transport.
https://v6.vbb.transport.rest/
ISC License
130 stars 12 forks source link

Cancelled trips #19

Closed hildwin closed 6 years ago

hildwin commented 6 years ago

First of all: Thank you for your service. I'm trying to build a display which shows the next departure at my favorite S-Bahn station. Your API is a great help to realize it.

Regarding the output I have a question: How can I recognize that a trip has been canceled?

Example:

Response from http://mobile.bahn.de/: S 85 >> Berlin-Schöneweide (S) 10:08 Fahrt fällt aus, Gl. 2

Response from the API: {'direction': 'S Schöneweide', 'station': {'products': {'suburban': True, 'regional': False, 'express': False, 'tram': False, 'bus': False, 'ferry': False, 'subway': False}, 'name': 'S+U Wittenau', 'coordinates': {'longitude': 13.335479, 'latitude': 52.596388}, 'id': '900000096101', 'type': 'station'}, 'remarks': [None, None], 'trip': 43004, 'line': {'class': 1, 'productCode': 0, 'nr': 85, 'productName': 'S-5', 'name': 'S85', 'symbol': 'S', 'product': 'suburban', 'express': False, 'metro': False, 'night': False, 'id': 's85', 'type': 'line', 'mode': 'train'}, 'ref': '1|43004|2|86|5122017', 'when': '2017-12-05T10:08:00+01:00', 'delay': None}

Thanks in advance!

derhuerst commented 6 years ago

AFAIK my API doesn't support it yet. There's more information about how to tell if a trip has been canceled in https://github.com/derhuerst/hafas-client/issues/2 and I'm currently rewriting the package that queries the VBB API. So you have to be patient for now. 😉

hildwin commented 6 years ago

Thank you. It is possible that delay = None is a hint for a cancelled trip?

derhuerst commented 6 years ago

it may also mean that there's currently no realtime info available, so no, not reliably.

derhuerst commented 6 years ago

In https://github.com/derhuerst/vbb-hafas/commit/6bf353110a597b8b904cd2d582d9625556cbfa73, i have set up logging to collect possible values for dProgType and aProgType (the VBB fields for the type of realtime information). Hopefully I'll get some insights from that an be able to support canceled trips soon.

derhuerst commented 6 years ago

Note to myself: isRchbl may also convey wether the departure/trip has been canceled.

derhuerst commented 6 years ago

Found it! It is dep.dCncl: true and arr.aCncl: true. Will expose them with the next release of vbb-hafas.

deg0nz commented 6 years ago

Nice! That is useful. I‘m gonna integrate it in my MagicMirror module.

derhuerst commented 6 years ago

Sry, with the next release after the one I just released. 😛

derhuerst commented 6 years ago

hafas-client@1.3.0 will expose cancelled: true on a journey leg.

My rewrite (which will likely become hafas-client@2) will also mark the journey as cancelled: true and set departure/arrival, departurePlatform/arrivalPlatform and delay to null.

derhuerst commented 6 years ago

The changes should be live at vbb.transport.rest now. It's hard to test wether everything works though, as only very few departures get canceled.

hildwin commented 6 years ago

I‘ll look into it! Thanks a lot.

hildwin commented 6 years ago

When I do a simple departure request curl 'https://vbb.transport.rest/stations/900000096101/departures?nextStation=900000084101&results=1' at a specific station I get this:

{"ref":"1|40079|0|86|8122017", "station":{"type":"station","name":"S+U Wittenau", "coordinates":{"latitude":52.596388,"longitude":13.335479}, "id":"900000096101", "products":{"suburban":true,"subway":false,"tram":false,"bus":false,"ferry":false,"express":false,"regional":false}}, "when":"2017-12-08T07:36:00+01:00", "direction":"S Wannsee", "line":{"type":"line","name":"S1","class":1,"productCode":0,"productName":"S-7","product":"suburban","mode":"train","public":true,"id":"s1","symbol":"S","nr":1,"metro":false,"express":false,"night":false}, "remarks":[{"type":"A","code":"bf","prio":2,"icoX":3,"txtN":"barrier-free"},{"type":"A","code":"FB","prio":350,"icoX":6,"txtN":"Bicycle conveyance"}], "trip":40079, "delay":60},

Is the new "cancelled" key only available when a trip is cancelled?

derhuerst commented 6 years ago

Is the new cancelled key only available when a trip is cancelled?

Yup. Wasn't sure what's the best way to specify this. Because there are many keys that are not being used all the time, I implemented cancelled in the same way. If the field exists and is true, the journey (part) has been cancelled.

hildwin commented 6 years ago

IMHO: I think that is an important information for everyone. One should be able to see it at a glance. I strongly suggest to show the key all the time. Furthemore I found nothing in the API Docs. Did I miss something? As you said, there are only a few cancelled trips a day. It is (for me) quite challenging to test an application without it.

derhuerst commented 6 years ago

Fair point! You're welcome do discuss this with us over at public-transport/friendly-public-transport-format#27

Regarding testing: Yeah, this is extremely annoying. I have the same problem all the time. Currently, my tests mainly check if the parsed response looks reasonable, but they can't tell if the values are actually correct. For now, I've refrained to mock the API for two reasons: a) It's significantly more work to constantly adapt the mock and b) because I don't test against the real API anymore, which might change underneath at any time.

hildwin commented 6 years ago

Despite the general question I'm happy to discuss with you in the other thread, I've found a cancelled trip without the cancelled key:

Information auf mobile.bahn,de

S 85 >> Berlin-Waidmannslust 16:08 Fahrt fällt aus, Gl. 1

The API result is:

{"ref":"1|42484|5|86|8122017","station":{"type":"station","name":"S+U Wittenau","coordinates":{"latitude":52.596388,"longitude":13.335479},"id":"900000096101","products":{"suburban":true,"subway":false,"tram":false,"bus":false,"ferry":false,"express":false,"regional":false}},"when":"2017-12-08T16:08:00+01:00","direction":"S Waidmannslust","line":{"type":"line","name":"S85","class":1,"productCode":0,"productName":"S-5","product":"suburban","mode":"train","public":true,"id":"s85","symbol":"S","nr":85,"metro":false,"express":false,"night":false},"remarks":[{"type":"A","code":"bf","prio":2,"icoX":4,"txtN":"barrier-free"},{"type":"A","code":"FB","prio":350,"icoX":7,"txtN":"Bicycle conveyance"}],"trip":42484,"delay":null},

derhuerst commented 6 years ago

Interesting. When I first loaded the departures page for S+U Wittenau (Wilhelmsruher Damm), there was an alert "Zug fällt aus". After I had reloaded, it said "Disruption" and only the details told me that there departure has been cancelled. And now, the page doesn't say anything about cancellations anymore.

Please check against the VBB website in the future, as bahn.de might give different data. Also, it would be really helpful for me if you gave me the URL you queried.

hildwin commented 6 years ago

The departure from Wittenau at 07:32 this morning with line S26 was cancelled. The result from the API was:

{'station': {'products': {'tram': False, 'subway': False, 'regional': False, 'ferry': False, 'express': False, 'bus': False, 'suburban': True}, 'name': 'S+U Wittenau', 'type': 'station', 'id': '900000096101', 'coordinates': {'latitude': 52.596388, 'longitude': 13.335479}}, 'remarks': None, 'trip': 30311, 'when': '2017-12-18T07:32:00+01:00', 'direction': 'S Teltow Stadt', 'line': {'product': 'suburban', 'class': 1, 'type': 'line', 'public': True, 'night': False, 'express': False, 'productCode': 0, 'productName': 'S-5', 'metro': False, 'mode': 'train', 'id': 's26', 'symbol': 'S', 'name': 'S26', 'nr': 26}, 'ref': '1|30311|5|86|18122017', 'delay': None}

The VBB-Website shows the following:

07:32 Ausfall | S26 | S Teltow Stadt | Gleis 2  | Störung.: Der Zug fällt aus betrieblichen Gründen aus. (Letzte Aktualisierung 04:29)

The URL was

https://vbb.transport.rest/stations/900000096101/departures?nextStation=900000084101&results=3

hildwin commented 6 years ago

Another answer from the API without the "cancelled trip" key:

{"ref":"1|30311|29|86|18122017","station":{"type":"station","name":"S+U Wittenau","coordinates":{"latitude":52.596388,"longitude":13.335479},"id":"900000096101","products":{"suburban":true,"subway":false,"tram":false,"bus":false,"ferry":false,"express":false,"regional":false}},"when":"2017-12-18T15:32:00+01:00","direction":"S Teltow Stadt","line":{"type":"line","name":"S26","class":1,"productCode":0,"productName":"S-5","product":"suburban","mode":"train","public":true,"id":"s26","symbol":"S","nr":26,"metro":false,"express":false,"night":false},"remarks":null,"trip":30311,"delay":null}

15:32  Ausfall | S26 | S Teltow Stadt Zwischenhalte | Gleis 2 | Störung.: Der Zug fällt aus betrieblichen Gründen aus. (Letzte Aktualisierung 14:33) via this site

s26-ausfall

derhuerst commented 6 years ago

Will look into this, thanks!

derhuerst commented 6 years ago

I had only added the cancelled flag to journey legs. 🙄 Added it to departures and passed stations now. Please check again.

derhuerst commented 6 years ago

I will close this for now. Please reopen if this issue still persists.

derhuerst commented 6 years ago

FYI the discussion has been taken further in #26 and then in public-transport/friendly-public-transport-format#27. Our decision:

derhuerst commented 6 years ago

This has been published as hafas-client@2.4.0. 🎉 Will update 2.vbb.transport.rest now.