Skip to content

A bus route visualisation for Porto Alegre's public transportation system

License

Notifications You must be signed in to change notification settings

rafaeelaudibert/POABus

Repository files navigation

🚍 POA Bus

Update Data Deploy

A bus route visualisation for Porto Alegre's public transportation system. You can access it on https://poabus.rafaaudibert.dev

⚙️ How

🏙️ Porto Alegre's Public Transportation API

We run a Github Action weekly, which fetches the data from Porto Alegre's public transportation API and generates the /data folder with both minified and human-readable files which will be used by our visualisation code to generate the routes and the stops of every available service in the city of Porto Alegre.

The API endpoints were found after poking around on the requests made by the poatransporte website. They are roughly as follows:

To understand it better, check out the script which fetches and parses the data.

After we collect this data, we automatically commit it to the repository.

🚫 Limitations

While developing this project, I was rate limited (by IP) because I requested the last mentioned endpoint too many times in a short period of time. I couldn't figure out the rate limit because the IP ban made the API hang and timeout instead of returning me a header (or an answer) with the reason why I was being rate limited. To solve this, I'm doing at most 5 requests per second, which seems to work just fine.

♻️ Data update

After the data is updated, we need to rebuild our code and send it to S3. This happens in another Github Action which listens for master pushes. It bundles the new JSON files onto the website, and updates the S3 bucket that is serving the requests.

💻 Code

The code is then pretty simple, courtesy of Lim Chee Aun's BusRouter SG project (credited below). We just use the data we generated showing it using MapBox and deck.gl.

🏃 Running locally

  • You will need Node 16 to run this. I suggest you installing nvm and running nvm install 16 and then using the nvm use command inside this repository to set it up.
  • Install the dependencies with npm install
  • Create a .env file based on the .env.example file with your MapBox API key.
  • Run it with npm start

👴 Credits

This is 95% based on the amazing BusRouter SG built by Lim Chee Aun with the data for Singapore's public transportation. I forked his visualisation work and just changed to parse the data from Porto Alegre's (awful) public transportation API.

🧙‍♂️ Author