rectify inline yaml sequence format
[bus.git] / maxious-canberra-transit-feed / 02-tidytimepoints.rb
blob:a/maxious-canberra-transit-feed/02-tidytimepoints.rb -> blob:b/maxious-canberra-transit-feed/02-tidytimepoints.rb
require 'rubygems' require 'rubygems'
require 'pp' require 'pp'
require 'yaml' require 'yaml'
  class Array
  def to_yaml_style
  :inline
  end
  end
Dir.chdir("output") Dir.chdir("output")
   
def getTimePoints() def getTimePoints()
$time_points = [] $time_points = []
$time_points_sources = Hash.new([]) $time_points_sources = Hash.new([])
Dir.glob("*.yml") { |file| Dir.glob("*.yml") { |file|
timetable = YAML::load_file(file) timetable = YAML::load_file(file)
$time_points = $time_points | timetable["time_points"] $time_points = $time_points | timetable["time_points"]
timetable["time_points"].each do |timepoint| timetable["time_points"].each do |timepoint|
$time_points_sources[timepoint] = $time_points_sources[timepoint] | [ file ] $time_points_sources[timepoint] = $time_points_sources[timepoint] | [ file ]
end end
} }
end end
  def correctTimePoints()
getTimePoints()  
pp $time_points.sort!  
#pp $time_points_sources.sort  
   
time_point_corrections = {"North Lynehamham" => "North Lyneham", time_point_corrections = {"North Lynehamham" => "North Lyneham",
"Lathlain St Platform 2" => "Lathlain St Bus Station - Platform 2", "Woden Bus Station Platform 10)" => "Woden Bus Station (Platform 10)",
"Lathlain St Sation - Platform 5" => "Lathlain St Bus Station - Platform 5", "Saint AndrewsVillage Hughes"=>"Saint Andrews Village Hughes",
"Lathlain Steet Station" => "Lathlain St Bus Station", "Flemmington Road / Sandford St"=>"Flemington Road / Sandford St",
"Lathlain St - Platform 3" => "Lathlain St Bus Station - Platform 3", "City Interchange"=>"City Bus Station",
"Lathlain Steet Station - Platform 3" => "Lathlain St Bus Station - Platform 3", "City Interchange (Platform 9)"=>"City Bus Station (Platform 9)",
"Lathlain St Station" => "Lathlain St Bus Station", "City Bus Station Platfrom 9"=>"City Bus Station (Platform 9)",
"Lathlain St Station - Platform 1" => "Lathlain St Bus Station - Platform 1", "Belconnen Community Bus StationPlatform 2)"=>"Belconnen Community Bus Station (Platform 2)",
"Lathlain St Station - Platform 2" => "Lathlain St Bus Station - Platform 2", "Bridbabella Gardens Nursing Home"=>"Brindabella Gardens Nursing Home",
"Lathlain St Station - Platform 3" => "Lathlain St Bus Station - Platform 3", "Bridbabella GardensNursing Home"=> "Brindabella Gardens Nursing Home",
"Lathlain St Station - Platform 4" => "Lathlain St Bus Station - Platform 4", "BrindabellaBusiness Park"=> "Brindabella Business Park",
"Lathlain St Station - Platform 5" => "Lathlain St Bus Station - Platform 5", "NarrabundahTerminus"=>"Narrabundah Terminus",
"Lathlain St Station - Platform 6" => "Lathlain St Bus Station - Platform 6", "Railway StationKingston"=>"Railway Station Kingston",
"Manuka Captain Cook" => "Manuka, Captain Cook", "Saint AndrewsVillage Hughes"=>"Saint Andrews Village Hughes",
"Flemington Rd, Sandford St" => "Flemington Rd/Sandford St", "Dickson ShopsAntill Street"=>"Dickson Shops",
"Erindale Centre / - Sternberg Crescent" => "Erindale Drive/Sternberg", "Cohen St Bus Station (Platform 3)" => "Cohen Street Bus Station (Platform 3)",
"Canberra Hospita" => "Canberra Hospital", "Cohen St Bus Station (Platform 6)" => "Cohen Street Bus Station (Platform 6)",
"Cohen Str Station - Platform 1" => "Cohen St Bus Station - Platform 1", "Newcastle Streetafter Isa Street" => "Newcastle Street after Isa Street",
"Cohen Street Station" => "Cohen St Bus Station", "Newcastle St after Isa St" => "Newcastle Street after Isa Street",
"Cohen Street Station - Platform 2" => "Cohen St Bus Station - Platform 2", "Newcastle Street after Isa St" => "Newcastle Street after Isa Street",
"Cohn St Station - Platform 3" => "Cohen St Bus Station - Platform 3", "Northbourne Ave / Antill St" => "Northbourne Avenue / Antill St",
"Cohen St Station" => "Cohen St Bus Station", "Macarthur / Northbourne" => "Macarthur / Northbourne Ave",
"Cohen St Station - Platform 1" => "Cohen St Bus Station - Platform 1", "Macarthur Ave / Northbourne" => "Macarthur / Northbourne Ave",
"Cohen St Station - Platform 2" => "Cohen St Bus Station - Platform 2", "Kings Ave / National Cct"=> "Kings Ave / National Circuit",
"Cohen St Station - Platform 3" => "Cohen St Bus Station - Platform 3", "Kosciuszco Ave / Everard Street"=>"Kosciuszko / Everard",
"Cohen St Station - Platform 4" => "Cohen St Bus Station - Platform 4", "Lithgow St Terminus" => "Lithgow St Terminus Fyshwick",
"Cohen St Station - Platform 5" => "Cohen St Bus Station - Platform 5", "Hospice Menindee Dr" => "Hospice / Menindee Dr",
"Cohen St Station - Platform 6" => "Cohen St Bus Station - Platform 6", "Gungahlin Market Place"=> "Gungahlin Marketplace",
"City - Platform 7" => "City Interchange - Platform 7", "Gwyder Square Kaleen"=> "Gwydir Square Kaleen",
"Cameron Avenue Station" => "Cameron Ave Bus Station", "Flemington Road / Nullabor Ave"=>"Flemington Rd / Nullabor Ave",
"Cameron Avenue Station - Platform 1" => "Cameron Ave Bus Station - Platform 1", "Flemington Road / Sandford St"=>"Flemington Rd / Sandford St",
"Cameron Avenue Station - Platform 2" => "Cameron Ave Bus Station - Platform 2", "Heagney Cres Clift Cres Richardson"=> "Heagney / Clift Richardson",
"Cameron Avenue Station - Platform 3" => "Cameron Ave Bus Station - Platform 3", "Charnwood Shops (Tillyard Drive)"=> "Charnwood Shops",
"Cameron Avenue Station - Platform 4" => "Cameron Ave Bus Station - Platform 4", "charnwood Shops"=> "Charnwood Shops",
"Cameron Avenue Station - Platform 5" => "Cameron Ave Bus Station - Platform 5", "Black Moutain- Telstra Tower"=>"Black Mountain Telstra Tower",
"Cameron Ave Station" => "Cameron Ave Bus Station", "Bonython Primary"=> "Bonython Primary School",
"Cameron Ave Station - Platform 1" => "Cameron Ave Bus Station - Platform 1", "Athllon Drive / Sulwood Dr Kambah"=>"Athllon / Sulwood Kambah",
"Cameron Ave Station - Platform 2" => "Cameron Ave Bus Station - Platform 2", "Alexander Machonochie Centre Hume"=>"Alexander Maconochie Centre",
"Cameron Ave Station - Platform 3" => "Cameron Ave Bus Station - Platform 3", "Alexander Maconochie Centre Hume"=>"Alexander Maconochie Centre",
"Cameron Ave Station - Platform 4" => "Cameron Ave Bus Station - Platform 4", "Anthony Rolfe Ave / Moonight Ave" =>"Anthony Rolfe Av / Moonlight Av",
"Cameron Ave Station - Platform 5" => "Cameron Ave Bus Station - Platform 5", "Australian National Botanic Gardens"=>"Botanic Gardens",
"Burton & Garranan Hall, Daley Road ANU" => "Burton & Garran Hall, Daley Road ANU", "Calwell shops"=> "Calwell Shops",
"Burton & Garranan Hall,Daley Road ANU" => "Burton & Garran Hall, Daley Road ANU", "Chuculba / William Slim Drive"=>"Chuculba / William Slim Dr",
"Garran/Daley Rd" => "Burton & Garran Hall, Daley Road ANU", "Fyshwick direct Factory Outlet"=>"Fyshwick Direct Factory Outlet",
"Kingstons Ave/National Crt" => "Kings Ave/National Crt", "Kaleen Village / Maibrynong"=>"Kaleen Village / Marybrynong",
"Newcastle Street after Isa St" => "Newcastle / Isa Street Fyshwick", "Kaleen Village / Marybrynong Ave"=>"Kaleen Village / Marybrynong",
"National Circ/Canberra Ave" => "National Circuit / Canberra Ave", "National Aquarium"=>"National Zoo and Aquarium",
"St Clare of Conder" => "St Clare of Assisi Primary", "chisholm Shops"=>"Chisholm Shops",
"McKillop College Isabella Campus" => "MacKillop College Isabella Campus", "O'connor Shops"=>"O'Connor Shops",
"Outrim / Duggan" => "Outtrim / Duggan", "Mckellar Shops"=>"McKellar Shops",
} "Melba shops"=> "Melba Shops",
time_point_corrections.each do |wrong, right| "William Web / Ginninderra Drive"=>"William Webb / Ginninderra Drive",
$time_points_sources[wrong].each do |wrongfile| "Procor / Mead"=>"Proctor / Mead",
badtimetable = YAML::load_file(wrongfile) "Fyshwick DirectFactory Outlet"=>"Fyshwick Direct Factory Outlet",
badentrynumber = badtimetable["time_points"].index wrong "Yarrulumla Shops"=>"Yarralumla Shops",
badtimetable["time_points"][badentrynumber] = right "Tharwa Dr / Pocket Ave"=>"Tharwa Dr / Pockett Ave",
puts "Corrected '" + wrong + "' to '" + right + "' in " + wrongfile "Paul Coe / Mirrebei Dr"=>"Paul Coe / Mirrabei Dr",
File.open(wrongfile, "w") do |f| "Mirrebei Drive / Dam Wall"=>"Mirrabei Drive / Dam Wall",
f.write badtimetable.to_yaml "Tharwa / Knoke" => "Tharwa Drive / Knoke Ave",
  "Tharwa / Pocket" => "Tharwa Dr / Pockett Ave",
  "Outrim / Duggan" => "Outtrim / Duggan",
  "ANU Burton and Garran Hall Daley Rd" => "Burton and Garran Hall Daley Road",
  "Farrer Primary"=>"Farrer Primary School",
  "St Thomas More Campbell"=>"St Thomas More's Campbell",
  "Lyneham Shops"=>"Lyneham Shops Wattle Street",
   
   
  }
  time_point_corrections.each do |wrong, right|
  $time_points_sources[wrong].each do |wrongfile|
  badtimetable = YAML::load_file(wrongfile)
  badentrynumber = badtimetable["time_points"].index wrong
  badtimetable["time_points"][badentrynumber] = right
  puts "Corrected '" + wrong + "' to '" + right + "' in " + wrongfile
  File.open(wrongfile, "w") do |f|
  f.write badtimetable.to_yaml
  end
end end
end end
end end
   
getTimePoints() getTimePoints()
  #pp $time_points.sort!
  #pp $time_points_sources.sort
   
   
  correctTimePoints()
  getTimePoints()
  correctTimePoints()
  getTimePoints()
pp $time_points.sort! pp $time_points.sort!