-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaxicroute.rb
110 lines (98 loc) · 2.9 KB
/
taxicroute.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
#!/usr/bin/env ruby -wKU
# taxicroute - a simple program to calculate costs for taxicab fares, as well as inner- and intra-city routes.
# Licensed under the MIT license. See LICENSE for full license text
# Copyright 2013
require "open-uri"
require "rubygems"
require "colorize"
require "./config.rb"
require "./address.rb"
require "./trip.rb"
Appdata.config do
parameter :muni
parameter :nominatim_endpoint
parameter :nominatim_options
parameter :gosmore_endpoint
parameter :gosmore_options
parameter :debug
parameter :round
parameter :costPerMile
parameter :outputFile
end
Appdata.config do
muni 'Rochester'
nominatim_endpoint 'http://nominatim.openstreetmap.org/search/'
nominatim_options '?format=json&addressdetails=1'
gosmore_endpoint 'http://www.yournavigation.org/api/1.0/gosmore.php'
gosmore_options '?geometry=0&v=motorcar&fast=1&format=geojson&layer=mapnik'
debug 'false'
round 0
costPerMile 2.5
outputFile true
end
inCity = 0
outCity = 0
totalOutMileage = Float(0)
totalInMileage = Float(0)
if(Appdata.outputFile)
foutput = File.new("processed_#{ARGV[0]}",'w')
end
File.readlines(ARGV[0]).each do |line|
tripInfo = line.split ','
fail = false
sAddr = tripInfo[4]+" "+tripInfo[5]+" "+tripInfo[6].strip
begin
sAddrGeo = Address.new sAddr
rescue
fail = true
end
dAddr = tripInfo[7]+" "+tripInfo[8]+" "+tripInfo[9].strip
begin
dAddrGeo = Address.new dAddr
rescue
fail = true
end
if(!fail)
sAddrState = sAddrGeo.municipality? ? "In-City" : "Out-City"
dAddrState = dAddrGeo.municipality? ? "In-City" : "Out-City"
output = tripInfo[0]+": (#{tripInfo[1]}, #{tripInfo[2]})\t"+sAddr+" (#{sAddrState}) <-> "+dAddr+" (#{dAddrState})"
if(sAddrState == "In-City" and dAddrState == "In-City")
trip = :in
else
trip = :out
end
if(trip == :in)
tripMetric = Trip.new(sAddrGeo,dAddrGeo)
print output.green
puts ("\t["+tripMetric.mileage+"]").blue
totalInMileage += Float(tripMetric.mileage)
inCity += 1
if(Appdata.outputFile)
foutput.write("#{line.strip!},#{tripMetric.mileage},IN,FLAT\n")
end
else
tripMetric = Trip.new(sAddrGeo,dAddrGeo)
print output.red
print ("\t["+tripMetric.mileage+"]").blue
puts ("\t{"+String(Float(tripMetric.mileage) * Appdata.costPerMile)+"}").yellow
totalOutMileage += Float(tripMetric.mileage)
outCity += 1
if(Appdata.outputFile)
foutput.write("#{line.strip!},#{tripMetric.mileage},OUT,#{Float(tripMetric.mileage) * Appdata.costPerMile}\n")
end
end
else
output = tripInfo[0]+": (#{tripInfo[1]}, #{tripInfo[2]})\t"+sAddr+" <-> "+dAddr+" #FAILED TO GEOCODE"
puts output.yellow
if(Appdata.outputFile)
foutput.write(line.strip!+",failed,failed,failed\n")
end
end
end
if(Appdata.outputFile)
foutput.close
end
puts " Inner-City Trips: #{inCity}"
puts " Out-of-City Trips: #{outCity}"
puts " Total inner-city Mileage: #{totalInMileage}"
puts "Total out-of-city Mileage: #{totalOutMileage}"