derhuerst / vbb-rest

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

document which routes are GTFS-based & which HAFAS-based #45

Open Cediddi opened 3 years ago

Cediddi commented 3 years ago

Hi, I'm trying to use this library and I'm following a workflow like this:

Last step throws an error like this:

{
  "isHafasError": true,
  "request": "{\"lang\":\"en\",\"svcReqL\":[{\"meth\":\"LocDetails\",\"req\":{\"locL\":[{\"type\":\"S\",\"lid\":\"A=1@L=001009267@\"}]}}],\"client\":{\"type\":\"IPA\",\"id\":\"VBB\",\"name\":\"vbbPROD\",\"v\":\"4010300\"},\"ext\":\"VBB.1\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"hafas-vbb-apps\"}}",
  "url": "https://fahrinfo.vbb.de/bin/mgate.exe?mic=bb4618f0b209632fb61e9dae462aabe2&mac=a246d90418328ad9249c3dda23fdc111",
  "statusCode": 400,
  "isClient": true,
  "code": "INVALID_REQUEST",
  "message": "location/stop not found",
  "hafasErrorCode": "LOCATION",
  "hafasErrorMessage": "HCI Service: location missing or invalid",
  "error": true,
  "msg": "HAFAS error: location/stop not found"
}

The query I'm running looks like this https://v5.vbb.transport.rest/stops/070301009267

I think my workflow is correct and this is a bug. Can you confirm?

derhuerst commented 3 years ago
  • Select a station and get details (name='Berlin, Mollstr./Otto-Braun-Str.' id='900000100040')

You're fetching https://v5.vbb.transport.rest/stops/900000100040?linesOfStops=true I assume?

  • Select a line from the station (name=M8 id='17463_900')

An M8 line with an id of 17463_900 doesn't exist for me:

curl 'https://v5.vbb.transport.rest/stops/900000100040?linesOfStops=true' -s | jq
{
    "type": "stop",
    "id": "900000100040",
    "name": "Mollstr./Otto-Braun-Str.",
    "location": {
        "type": "location",
        "id": "900100040",
        "latitude": 52.525185,
        "longitude": 13.419942
    },
    "products": {
        "suburban": false,
        "subway": false,
        "tram": true,
        "bus": true,
        "ferry": false,
        "express": false,
        "regional": false
    },
    "lines": [
        {
            "type": "line",
            "id": "12",
            "fahrtNr": null,
            "name": "12",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": null,
            "nr": 12,
            "metro": false,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#6c5b98"
            }
        },
        {
            "type": "line",
            "id": "50",
            "fahrtNr": null,
            "name": "50",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": null,
            "nr": 50,
            "metro": false,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#16a696"
            }
        },
        {
            "type": "line",
            "id": "m1",
            "fahrtNr": null,
            "name": "M1",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": "M",
            "nr": 1,
            "metro": true,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#ed9222"
            }
        },
        {
            "type": "line",
            "id": "m2",
            "fahrtNr": null,
            "name": "M2",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": "M",
            "nr": 2,
            "metro": true,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#7eb43d"
            }
        },
        {
            "type": "line",
            "id": "m4",
            "fahrtNr": null,
            "name": "M4",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": "M",
            "nr": 4,
            "metro": true,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#d01c22"
            }
        },
        {
            "type": "line",
            "id": "m5",
            "fahrtNr": null,
            "name": "M5",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": "M",
            "nr": 5,
            "metro": true,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#c48946"
            }
        },
        {
            "type": "line",
            "id": "m6",
            "fahrtNr": null,
            "name": "M6",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": "M",
            "nr": 6,
            "metro": true,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#01609c"
            }
        },
        {
            "type": "line",
            "id": "m8",
            "fahrtNr": null,
            "name": "M8",
            "public": true,
            "mode": "train",
            "product": "tram",
            "symbol": "M",
            "nr": 8,
            "metro": true,
            "express": false,
            "night": false,
            "color": {
                "fg": "#fff",
                "bg": "#f47922"
            }
        },
        {
            "type": "line",
            "id": "142",
            "fahrtNr": null,
            "name": "142",
            "public": true,
            "mode": "bus",
            "product": "bus",
            "symbol": null,
            "nr": 142,
            "metro": false,
            "express": false,
            "night": false
        },
        {
            "type": "line",
            "id": "200",
            "fahrtNr": null,
            "name": "200",
            "public": true,
            "mode": "bus",
            "product": "bus",
            "symbol": null,
            "nr": 200,
            "metro": false,
            "express": false,
            "night": false
        }
    ]
}
  • Select the variant with most trips (the one with 371 trips)

How do you do that? Where do you get the number of trips from?

Cediddi commented 3 years ago

I can provide a pseudo code.

response = GET https://v5.vbb.transport.rest/stations?query=mollstr
station = select first from request where name = 'Berlin, Mollstr./Otto-Braun-Str.'

response = GET https://v5.vbb.transport.rest/stations/{station['id']}
line = select first from response['lines'] where name = 'M8'

response = GET https://v5.vbb.transport.rest/lines/{line['id']}
variant = select first from response['variants'] order by trips descending

first_stop = select first from variant['stops'] 

response = GET https://v5.vbb.transport.rest/stops/{first_stop}
// response is 502

I'm using python, you can check the script that I'm writing. Problematic part is line 186

https://gist.github.com/Cediddi/cfcf84aa3541a46beeee4064e3e33e40#file-allons_y-py-L186

derhuerst commented 3 years ago

Ah, now I understand the problem!

These routes just return GTFS data:

The other routes (including /stops/{id}) query VBB's HAFAS API.

Unfortunately, the GTFS stop/station IDs & line IDs don't always match the HAFAS stop/station IDs & line IDs. Most of the times they work with HAFAS, but "haltepunkt"-like stop IDs (e.g. those of individual tram tracks at a station) apparently don't.

Sorry, this is really not documented at all. 😔

derhuerst commented 3 years ago

Can you tell me what you would like to build? Maybe I can tell you how to solve this with the v5.vbb.transport.rest API.

Cediddi commented 3 years ago

It is a coding challenge for a job application, thus I cannot share the question.

I think this API needs an open api documentation, other than that I think it's a great api and really easy to use and understand.

derhuerst commented 3 years ago

Completely agree, I've been planning to add an Open API spec for a while, just haven't found the time & motivation to do it yet.

[...] I think it's a great api and really easy to use and understand.

Well, I disagree in regards to the opaque HAFAS/GTFS distinction.