Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

157 lines (153 sloc) 5.654 kB
require 'pp'
require 'json'
require 'net/http'
require 'cgi'
#csv_to_hashed, with some keys ignored, via http://www.taxifarefinder.com/rates.php
$taxi_info = [{"Add. Charge (per mile)"=>"$2.80",
"City"=>"Boston",
"Wait Time Charge (per hour)"=>"$28.00",
"Initial Increment (mile)"=>"1/7",
"Initial Charge"=>"$2.60"},
{"Add. Charge (per mile)"=>"$2.10",
"City"=>"Kansas City",
"Wait Time Charge (per hour)"=>"$40.00",
"Initial Increment (mile)"=>"1/10",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.60",
"City"=>"Las Vegas",
"Wait Time Charge (per hour)"=>"$30.00",
"Initial Increment (mile)"=>"1/13",
"Initial Charge"=>"$3.30"},
{"Add. Charge (per mile)"=>"$2.45",
"City"=>"Los Angeles",
"Wait Time Charge (per hour)"=>"$26.53",
"Initial Increment (mile)"=>"1/7",
"Initial Charge"=>"$2.65"},
{"Add. Charge (per mile)"=>"$2.50",
"City"=>"Milwaukee",
"Wait Time Charge (per hour)"=>"$21.00",
"Initial Increment (mile)"=>"1/10",
"Initial Charge"=>"$2.75"},
{"Add. Charge (per mile)"=>"$2.40",
"City"=>"Honolulu",
"Wait Time Charge (per hour)"=>"$27.00",
"Initial Increment (mile)"=>"1/8",
"Initial Charge"=>"$2.25"},
{"Add. Charge (per mile)"=>"$2.30",
"City"=>"Philadelphia",
"Wait Time Charge (per hour)"=>"$30.00",
"Initial Increment (mile)"=>"1/7",
"Initial Charge"=>"$2.70"},
{"Add. Charge (per mile)"=>"$2.25",
"City"=>"San Francisco",
"Wait Time Charge (per hour)"=>"$27.00",
"Initial Increment (mile)"=>"1/5",
"Initial Charge"=>"$3.10"},
{"Add. Charge (per mile)"=>"$2.50",
"City"=>"Orlando",
"Wait Time Charge (per hour)"=>"$22.50",
"Initial Increment (mile)"=>"-",
"Initial Charge"=>"$3.00"},
{"Add. Charge (per mile)"=>"$2.60",
"City"=>"San Diego",
"Wait Time Charge (per hour)"=>"$20.00",
"Initial Increment (mile)"=>"1/10",
"Initial Charge"=>"$2.40"},
{"Add. Charge (per mile)"=>"$2.25",
"City"=>"Denver",
"Wait Time Charge (per hour)"=>"$22.50",
"Initial Increment (mile)"=>"1/9",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.40",
"City"=>"Miami",
"Wait Time Charge (per hour)"=>"$24.00",
"Initial Increment (mile)"=>"1/6",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.50",
"City"=>"Portland",
"Wait Time Charge (per hour)"=>"$15.00",
"Initial Increment (mile)"=>"1/10",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.35",
"City"=>"Minneapolis",
"Wait Time Charge (per hour)"=>"$24.00",
"Initial Increment (mile)"=>"1/5",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.00",
"City"=>"Seattle",
"Wait Time Charge (per hour)"=>"$30.00",
"Initial Increment (mile)"=>"-",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.00",
"City"=>"New York",
"Wait Time Charge (per hour)"=>"$24.00",
"Initial Increment (mile)"=>"1/5",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.25",
"City"=>"Detroit",
"Wait Time Charge (per hour)"=>"$24.00",
"Initial Increment (mile)"=>"1/8",
"Initial Charge"=>"$3.00"},
{"Add. Charge (per mile)"=>"$2.00",
"City"=>"Atlanta",
"Wait Time Charge (per hour)"=>"$21.00",
"Initial Increment (mile)"=>"1/8",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$2.24",
"City"=>"Cleveland",
"Wait Time Charge (per hour)"=>"$18.00",
"Initial Increment (mile)"=>"1/8",
"Initial Charge"=>"$2.75"},
{"Add. Charge (per mile)"=>"$2.20",
"City"=>"Salt Lake City",
"Wait Time Charge (per hour)"=>"$22.00",
"Initial Increment (mile)"=>"1/11",
"Initial Charge"=>"$2.20"},
{"Add. Charge (per mile)"=>"$1.80",
"City"=>"Phoenix",
"Wait Time Charge (per hour)"=>"$19.80",
"Initial Increment (mile)"=>"-",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$1.80",
"City"=>"Baltimore",
"Wait Time Charge (per hour)"=>"$24.00",
"Initial Increment (mile)"=>"-",
"Initial Charge"=>"$2.00"},
{"Add. Charge (per mile)"=>"$1.87",
"City"=>"Houston",
"Wait Time Charge (per hour)"=>"$20.00",
"Initial Increment (mile)"=>"2/11",
"Initial Charge"=>"$2.50"},
{"Add. Charge (per mile)"=>"$1.80",
"City"=>"Chicago",
"Wait Time Charge (per hour)"=>"$20.00",
"Initial Increment (mile)"=>"1/9",
"Initial Charge"=>"$2.25"},
{"Add. Charge (per mile)"=>"$1.80",
"City"=>"Dallas",
"Wait Time Charge (per hour)"=>"$18.00",
"Initial Increment (mile)"=>"1/9",
"Initial Charge"=>"$2.25"},
{"Add. Charge (per mile)"=>"$1.75",
"City"=>"Pittsburgh",
"Wait Time Charge (per hour)"=>"$9.00",
"Initial Increment (mile)"=>"1/7",
"Initial Charge"=>"$2.25"},
{"Add. Charge (per mile)"=>"$1.50",
"City"=>"Washington",
"Wait Time Charge (per hour)"=>"$15.00",
"Initial Increment (mile)"=>"1/6",
"Initial Charge"=>"$3.00"},
{"Add. Charge (per mile)"=>"$1.70",
"City"=>"St. Louis",
"Wait Time Charge (per hour)"=>"$22.00",
"Initial Increment (mile)"=>"1/10",
"Initial Charge"=>"$2.50"}]
KM_PER_MILE = 1.609344
$taxi_info.each {|l| r= JSON.parse(Net::HTTP.get(URI.parse("http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address="+CGI.escape(l["City"]))))["results"][0]["geometry"]["location"]; l[:lat]=r["lat"]; l[:lon]=r["lng"]}
$taxi_info.each {|l| l[:per_km] = l.delete("Add. Charge (per mile)").sub('$','').to_f / KM_PER_MILE}
$taxi_info.each {|l| l[:per_hour_waiting] = l.delete("Wait Time Charge (per hour)").sub('$','').to_f}
$taxi_info.each {|l| l[:initial_increment_km] = l.delete("Initial Increment (mile)").split('/').map(&:to_f).inject(&:/) * KM_PER_MILE}
$taxi_info.each {|l| l[:initial_charge] = l.delete("Initial Charge").sub('$','').to_f}
$taxi_info.each {|l| l[:city] = l.delete("City")}
pp $taxi_info
Jump to Line
Something went wrong with that request. Please try again.