Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New App: Traffic #343

Merged
merged 3 commits into from May 3, 2022
Merged

New App: Traffic #343

merged 3 commits into from May 3, 2022

Conversation

rgkimball
Copy link
Contributor

This PR revives the functionality of a previously high-usage app - @LukiLeu's live traffic. As you'll recall, the cost of serving Google's Maps API proved to be unsustainable and it was subsequently removed from the app library after receiving hundreds of installs. This alternative app provides a familiar display with two new sources of data, and users will need to bring their own API keys in order to keep license usage low.

  • MapQuest: provides real time directions for driving, cycling and walking, influenced by their traffic data
  • OpenRouteService: provides "ideal" travel times that do not reflect traffic for a broader array of travel modes: e-bikes, wheelchairs, freight and hiking.

Also, since I'm unable to test the location selection tool from my local Pixlet emulator, I would very much appreciate some extra scrutiny from the Tidbyt team to ensure everything works as expected!

Finally, given the sensitivity around this app and the history around its predecessor, I am happy to discuss or revise as you/the community see fit.

Key Features

image

Like the previous app, we use schema.Location to set an Origin and Destination with optional labels. If the user doesn't provide labels, we will reverse-query the coordinates to get the nearest address:

ezgif-2-db12d9624b

I found better performance with ORS than MapQuest for reverse address search from GPS coordinates, so although both are available and implemented, I default to ORS if the user has provided a key for both regardless of the transportation mode selected. Additionally, when the results come back I compare the elements of the label (street address, city, state, country) and only display values that differ. Notice the example above displays NY and CT but not USA.

The API employed by each transportation mode is noted in the selection so users know which key(s) they need to use the app:

image

One key enhancement over the previous app is relative-duration color-coding. MapQuest's API provides both a "real time" and an "ideal" travel time when querying for directions, allowing us to calculate how much longer the current travel prediction is than it would be in a vacuum. We use this information to display times in green/yellow/red based on how much longer your trip may take - this proves to be a great way to monitor peak commute times and helps Tidbyt owners decide to leave earlier/later to save time! (see above vs. below for heavy vs. moderate traffic)

We also are afforded a number of route configurations with MapQuest: we can tell the API that we prefer non-toll roads, or to avoid limited access roads like highways. These will all serve to make our trip duration more accurate if users know their commute well:

image

Since we don't receive traffic information from ORS, we'll simply display times for those transportation methods in white:

image

It's worth noting that this app is written to support the extension back to Google Maps if user demand justifies its inclusion, though with 15,000 monthly requests on the free MapQuest plan and having observed reasonable accuracy, I don't personally see the need to migrate!

The one major downside to MapQuest/ORS - no public transportation support! Though with the numerous train schedule apps on the platform already, I don't see this as a blocker to adoption.

API Key Acquisition

I included the registration URL in the description of the schema, though I'd love to hear if there is a better way to offer instructions to app users. In both cases it is easy (and free!) to register for API keys:

MapQuest Profile, Manage Keys

image

OpenRouteService Developer Dashboard

image

In my testing I never came close to my personal API limits:

MapQuest API Limits

15,000 direction requests per month (~500/day, or one request every 2.8 minutes). We cache directions for 5 minutes, so users can easily have two screens running 24 hours per day and won't see an error until the 26th day of the month on the free plan. This is something of a balancing act since we want the information to be timely, though I'd imagine most Tidbyt users wouldn't need this screen to be on 24 hours/day! Heavy users can always pay MapQuest for more credits or register multiple API keys if they need more data.

ORS API Limits

2,000 direction requests daily (we cache for 5 minutes, so feasibly a Tidbyt user could use this screen to show 6 different ORS routes), and 1,000 reverse geocode requests (we cache coordinate pairs for 24 hours - directions will run out long before these do, which is another good reason to prioritize ORS for reverse search when the user has supplied both keys).

Thanks for reading, happy to discuss and answer questions!

@LukiLeu
Copy link
Contributor

LukiLeu commented Apr 11, 2022

Oh wow. Looks really nice. I like the color-coding of the duration (Neat idea!) and the new colorful icons. Can't wait to try it out.

@maddox
Copy link
Contributor

maddox commented Apr 11, 2022

This is great! Was a Waze option considered?

I know that Home Assistant has a great component for drive times using Waze.

@rgkimball
Copy link
Contributor Author

This is great! Was a Waze option considered?

I didn't look at Waze specifically, but it certainly could be implemented! The code is written to be modular so it is amenable to new services.

Copy link
Contributor

@betterengineering betterengineering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks @rgkimball!

@betterengineering betterengineering merged commit ee0e1bd into tidbyt:main May 3, 2022
@rgkimball rgkimball deleted the traffic branch May 5, 2022 19:11
@tidbyt tidbyt locked as resolved and limited conversation to collaborators May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants