Created
August 22, 2011 17:05
-
-
Save ctbarna/1162917 to your computer and use it in GitHub Desktop.
Parse FDNY response time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parse the FDNY average response time into JSON. | |
require 'rubygems' | |
require 'csv' | |
require 'json' | |
FILE = '../../Data/FDNY_monthly_response_time_001.TXT' | |
# Read the data | |
data = CSV.read(FILE, :col_sep => "\t", | |
:headers => true, :write_headers => false) | |
proc_data = [] | |
# Format the data | |
data.each do |row| | |
# Months | |
if /[0-9]{6}/ =~ row[0] | |
row[0] = Date.strptime(row[0], fmt="%Y%m") | |
end | |
# Convert the count number. | |
row[3] = row[3].to_i | |
# Time | |
time = row[4].split(":") | |
time.each_index do |i| | |
time[i] = time[i].to_i | |
end | |
row[4] = time[0]*60+time[1] | |
# Zip everything up. | |
proc_data.push(Hash[*row.headers().zip(row.fields()).flatten]) | |
end | |
File.open('fdny.json', 'w') {|f| f.write(JSON.generate(proc_data)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment