Skip to content

Commit

Permalink
associate lat lng with stops
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Choi committed Feb 26, 2011
1 parent 38f4d34 commit 535cc2b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions train_locations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@
predictions = YAML::load(File.read("subway_predictions.yml"))

def reduce(hash)
{ :name => hash[:name.to_s],
:time => hash[:time.to_s] }
{
:name => hash[:name.to_s],
:time => hash[:time.to_s]
}
end

# associate with lat, lng
GEO_STOPS = YAML::load(File.open("geo_subway_stops.yml"))

def geo(line, name)
x = GEO_STOPS[line.upcase].detect {|x|
name.sub(/ Station$/, '').upcase == x[0]
}
x ? x[1..-1] : nil
end

r = {}
predictions.each do |line|
r[line[:line]] = line[:trips].
select {|t| t[:predictions].size > 1}.
map { |trip|
{:left => reduce( trip[:predictions][0] ),
:arriving => reduce(trip[:predictions][1]) }
left = reduce( trip[:predictions][0] )
arr = reduce( trip[:predictions][1] )
left[:geo] = geo(line[:line], left[:name])
arr[:geo] = geo(line[:line], arr[:name])
{ :left => left, :arriving => arr }
}

end

# associate with lat, lng

geo_stops = YAML::load(File.open("geo_subway_stops.yml"))

File.open("train_locations.yml", 'w') {|f| f.puts r.to_yaml}

Expand Down

0 comments on commit 535cc2b

Please sign in to comment.