Friday, October 10, 2014

KC Traffic Out Scouting the Scout

We have a video camera, roadway sensor, digital sign, traffic management system installed in Kansas City called KC Scout. The KC Scout provides realtime traffic data across the metro. The service has a web site and is pretty handy for checking in on traffic around the metro.

Using the stripped down KC Scout mobile web site I found a way to grab all the data from the speed detectors around the metro. Using this data I was able to build a custom system that would notify me if traffic on my route to and from work was delayed. Here is how it all went down.

Python Script
First I wrote a python script to scrape the mobile web site to get the speed detector data.


This script will grab all the detector data and insert it into a database. I wanted to store data over time so I can run some trending analysis at a later date. So we store speed data captured every 5 minutes. The python script is executed as part of a Scheduled Task.

SQL Table Structure
I created 3 tables to support the data collected and to display the results.


  • data - stores the speeds from the detectors
  • routes - stored the route id and the route name
  • routes_location - stored locations, sort orders, and route numbers for each location in a route


This allows me to add custom routes for the various commute options around the metro.

SQL Stored Procedure
Once I had a steady flow of data I created the following Stored Procedure to display the data.



This procedure allows me to pass a Zone ID and the number of Minutes I want to use to calculate the average speed for a specific location. I added a sort column to the kctraffic_data_routes_location table so I could put the locations in the correct order along the specified route.

Webpage
I then created a front-end to display the data. I didn't spend a lot of time on the front-end because to me the bigger value is in the email notification. I did use the Foundation Framework in attempt to make it look good on a mobile device. I tested it with my Galaxy S3 and it looks decent. I may need to tweak the size of the fonts and such to make it fit better but for now its good.




Notification System
I am still working on this. I created a scheduled task to query the locations on my route to see if any location was running slower than normal. If certain thresholds are met then i will email myself a traffic alert a few minutes before leaving from home or work. The email contains a link to the web page detailed above so you can get a quick view of the problem areas along your route and plan accordingly.

I am sure most, if not all, this functionality is available through the Scout website...but what fun is that really.

2 comments:

  1. that is bad ass. next, break out your dijkstra and have it tell you the shortest route to the office.

    or better yet, set up a self-driving car and let it do all that for you. =~)

    or, you know, work from home.

    ReplyDelete