OpendataCH / Transport

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

Add list of available transportation types for each station #196

Closed Bcow7 closed 5 years ago

Bcow7 commented 5 years ago

Hi @fabian,

I noticed that stations returned by search.ch API (/completion) have specific type and if you choose the wrong station ID some connections will be not displayed in StationBoard.

As you can see in the following example, sometimes similar names don't return same type of transportation.

image image (gare means Bahnhof)

In this example Vevey, gare will return only bus connections. image

To improve your very useful API, I added a field _transportationtypes in /locations response.

e.g /v1/locations?query=Vevey

{
  "stations": [
    {
      "id": "8501200",
      "name": "Vevey",
      "score": null,
      "coordinate": {
        "type": "WGS84",
        "x": 46.463002,
        "y": 6.84343
      },
      "distance": null,
      "transportation_types": [
        "train"
      ]
    },
    {
      "id": "8579174",
      "name": "Vevey, gare",
      "score": null,
      "coordinate": {
        "type": "WGS84",
        "x": 46.462672,
        "y": 6.842327
      },
      "distance": null,
      "transportation_types": [
        "bus"
      ]
    },

   ...

  ]
}

What do you think about that modification? I think it could be useful for other users...

Regards, Florent

fabian commented 5 years ago

@Bcow7 Nice! I like the idea of making the iconclass available!

However I'm a bit concerned transportation_types on the station could be interpreted wrongly:

As it's an array a user of the Transport API might think all available transportation types of that station will be returned. But as it's based on the iconclass from search.ch, only the main transportation type is returned.

How about using an attribute icon on the station instead? This make it clear it's just for display and should not be used in any kind of transportation type filtering logic.

The mapping from sl-icon-type- to a simpler value makes sense.

Bcow7 commented 5 years ago

Hello @fabian!

I like the idea, so I committed the modifications you suggested!

By the way could you tell me how you handle so many requests because I saw that search.ch has a daily limit. Did you subscribe to any fee-based offer?

fabian commented 5 years ago

@Bcow7 Awesome, thanks! Merged and live now.

We have an agreement with search.ch to forward the client IP address, so the same daily limit also applies to transport.opendata.ch, but for each individual IP address: https://opendata.ch/2017/06/search-ch-rettet-transport-opendata-ch/