louiedog98/nycturnstiles — pull request #2 by nealrs (2013-06-29 21:22:28+00:00)
Title: MTA datafile to traffic chart in 4 easy steps!

Based on @louiedog98's original turnstile script, I created three new scripts and a spreadsheet template, which enable you to transform a raw data file into a chart illustrating turnstile traffic at any MTA station. Obviously this can use some refactoring so it's a single script (and an interface for that matter), but this is a useable option for anyone familiar with the console.

Run regularize.rb on a raw turnstile file (e.g turnstile_130209.txt) to remove the 8x multiplexing and eliminate any non-'REGULAR' audit events.

Run one_station.rb on the resulting file (reg_turnstile_130209.txt) & input the desired station / remoteUnit code (e.g R021 for Bryant Park. This will write out the station specific turnstile data. This takes a little while because it's looping over everything, so be patient. The script prints 'Dunzo' to the console once it's complete.

Run compile_station.rb on the resulting file (R021_reg_turnstile_130209.txt) to setup the charting data. The script first establishes a unique, sorted, set of datetime codes - and then it strips out any irregular audit times (e.g 4:15:00) so that it always represents 4 hour intervals. Next, it loops through the one_station data and sums entries & exits (across all scp codes) for each datetime. And of course, it writes out everything to a new file.

Finally, it's chart time. Follow the instructions in plot_template.xlsx and paste in the chart data (sum_R021_reg_turnstile120209.txt) to plot the data as shown below.

Note: Because I'm only using REGULAR, on-hour audit events, there are a few issues with the resulting data (notice how there is some data missing on Thursday?) - but I'm working on it!

![r021_13_02_09_plot](https://f.cloud.github.com/assets/1568188/726495/59e635c4-e100-11e2-96fd-68d4426e58f3.png)