newbie

28 views
Skip to first unread message

Drew Baden

unread,
Jul 7, 2024, 5:34:07 PM7/7/24
to onebusaway-developers
Greetings.   I'm a newbie trying to learn to make an iPhone App to display bus data, using the OneBusAway API.

I first load the routes for my agency (Seattle) using the URL:

https://api.pugetsound.onebusaway.org/api/where/routes-for-agency/1.json?key=


Works fine.   Then I click on a route and load the data for that route using:


https://api.pugetsound.onebusaway.org/api/where/schedule-for-route/<routeId>.json?key=


Works fine as well.   I can dig out all of the stops and static arrival and departure times for stops along a particular direction.


Then, I take a particular stop id and load real-time data using:


https://api.pugetsound.onebusaway.org/api/where/arrivals-and-departures-for-stop/<stop_id>.json?key=


That also works fine.  From the documentation:


https://developer.onebusaway.org/api/where/methods/arrivals-and-departures-for-stop


it says that I can get the real-time info for the route, and in particular the scheduledArrivalTime and scheduledDepartureTime in ms since unix epoch.


My question is this:  when I compare the scheduledArrivalTime (scheduledDepartureTime is usually the same value) to what I get when I load the route, I get different answers.  The times are not the same.  Sometimes they are off by 10 minutes, which is curious.


I guess what my question really is is this: from those who've done something similar already (in javascript or Swift), what's the best method for doing this?


Thanks!  Sorry if this is a dumb question that has been answered before.


Drew

Aaron Brethorst

unread,
Jul 7, 2024, 5:45:51 PM7/7/24
to onebusaway-developers
Hey Drew - Not that I doubt your findings, but I can't say that I've noticed this discrepancy before. Can you give me an example of two API calls I can compare to see this first-hand?

Also, out of curiosity, is there any reason you're building all of this lower-level API functionality from scratch? You should be able to reuse the OBAKitCore framework from https://github.com/onebusaway/onebusaway-ios, which includes both a well tested networking stack and models. I'm happy to help you get it incorporated into your app if that ends up being a challenge. (I haven't gotten around to turning it into a Swift Package yet, unfortunately.)

cheers,
Aaron 

Baden Drew

unread,
Jul 8, 2024, 1:16:03 AM7/8/24
to onebusaway...@googlegroups.com
Thanks, but now I have another problem that precludes me from solving the first one!

When I issue this command:


I get a json object that I decode, and I look at the arrivalsAndDepartures section.   It contains 2 blocks, both have numberOfStopsAway = 9, both have predicted = false, consistent with both having 0 for predictedDeparture/ArrivalTime.  And both have the closest stop at id 1_18085, which is the first stop on the 44 bus route incoming.

Here’s the json object, for what it's worth.

Also, under data there’s “entry” and “references”, but I don’t see any documentation on “references” when I look here:


Thanks for your help!!!
   Drew

PS.  Yes, I’m not using OBAKitCore because I am a newbie iOS app developer and haven’t gotten to the point where I can plug such a thing in, so I decided to see if I can understand things from the documentation itself as a starter.  But I will look into it.

{

  "code" : 200,

  "data" : {

    "entry" : {

      "arrivalsAndDepartures" : [

        {

          "numberOfStopsAway" : 9,

          "predictedDepartureInterval" : null,

          "lastUpdateTime" : 0,

          "predictedDepartureTime" : 0,

          "routeShortName" : "44",

          "scheduledDepartureTime" : 1720415314000,

          "situationIds" : [


          ],

          "predictedOccupancy" : "",

          "serviceDate" : 1720335600000,

          "predictedArrivalTime" : 0,

          "vehicleId" : "",

          "frequency" : null,

          "tripStatus" : {

            "occupancyCapacity" : -1,

            "occupancyCount" : -1,

            "position" : {

              "lat" : 47.667934000654007,

              "lon" : -122.398323

            },

            "lastKnownOrientation" : 0,

            "status" : "default",

            "lastKnownDistanceAlongTrip" : 0,

            "nextStopTimeOffset" : 3,

            "occupancyStatus" : "",

            "closestStop" : "1_18085",

            "totalDistanceAlongTrip" : 8720.2389357926986,

            "vehicleId" : "",

            "closestStopTimeOffset" : 3,

            "lastUpdateTime" : 0,

            "phase" : "",

            "nextStop" : "1_18085",

            "predicted" : false,

            "scheduleDeviation" : 0,

            "scheduledDistanceAlongTrip" : 8720.2388630707283,

            "vehicleFeatures" : [


            ],

            "orientation" : 270,

            "lastLocationUpdateTime" : 0,

            "blockTripSequence" : 3,

            "activeTripId" : "1_629475226",

            "frequency" : null,

            "serviceDate" : 1720335600000,

            "distanceAlongTrip" : 0,

            "situationIds" : [


            ]

          },

          "scheduledArrivalInterval" : null,

          "arrivalEnabled" : true,

          "tripId" : "1_562591026",

          "blockTripSequence" : 4,

          "routeLongName" : "",

          "historicalOccupancy" : "",

          "scheduledArrivalTime" : 1720415314000,

          "status" : "default",

          "scheduledTrack" : "",

          "occupancyStatus" : "",

          "actualTrack" : "",

          "stopSequence" : 9,

          "tripHeadsign" : "University Of Washington Medical Center Wallingford",

          "predicted" : false,

          "scheduledDepartureInterval" : null,

          "stopId" : "1_75407",

          "distanceFromStop" : 2979.4030910503388,

          "departureEnabled" : true,

          "predictedArrivalInterval" : null,

          "routeId" : "1_100224",

          "totalStopsInTrip" : 27

        },

        {

          "numberOfStopsAway" : 9,

          "predictedDepartureInterval" : null,

          "lastUpdateTime" : 0,

          "predictedDepartureTime" : 0,

          "routeShortName" : "44",

          "scheduledDepartureTime" : 1720416454000,

          "situationIds" : [


          ],

          "predictedOccupancy" : "",

          "serviceDate" : 1720335600000,

          "predictedArrivalTime" : 0,

          "vehicleId" : "",

          "frequency" : null,

          "tripStatus" : {

            "occupancyCapacity" : -1,

            "occupancyCount" : -1,

            "position" : {

              "lat" : 47.667934252168607,

              "lon" : -122.398323

            },

            "lastKnownOrientation" : 0,

            "status" : "default",

            "lastKnownDistanceAlongTrip" : 0,

            "nextStopTimeOffset" : 1203,

            "occupancyStatus" : "",

            "closestStop" : "1_18085",

            "totalDistanceAlongTrip" : 8720.2389357926986,

            "vehicleId" : "",

            "closestStopTimeOffset" : -357,

            "lastUpdateTime" : 0,

            "phase" : "",

            "nextStop" : "1_18085",

            "predicted" : false,

            "scheduleDeviation" : 0,

            "scheduledDistanceAlongTrip" : 8720.2108958796307,

            "vehicleFeatures" : [


            ],

            "orientation" : 270,

            "lastLocationUpdateTime" : 0,

            "blockTripSequence" : 11,

            "activeTripId" : "1_562590346",

            "frequency" : null,

            "serviceDate" : 1720335600000,

            "distanceAlongTrip" : 0,

            "situationIds" : [


            ]

          },

          "scheduledArrivalInterval" : null,

          "arrivalEnabled" : true,

          "tripId" : "1_562591186",

          "blockTripSequence" : 12,

          "routeLongName" : "",

          "historicalOccupancy" : "",

          "scheduledArrivalTime" : 1720416454000,

          "status" : "default",

          "scheduledTrack" : "",

          "occupancyStatus" : "",

          "actualTrack" : "",

          "stopSequence" : 9,

          "tripHeadsign" : "University Of Washington Medical Center Wallingford",

          "predicted" : false,

          "scheduledDepartureInterval" : null,

          "stopId" : "1_75407",

          "distanceFromStop" : 2979.4310582414473,

          "departureEnabled" : true,

          "predictedArrivalInterval" : null,

          "routeId" : "1_100224",

          "totalStopsInTrip" : 27

        }

      ],

      "nearbyStopIds" : [

        "1_29640"

      ],

      "stopId" : "1_75407",

      "situationIds" : [


      ]

    },

    "references" : {

      "stops" : [

        {

          "parent" : "",

          "id" : "1_75407",

          "code" : "75407",

          "locationType" : 0,

          "lon" : -122.361046,

          "routeIds" : [

            "1_100224"

          ],

          "staticRouteIds" : [

            "1_100224"

          ],

          "direction" : "SE",

          "lat" : 47.667099,

          "name" : "NW Market St & 3rd Ave NW",

          "wheelchairBoarding" : "ACCESSIBLE"

        },

        {

          "parent" : "",

          "id" : "1_18085",

          "code" : "18085",

          "locationType" : 0,

          "lon" : -122.398415,

          "routeIds" : [

            "1_100224"

          ],

          "staticRouteIds" : [

            "1_100224"

          ],

          "direction" : "S",

          "lat" : 47.667934000000002,

          "name" : "32nd Ave NW & NW Market St",

          "wheelchairBoarding" : "ACCESSIBLE"

        },

        {

          "parent" : "",

          "id" : "1_29640",

          "code" : "29640",

          "locationType" : 0,

          "lon" : -122.361328,

          "routeIds" : [

            "1_100224"

          ],

          "staticRouteIds" : [

            "1_100224"

          ],

          "direction" : "NW",

          "lat" : 47.667763000000001,

          "name" : "NW Market St & 3rd Ave NW",

          "wheelchairBoarding" : "ACCESSIBLE"

        }

      ],

      "trips" : [

        {

          "routeId" : "1_100224",

          "blockId" : "1_7253369",

          "timeZone" : "",

          "id" : "1_562591026",

          "tripShortName" : "",

          "serviceId" : "1_11248",

          "shapeId" : "1_20044006",

          "directionId" : "1",

          "peakOffpeak" : 0,

          "routeShortName" : "",

          "tripHeadsign" : "University Of Washington Medical Center Wallingford"

        },

        {

          "routeId" : "1_100224",

          "blockId" : "1_7253369",

          "timeZone" : "",

          "id" : "1_629475226",

          "tripShortName" : "",

          "serviceId" : "1_11248",

          "shapeId" : "1_11044004",

          "directionId" : "0",

          "peakOffpeak" : 0,

          "routeShortName" : "",

          "tripHeadsign" : "Ballard Wallingford"

        },

        {

          "routeId" : "1_100224",

          "blockId" : "1_7253368",

          "timeZone" : "",

          "id" : "1_562591186",

          "tripShortName" : "",

          "serviceId" : "1_11248",

          "shapeId" : "1_20044006",

          "directionId" : "1",

          "peakOffpeak" : 0,

          "routeShortName" : "",

          "tripHeadsign" : "University Of Washington Medical Center Wallingford"

        },

        {

          "routeId" : "1_100224",

          "blockId" : "1_7253368",

          "timeZone" : "",

          "id" : "1_562590346",

          "tripShortName" : "",

          "serviceId" : "1_11248",

          "shapeId" : "1_11044004",

          "directionId" : "0",

          "peakOffpeak" : 0,

          "routeShortName" : "",

          "tripHeadsign" : "Ballard Wallingford"

        }

      ],

      "situations" : [


      ],

      "stopTimes" : [


      ],

      "routes" : [

        {

          "url" : "https:\/\/kingcounty.gov\/en\/dept\/metro\/routes-and-service\/schedules-and-maps\/044.html",

          "agencyId" : "1",

          "color" : "",

          "id" : "1_100224",

          "longName" : "",

          "shortName" : "44",

          "description" : "Ballard - Montlake",

          "nullSafeShortName" : "44",

          "textColor" : "",

          "type" : 3

        }

      ],

      "agencies" : [

        {

          "phone" : "206-553-3000",

          "url" : "https:\/\/kingcounty.gov\/en\/dept\/metro",

          "lang" : "EN",

          "id" : "1",

          "disclaimer" : "",

          "timezone" : "America\/Los_Angeles",

          "email" : "",

          "fareUrl" : "https:\/\/kingcounty.gov\/en\/dept\/metro\/fares-and-payment\/prices",

          "name" : "Metro Transit",

          "privateService" : false

        }

      ]

    }

  },

  "text" : "OK",

  "version" : 2,

  "currentTime" : 1720414797520

}


--
You received this message because you are subscribed to the Google Groups "onebusaway-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onebusaway-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/onebusaway-developers/bda49390-46ab-45d6-b3b2-d8d460fea326n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages