Advertisement
Guest User

Untitled

a guest
May 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. USER_ID = 1405
  2. MAX_MAPS = 100000
  3. MAX_IMPORTS = 100000
  4. START_AGENCY_INDEX = 193
  5.  
  6. user = User.find(USER_ID)
  7.  
  8. agency_count = Flightcase::Agency.all.count
  9. Flightcase::Agency.last(MAX_MAPS).each_with_index { |agency, agency_index|
  10. name = "#{agency.name} map"
  11. city = agency.city
  12. if city.nil?
  13. city = 'San Francisco'
  14. end
  15.  
  16. if agency_index < START_AGENCY_INDEX
  17. next
  18. puts "Skipping '#{name}', it is below the starting index of #{START_AGENCY_INDEX}"
  19. end
  20.  
  21. begin
  22. map = user.maps.new(
  23. name: name,
  24. author_id: USER_ID,
  25. flightcase_agency_id: agency.id,
  26. city: city,
  27. color: '#0D7215',
  28. center: '{"type":"Point","coordinates":[-122.4194155,37.7749295]}'
  29. )
  30.  
  31. puts "Creating map #{agency_index + 1}/#{agency_count}: '#{name}'..."
  32.  
  33. map.save!
  34. map.copy_stops_from_agency!
  35.  
  36. line_count = agency.active_lines.count
  37. agency.active_lines.slice(0, MAX_IMPORTS).each_with_index { |line, line_index|
  38. puts " Importing #{line_index + 1}/#{line_count}: '#{line.long_name}'..."
  39.  
  40. begin
  41. patterns = line.patterns.select { |p| p.rank == 'LONGEST' }
  42. pattern_conditions = {
  43. flightcase_patterns: {
  44. flightcase_line_id: line.id,
  45. id: patterns[0].id,
  46. },
  47. }
  48.  
  49. flightcase_pattern = ::Flightcase::Pattern.active.where(pattern_conditions).first!
  50. import = ::Flightcase::LineImport.new(map, flightcase_pattern)
  51. import.run!
  52. rescue
  53. puts "FAILED TO IMPORT LINE #{line.id}!"
  54. end
  55. }
  56. rescue
  57. puts "FAILED TO CREATE MAP #{agency.id}!"
  58. puts e
  59. end
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement