Code Monkey home page Code Monkey logo

path-data's Introduction

PATH Data API Build Code Coverage

This repository contains the contract and server-side implementation of an API that exposes data about the Port Authority Trans-Hudson Rapid Transit System.

This software is not endorsed nor supported by the Port Authority of New York and New Jersey.

Using This Software

Prefer to use the publically exposed API (below) rather than running this software yourself. See this article for more information.

Public APIs

The APIs provided by this service can be found at:

List Stations

HTTP: https://path.api.razza.dev/v1/stations

{
  "stations": [
    {
      "station": "NEWARK",
      "id": "26733",
      "name": "Newark",
      "coordinates": {
        "latitude": 40.73454,
        "longitude": -74.16375
      },
      "platforms": [
        // ...
      ],
      "entrances": [
        // ...
      ],
      "timezone": "America/New_York"
    },
    // ...
  ]
}

Get Station

HTTP: https://path.api.razza.dev/v1/stations/{station_name} where {station_name} is one of:

newark
harrison
journal_square
grove_street
exchange_place
world_trade_center
newport
hoboken
christopher_street
ninth_street
fourteenth_street
twenty_third_street
thirty_third_street

HTTP: https://path.api.razza.dev/v1/stations/harrison

{
  "station": "HARRISON",
  "id": "26729",
  "name": "Harrison",
  "coordinates": {
    "latitude": 40.73942,
    "longitude": -74.15587
  },
  "platforms": [
    {
      "id": "781720",
      "name": "Harrison",
      "coordinates": {
        "latitude": 40.73942,
        "longitude": -74.15587
      }
    },
    {
      "id": "781721",
      "name": "Harrison",
      "coordinates": {
        "latitude": 40.73942,
        "longitude": -74.15587
      }
    }
  ],
  "entrances": [
    {
      "id": "782492",
      "name": "Harrison",
      "coordinates": {
        "latitude": 40.739,
        "longitude": -74.1558
      }
    },
    {
      "id": "782493",
      "name": "Harrison",
      "coordinates": {
        "latitude": 40.7395,
        "longitude": -74.1559
      }
    }
  ],
  "timezone": "America/New_York"
}

Realtime Arrivals

HTTP: https://path.api.razza.dev/v1/stations/<station_name>/realtime

{
  "upcomingTrains": [
    {
      "lineColors": [
        "#65C100"
      ],
      "projectedArrival": "2019-04-13T01:56:00Z",
      "lastUpdated": "2019-04-13T01:52:05Z",
      "status": "ON_TIME",
      "headsign": "Hoboken",
      "route": "HOB_WTC",
      "routeDisplayName": "World Trade Center - Hoboken",
      "direction": "TO_NJ"
    },
    {
      "lineColors": [
        "#65C100"
      ],
      "projectedArrival": "2019-04-13T02:11:00Z",
      "lastUpdated": "2019-04-13T01:52:05Z",
      "status": "ON_TIME",
      "headsign": "Hoboken",
      "route": "HOB_WTC",
      "routeDisplayName": "World Trade Center - Hoboken",
      "direction": "TO_NJ"
    },
    {
      "lineColors": [
        "#D93A30"
      ],
      "projectedArrival": "2019-04-13T02:01:00Z",
      "lastUpdated": "2019-04-13T01:52:05Z",
      "status": "ON_TIME",
      "headsign": "Newark",
      "route": "NWK_WTC",
      "routeDisplayName": "World Trade Center - Newark",
      "direction": "TO_NJ"
    },
    {
      "lineColors": [
        "#D93A30"
      ],
      "projectedArrival": "2019-04-13T02:16:00Z",
      "lastUpdated": "2019-04-13T01:52:05Z",
      "status": "ON_TIME",
      "headsign": "Newark",
      "route": "NWK_WTC",
      "routeDisplayName": "World Trade Center - Newark",
      "direction": "TO_NJ"
    }
  ]
}

List Routes

HTTP: https://path.api.razza.dev/v1/routes/

{
  "routes": [
    {
      "route": "JSQ_33_HOB",
      "id": "1024",
      "name": "Journal Square - 33rd Street (via Hoboken)",
      "color": "ff9900",
      "lines": [
        {
          "displayName": "33rd Street (via Hoboken) - Journal Square",
          "headsign": "Journal Square via Hoboken",
          "direction": "TO_NJ"
        },
        {
          "displayName": "Journal Square - 33rd Street (via Hoboken)",
          "headsign": "33rd via Hoboken",
          "direction": "TO_NY"
        }
      ]
    },
    // ...
  ]
}

Get Route

HTTP: https://path.api.razza.dev/v1/routes/NWK_WTC

{
  "route": "NWK_WTC",
  "id": "862",
  "name": "Newark - World Trade Center",
  "color": "d93a30",
  "lines": [
    {
      "displayName": "World Trade Center - Newark",
      "headsign": "Newark",
      "direction": "TO_NJ"
    },
    {
      "displayName": "Newark - World Trade Center",
      "headsign": "World Trade Center",
      "direction": "TO_NY"
    }
  ]
}

Demo

You can query the API via your web browser by navigating to a valid endpoint. For example the 9th street station realtime data.

A simple web app using the realtime arrival data can be found here.

Versioning

New fields and features will continue to be added to v1 of the API. No fields will be removed and no breaking changes will be made to v1. Any breaking changes will result in a version number increment and the previous API version will run along side the new version for at least 30 days. There are a number of external consumers of this API including Transit and Citymapper.

Other sources

Project to convert this data into GTFS Realtime format: https://github.com/jamespfennell/path-train-gtfs-realtime

path-data's People

Contributors

dependabot[bot] avatar kerrickstaley avatar mrazza avatar wgraham17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

path-data's Issues

API not working since this morning 9:30 am

I have some automations that run on node-red that uses this api to get train timings, that get activated only when i commute, after the long weekend this morning 9:30 am on my way to work i did not get the notifications and looking at it now 12:50pm i see the api does not run.

Anyone knows whats happening?

Server downtime

image
Not sure if you are aware or not, but the API has been down for a few days now.

This is what your status page shows, not sure if a code issue or an operational one.

https://jsfiddle.net/a6Ls5w8b/9/

Here are some unrelated improvements I made to your jsfiddle example from the reddit post in case you are interested. Shows train direction, line color etc in the view.

NullReferenceException when checking for PATH DB updates

System.NullReferenceException: Object reference not set to an instance of an object. at PathApi.Server.PathServices.PathApiClient.CheckForDbUpdate(String checksum) in /home/mrazza/sources/path-data/server/PathServices/PathApiClient.cs:line 93 at PathApi.Server.PathServices.PathApiClient.GetLatestChecksum(String startingChecksum) in /home/mrazza/sources/path-data/server/PathServices/PathApiClient.cs:line 36 at PathApi.Server.PathServices.PathSqlDbRepository.OnStartup() in /home/mrazza/sources/path-data/server/PathServices/PathSqlDbRepository.cs:line 72 at PathApi.Server.StartupTaskExecutor.ExecuteTasks() in /home/mrazza/sources/path-data/server/StartupTaskExecutor.cs:line 39

var stringResponse = await httpResponse.Content.ReadAsStringAsync();

API error rate is high for realtime endpoint

The API's /realtime endpoint frequently returns a 503 response when queried. Over the past week, the site has returned a 503 response about 24% of the time. This number comes from some VictoriaMetrics + Prometheus monitoring I set up that periodically queries the Hoboken realtime endpoint at https://path.api.razza.dev/v1/stations/hoboken/realtime.

Here's a graph of the response code over time:
Screenshot 2024-01-15 at 11 29 14 PM

Not trying to complain here, just stating the way things are. I realize that running this service is probably expensive and PATH doesn't go out of their way to make it easier for you! I'm happy to help out with funding or running the service since I use it every day.

Recent data abnormalities

This is a followup to #20. I've done some more research recently, and intermittently the data from this API is either completely missing or incomplete. The PANYNJ's realtime schedules (https://www.panynj.gov/path/en/index.html) do not show any problems during these times. I've attached an image and video (showing data quickly pop in and out) below showing the issue on the demo website.

If there's any further details I can provide, please let me know.

CleanShot.2023-12-18.at.17.09.26.mp4

CleanShot 2023-12-18 at 16 59 51@2x

[RFC] Adding alerts for the PATH train

It seems there is now a relatively easy (albeit slow) way to query active alerts from the PATH's official website: https://www.panynj.gov/bin/portauthority/everbridge/incidents?status=All&department=Path. I would like to get PATH service alerts integrated into the PATH GTFS realtime project, and figured it may make sense to add it here first and then consume the new API from the GTFS project, since it already uses this for realtime trip data.

I am curious what your thoughts on the above are and if you're open to the idea - thanks in advance for your time/feedback!

EDIT: Adding a reference to the parallel RFC Issue in the GTFS project: jamespfennell/path-train-gtfs-realtime#2

New API consumer

I wanted to let you know about a new consumer of your API, and couldn't find another way to contact you!

This week I deployed a project that reads your API and outputs a public feed in the GTFS Realtime format. I'm hitting your API every 5 seconds which I hope is okay. More information is on the project repo: https://github.com/jamespfennell/path-train-gtfs-realtime

The motivation is to enable applications that already work with GTFS "natively" to use the data without any app-specific logic. So, for example, the backend of my web app which previously just had NYC Subway data now has PATH data with no customization required more or less: https://www.realtimerail.nyc/transiter/v0.4/systems

Thanks for the API, it's really great to be able to get this data.

Startup failure: failure to load database

Investigation required.

2021-06-11 04:28:21.968 +00:00 [Information] (/StartupTaskExecutor.ExecuteTasks:38) Executing startup tasks...
2021-06-11 04:28:21.991 +00:00 [Information] (/PathSqlDbRepository.OnStartup:69) Preparing PATH SQL repository...
2021-06-11 04:28:22.639 +00:00 [Information] (/PathApiClient.GetLatestChecksum:44) PATH DB checksum updated to "CE78A735F3DCF2CCB49E546CF40F9E29".
Unhandled Exception: System.AggregateException: One or more errors occurred. (Invalid response from PATH API when downloading DB update: NotFound) ---> System.Net.Http.HttpRequestException: Invalid response from PATH API when downloading DB update: NotFound
   at PathApi.Server.PathServices.PathApiClient.GetDatabaseAsStream(String checksum) in /home/mrazza/sources/path-data/server/PathServices/PathApiClient.cs:line 66
   at PathApi.Server.PathServices.PathSqlDbRepository.DownloadDatabase() in /home/mrazza/sources/path-data/server/PathServices/PathSqlDbRepository.cs:line 299
   at PathApi.Server.PathServices.PathSqlDbRepository.OnStartup() in /home/mrazza/sources/path-data/server/PathServices/PathSqlDbRepository.cs:line 73
   at PathApi.Server.StartupTaskExecutor.ExecuteTasks() in /home/mrazza/sources/path-data/server/StartupTaskExecutor.cs:line 39
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at PathApi.Server.Program.Main(String[] args) in /home/mrazza/sources/path-data/server/Program.cs:line 41

Incorrect mapping of "33rd Street" line to `JSQ_33_HOB` route

This API is returning the incorrect route for the "33rd Street" line. Below is an example response from the demo site where the line name is "33rd Street" but the route is JSQ_33_HOB. I've also included a screenshot from the official PATH website during the same time, which confirms the expected route is "33rd Street" without stopping at Hoboken.

I noticed this when using the downstream path-train-gtfs-realtime API. I am working on a patch to handle this case within that project for now. Please let me know if there's any further details I can provide, and thanks for your work on this project!

{
 "upcomingTrains": [
  {
   "lineName": "33rd Street",
   "headsign": "33rd Street",
   "route": "JSQ_33_HOB",
   "routeDisplayName": "Journal Square - 33rd Street (via Hoboken)",
   "direction": "TO_NY",
   "lineColors": [
    "#FF9900"
   ],
   "status": "ON_TIME",
   "projectedArrival": "2023-12-27T00:09:21Z",
   "lastUpdated": "2023-12-27T00:01:24Z"
  },
 ]
}

CleanShot 2023-12-26 at 19 03 50@2x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.