Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USER_ID = 1405
- MAX_MAPS = 100000
- MAX_IMPORTS = 100000
- START_AGENCY_INDEX = 193
- user = User.find(USER_ID)
- agency_count = Flightcase::Agency.all.count
- Flightcase::Agency.last(MAX_MAPS).each_with_index { |agency, agency_index|
- name = "#{agency.name} map"
- city = agency.city
- if city.nil?
- city = 'San Francisco'
- end
- if agency_index < START_AGENCY_INDEX
- next
- puts "Skipping '#{name}', it is below the starting index of #{START_AGENCY_INDEX}"
- end
- begin
- map = user.maps.new(
- name: name,
- author_id: USER_ID,
- flightcase_agency_id: agency.id,
- city: city,
- color: '#0D7215',
- center: '{"type":"Point","coordinates":[-122.4194155,37.7749295]}'
- )
- puts "Creating map #{agency_index + 1}/#{agency_count}: '#{name}'..."
- map.save!
- map.copy_stops_from_agency!
- line_count = agency.active_lines.count
- agency.active_lines.slice(0, MAX_IMPORTS).each_with_index { |line, line_index|
- puts " Importing #{line_index + 1}/#{line_count}: '#{line.long_name}'..."
- begin
- patterns = line.patterns.select { |p| p.rank == 'LONGEST' }
- pattern_conditions = {
- flightcase_patterns: {
- flightcase_line_id: line.id,
- id: patterns[0].id,
- },
- }
- flightcase_pattern = ::Flightcase::Pattern.active.where(pattern_conditions).first!
- import = ::Flightcase::LineImport.new(map, flightcase_pattern)
- import.run!
- rescue
- puts "FAILED TO IMPORT LINE #{line.id}!"
- end
- }
- rescue
- puts "FAILED TO CREATE MAP #{agency.id}!"
- puts e
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement