Detta inlägg är gammalt och kan innehålla inaktuell information.

Real time data

I was expecting to have the buses passing by a stop in the realtime information. Instead if I pass one of the stops numbers to the url, I get no result. And the example used at:
https://www.trafiklab.se/api/sl-realtidsinforma...
is not even a stop.
How do I get the actual arrivale to a given stop?

Kommentarer

  • Hi!
    Real time information is not included in GTFS extract.

    BR, Åke

    Team Trafiklab
  • Hi!

    I missunderstood Your question - You call the API:

    http://api.sl.se/api2/realtimedepartures.<FORMAT>?key=<DIN API NYCKEL>&siteid=<SITEID>&timewindow=<TIMEWINDOW>

    see documentation at
    https://www.trafiklab.se/api/sl-realtidsinforma...

    BR, Åke

    Team Trafiklab
  • Of course, I perused that information, otherwise I would not have known of the url. The point is that it mentions a siteid to be passed to the ur that appears nowhere in the GTFS static information, nor is explained in that documentation. Also that 9192 in the documentation comes totally out of the blue.

    My purpose is to send the identifier of a stop and get the list of buses getting there with waiting time, stops to run/or location of the bus and bus identifier.

    How do I do it?

  • Hello!

    You have two options to get SITE-ID for SL:

    1. Use the API SL Platsuppslag if You know the a portin of the stop name.
    2. Use the API SL Närliggande hållplatser if You know the coordinates of the stop.

    Then You can call theAPI SL Realtidsinformation 3.

    BR, Åke

    Team Trafiklab
  • My problem is that I do not know what to call. I managed to display the bus and metro stops all over Scandinavia, as you may also easily check if you download the free inArrivo HD iOS app. The sample in the Realtidsinformation 3 page all but mentions the stop id, but rather uses the sited. At any rate, by looking at the result of the sample url, that is not quite what I am looking for, as it gives information about a lot of stops, not just one.

    I try again: what url may I call to get the waiting times for a single stop? Please put some links or give some samples as it is not easy to find things in
    Swedish assisted by my poor knowledge of the language and google.

  • Ok, I found the former page you mentioned, but unfortunately I did not request that key when I created my account, as I thought the real time information was what I needed. How may I add it now?

  • Ok, I registered a new project adding the missing key too. Yet if executehttp://api.sl.se/api2/typeahead.json?key=<key>&searchstring=7469874
    corresponding to stop Åkerivägen.
    I receive a set of items of this kind:
    {"Name":"7460","SiteId":"7460","Type":"Station","X":"17609580","Y":"59245466"}
    what should I do with them, perhaps call the realtime api with the received sited and that the first of its results?

  • Hi Fabrizio!

    The GTFS extract stations id are national and are different than SL's local id's.
    You are trying to call SL's API with the national stop-id and not SL's local stop-id.

    I explained earlier hove to get SL's Site-id when You don't have the national stop id at hand, but the name of the station or nearby coordinates.
    Then You could use the API SL - Platsuppslag that find the site-Id given an input string.

    Example:
    http://api.sl.se/api2/typeahead.xml?key=<Your Key>&searchstring=gillstigen

    <ResponseOfListOfSite xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <StatusCode>0</StatusCode>
    <ExecutionTime>0</ExecutionTime>
    <ResponseData>
    <Site>
    <Name>Gillestigen (Södertälje)</Name>
    <SiteId>7524</SiteId>
    <Type>Station</Type>
    <X>17582711</X>
    <Y>59199657</Y>
    </Site>
    <Site>

    *Another way, to get SL stop id is to call the translation table available at Trafiklab. *

    In this tables is GTFS stop id is translated to the local operators Site-id in a CSV file. **For SL is the translation to stop-area so You have to take two steps to get the Site-id.

    The reason for this is that SL has many multiple stop-areas map to a site-id.**

    Documentation on this functionality is found at https://www.trafiklab.se/api/gtfs-sverige/dokum...

    Step 1:

    In Your case is the call to make (no key is needed) https://api.trafiklab.se/samtrafiken/gtfs/extra...

    The entry You are seaching for is:
    agency_id,stop_id,agency_stop_id
    275,7469874,75104

    Step 2:

    When You have the stop area do You need to make another call to get the SITE-ID for SL.

    • Get a key to API SL - Hållplatser och Linjer 2.

    • The API SL - Hållplatser och Linjer 2 returns a CSV–file with Stop_area id to Site-Id mapping.

    (note: You need to create a key for this API)
    <Site xmlns="http://api.sl.se/api/pws">
    <SiteId>7524</SiteId>
    <SiteName>Gillestigen</SiteName>
    <StopAreaNumber>75104</StopAreaNumber>
    <LastModifiedUtcDateTime>2012-03-26 23:55:32.900</LastModifiedUtcDateTime>
    <ExistsFromDate>2012-06-23 00:00:00.000</ExistsFromDate>
    </Site>

    Now You can call the SL Real time API (SL Realtidsinformation 3) with the Site-id.

    http://api.sl.se/api2/realtimedepartures.xml?key=<YOUR Key>&siteid=7524&timewindow=30
    <ResponseData>
    <LatestUpdate xmlns="http://sl.se/Departures.xsd">2015-08-24T15:25:00</LatestUpdate>
    <DataAge xmlns="http://sl.se/Departures.xsd">19</DataAge>
    <Metros xmlns="http://sl.se/Departures.xsd"/>
    <Buses xmlns="http://sl.se/Departures.xsd">
    <Bus>
    <TransportMode>BUS</TransportMode>
    <LineNumber>754</LineNumber>
    <Destination>Geneta (Scaniarinken)</Destination>
    <JourneyDirection>2</JourneyDirection>
    <SiteId>7524</SiteId>
    <StopAreaName>Gillestigen</StopAreaName>
    <StopAreaNumber>75104</StopAreaNumber>
    <StopPointNumber>75104</StopPointNumber>
    <TimeTabledDateTime>2015-08-24T15:27:41</TimeTabledDateTime>
    <ExpectedDateTime>2015-08-24T15:27:41</ExpectedDateTime>
    <DisplayTime>2 min</DisplayTime>
    </Bus>
    <Bus>

    BR, Åke

    Team Trafiklab
  • Very long post. I start from the beginning. I do not know if I have a national code, I imported everything coming from your tables. In particular I have numbers like: 7469859 for Åkerivägen: how do I get the national codes instead? assuming I may use them to straightly get the waiting times for the stop.

    I would prefer not to use the stop name as it could be ambiguous. As a matter of fact if I submitted the number I got a list of site-id, albeit with no hint whether they referred to the area where the submitted stop sits.

    I wonder where that agency_id,stop_id,agency_stop_id table pops up from. That is not in the GTFS files! So agencies are also linked to stops in addition to routes, good.
    May I save that table to my DB for a faster lookup or it changes too rapidly?

    Anyway, I think I may locate my entry in the table and so also get an agency_id and agency_stop_id. Let's go forward.

    Here is the first logical leap: how do I get the stop_area if I only have an agency_id and agency_stop_id?

    To save time: assuming I get the stop_area, I think I may get a single site_id, hopefully not 10 of them like the last time I tried!

    Then it should be done, with the exception of the approaching bus identifier I need to handle the relative annotations on the map I am afraid is not returned by the realtime departures api. How do I get them? I assume the LineNumber is the bus number. Do you confirm the StopAreaNumber is the location where the bus is passing by?

    Summarizing:
    I think I am just at a loss for getting from agency_id and agency_stop_id to a stop_area. And to get the bus identifiers.

  • Hi Fabrizio!

    A stop-id that start with 74 is a national stop-ids. This ID is used by Resrobot a national travel planner.

    I explained in my l previous comment what You need to do to get the Site Id for SL.
    Just follow the description. If You don't, then I cant help You forward.

    It's adviced to save the Site Id locally for faster lookups and fewer API calls.

    BR, Åke

    Team Trafiklab
  • The problem is that to get the site-id, it appears I need the stop_area, but I have no cue about how to get it.

  • As a a matter of fact most of my bus stops start with 74 with the exception of Copenhagen Airport having number 8600858.

    Conversely metro stops begin with other numbers, usually, often with 86.

    Given I have loaded the information from your GTFS files without any creativity on my part, if there are no national codes in my DB, there are also no national codes in your GTFS text files.

    At any rate, how do I get forward from here? In Rome I just need to pass the stop number to have the waiting times for the stop, it is ok to do some more job to have the same thing in Scandinavia, but I wish there were a clear procedure for doing it.

  • Hi Fabrizio, SL and the other local agencies is a bit tricky to work with because they have their own ids. You could instead use the APIs for resrobot which uses the national ids same as you can find in the GTFS extracts. If you want to call SLs API you need to make the translation between the ids yourself using the tools provided above. I've written this python script to make it a bit easier to convert between SL and GTFS, it might help, https://github.com/johannilsson/sl2gtfs

  • Sorry but I got a bit discomforted on this issue and so I need to start from the beginning. At present I have the files downloaded from Trafiklab loaded on my sql server with just a little tweaking I shall need to cope with later. In particular both trips and 'stripes' are a multiple of the actual passing lines and crossing between lines and stops. So I discarded all duplicates for trips with a certain destination and all attached stripes. Of course in this way I created holes like those of the Swiss cheese, but I found no better way. Is there some 'official' way to have a single line independently of how many buses thread it?

    At any rate I have a very partial subset of the actual lines, but all the stops. In those I have numbers like 7469859 for Åkerivägen. I need a way to get the waiting times for such codes. I think you consider those the GTFS data. So I think I need a tool to convert my codes into ones that may be passed to a trafiklab url (which one?) to get the timetables.

  • Anyway the verb "want" should be substituted with "desperately seek" :-)

  • Different APIs have different IDs so it's hard to know which ones you refer to here.

    If you use the GTFS extract you cannot use those IDs with e.g. SL. They need to be converted into SL Site IDs, you can use the tool I linked above for that. When using the raw files from SL lines and stops you just need make sure you use the Site ID when talking to one of SLs APIs. If you just keep the IDs separated and treat each APIs independent from each other with some ID conversions in between it's "fairly" straight forward 😀

  • Hi Johan and Fabrizio!

    Johan - Thank You for helping Fabrizio with Your expertize knowledge.
    It's for us very difficult to give prograrmming advices as we are not experience with developing solutions as You are.

    Best regards ,Åke

    Team Trafiklab
  • Hi Johan, thanks for your answer, perhaps by now it should be paramount clear I am not attached to any state of things. I need to show annotations on the map upon clicking which to poll the waiting times for the stop and display them to the user. Of course the two codes must be matching, otherwise I would poll the waiting times of another stop or of an unexisting one. What to put in the stop or to use for polling the stop is indifferent, as long as they match.

    If I understand you fine, I may apply your script to the codes I downloaded from the GTFS repository to get a value I may submit to the SL3 url for the realtime information, or did I misunderstood you?

    On passing, I really ignore why they do not use the same codes everywhere themselves, as for example it is done in Rome. We are not yet there, but the route calculation seems to use yet another collection of unmatching codes...

  • Hi Åke, thanks to you. Yet no programming experience would be needed if things were straightforward. I invite you to check the way the Agency for the Mobility of Rome handles similar information; it is in Italian, but your should have no problems in translating it by google. There are even python examples about how to use their apis!

    http://www.agenziamobilita.roma.it/it/progetti/...

  • At any rate, the new version of the app with the stub support for Sweden was approved. In order to know better the situation, you may freely download it at:
    http://www.inarrivo.net/iosApp.html

  • It's different APIs and they're really not built to be compatible with each as you discovered. The SL APIs is meant to be used with the rest of SLs API that they provide e.g. their journey planner, search etc.

    Those of us that combines multiple APIs need to workaround these problems and create our own glue in between. The recent mapping file that Trafiklab provides with the GTFS feed is of great help here, before we relied to handcrafted mapping files, so things has got a lot better. The tool I linked can do this for you and is used in production for exactly that purpose.

    Why they're different is probably because they're built and maintained by different organisations. I'm guessing they're here on Trafiklab to make it easier for us developers to manage API keys and docs in one place instead of having it spread out to different places. Some agencies also publish their APIs through their own channels.

  • Given I am a poor Italian whose ancestors made square buildings, while nordic people had round ones and so I am little accustomed to nordic twisted minds, I posted an offer on people per hour by which anyone among you or other guests to the forum could answer. It is detailed at:
    https://www.peopleperhour.com/job/view?id=885178
    That is euro 100 for a job anyone with the proper mind conditions could do in half an hour.

  • Many thanks a whole lot for sharing!

Kommentera eller skriv ett nytt inlägg

Ditt namn och inlägg kan ses av alla. Din e-post visas aldrig publikt.