forked from codeforamerica/transpochoices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaxi_generate.rb
157 lines (153 loc) · 5.53 KB
/
taxi_generate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require 'pp'
require 'json'
require 'net/http'
require 'cgi'
#csv_to_hashed, with some keys ignored. courtesy of 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