diff options
author | otherl <lgdmiller@gmail.com> | 2013-09-29 01:44:00 +0100 |
---|---|---|
committer | otherl <lgdmiller@gmail.com> | 2013-09-29 01:44:00 +0100 |
commit | e12a7e69dce4081ac809fc11d83de5d7330269cf (patch) | |
tree | 79f5271e8c43b8778ab2f682cbfcc4eea6e1d708 /tube_data_parser.rb | |
parent | b96d9822465eca859fae71d48bd33a8591e51260 (diff) |
Fixed a bug that caused change times to not be used. Improved input parsing for line status. Refactored and improved parts of the code.
Diffstat (limited to 'tube_data_parser.rb')
-rw-r--r-- | tube_data_parser.rb | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/tube_data_parser.rb b/tube_data_parser.rb index 7863df3..47c45b0 100644 --- a/tube_data_parser.rb +++ b/tube_data_parser.rb @@ -8,23 +8,8 @@ csv_data.each do |line,direction,from_station,to_station,distance,unimpeded_time end tube_data_hash.keys.each do |from_station| stations = tube_data_hash.find_all {|f_stat,t_stats| f_stat.split('_')[0] == from_station.split('_')[0] } - if stations.size == 1 - tube_data_hash[from_station.gsub(/_.*/,'')] = tube_data_hash.delete(from_station) - to_stations = tube_data_hash[from_station.gsub(/_.*/,'')] - to_stations.keys.each {|station| to_stations[station.gsub(/_.*/,'')] = to_stations.delete(station)} - else - stations.each do |f_stat,t_stats| - tube_data_hash[from_station].merge! t_stats - end - end -end -change_stations = tube_data_hash.find_all {|f_stat,t_stats| f_stat.match /_/ }.map {|f_stat,t_stats| f_stat} -change_stations.each do |from_station| - to_stations = tube_data_hash[from_station] - to_stations.keys.each {|station| to_stations[station.gsub(/_.*/,'')] = to_stations.delete(station) unless change_stations.include?(station)} - tube_data_hash[from_station][from_station.gsub(/_.*/,'')] = {'line' => from_station.split('_')[1], 'direction' => nil, 'distance' => 0.01, 'unimpeded_time' => 0.01, 'peak_time' => 0.01, 'off_peak_time' => 0.01} - tube_data_hash[from_station].each do |to_station,data| - tube_data_hash[from_station.gsub(/_.*/,'')][from_station] = {'line' => from_station.split('_')[1], 'direction' => nil, 'distance' => 0.01, 'unimpeded_time' => 0.01, 'peak_time' => 0.01, 'off_peak_time' => 0.01} + stations.each do |f_stat,t_stats| + tube_data_hash[from_station].merge! t_stats end end File.new('graph.yaml', 'w') << tube_data_hash.to_yaml |