alexander-albers / tripkit

Swift library for querying data from public transport providers.
MIT License
83 stars 8 forks source link

BVG: include Berlkönig #26

Closed alexander-albers closed 3 years ago

alexander-albers commented 3 years ago

BVG requires, for whatever reason, that the product type "BERLKOENIG" is included, or otherwise some trips may fail, even if those don't include any Berlkönig products.

See for example this request:

{
  "auth": {
    "aid": <secret>,
    "type": "AID"
  },
  "svcReqL": [
    {
      "meth": "TripSearch",
      "cfg": {},
      "req": {
        "arrLocL": [
          {
            "type": "S",
            "lid": "A=1@O=U Elsterwerdaer Platz (Berlin)@X=13560758@Y=52504644@U=86@L=900171006@B=1@p=1617247685@"
          }
        ],
        "getPolyline": true,
        "gisFltrL": [
          {
            "type": "M",
            "meta": "foot_speed_normal",
            "profile": {
              "linDistRouting": false,
              "maxdist": 2000,
              "type": "F"
            },
            "mode": "FB"
          }
        ],
        "depLocL": [
          {
            "lid": "A=1@O=Pilgramer Str./Rahnsdorfer Str. (Berlin)@X=13619395@Y=52496554@U=86@L=900176540@B=1@p=1617247685@",
            "type": "S"
          }
        ],
        "outFrwd": true,
        "outTime": "080000",
        "extChgTime": -1,
        "getPasslist": true,
        "trfReq": {
          "jnyCl": 2,
          "tvlrProf": [
            {
              "type": "E"
            }
          ],
          "cType": "PK"
        },
        "jnyFltrL": [
          {
            "value": "1111111111",
            "mode": "BIT",
            "type": "PROD"
          },
          {
      -->   "value": "BERLKOENIG",
            "mode": "INC",
            "type": "GROUP"
          }
        ],
        "outDate": "20210409"
      }
    }
  ],
  "ext": "BVG.1",
  "formatted": true,
  "lang": "de",
  "ver": "1.24",
  "client": {
    "id": "BVG",
    "type": "IPH",
  }
}

However, enabling this option leads to a new JNY-type named "KISS", which is currently not handled and results in a parse error.

--> Revert this commit after KISS is handled: https://github.com/alexander-albers/tripkit/commit/b04f52c0b1cf1f2bae755cd6a2c7f9ca479a11e9

derhuerst commented 3 years ago

hafas-client implementation:

https://github.com/public-transport/hafas-client/blob/92fb29d6875de870302a21ae68131361b8446fce/p/bvg/index.js#L65-L93

alexander-albers commented 3 years ago

When enabling the Berlkönig flag, always getting a Berlkönig trip as the very first trip result is probably very annoying, as it is often times way slower than taking a regular train/bus. My new resolution is setting the following jnyFilterIncludes:

[
   ["value": "BERLKOENIG", "mode": "INC", "type": "GROUP"],
   ["value": "berlkoenig", "mode": "EXC", "type": "GISPROD"]
]

It might seem unnecessary to first enable the product and then disable it again right away, but this is also what the official BVG App does when disabling the product. The main advantage is that we still find all regular trips, like the trip mentioned above, while excluding Berlkönig products from the search results. Not including both flags would again lead to an error for the above mentioned trip.