diff options
Diffstat (limited to 'lib/tasks/exports.rake')
| -rw-r--r-- | lib/tasks/exports.rake | 38 | 
1 files changed, 36 insertions, 2 deletions
| diff --git a/lib/tasks/exports.rake b/lib/tasks/exports.rake index 6ff73dac0..8688611e8 100644 --- a/lib/tasks/exports.rake +++ b/lib/tasks/exports.rake @@ -43,7 +43,7 @@ namespace :export do    desc "export a complete offer from the given referential in the given X next days"    task :full_offer, [:referential_id, :configuration_name, :timelapse, :output_dir, :logs_output_dir] => :environment do |t, args|      referential = Referential.find args[:referential_id] -    args.with_defaults(output_dir: referential.name, logs_output_dir: "./log/exporters/", timelapse: 90) +    args.with_defaults(output_dir: "#{referential.name.parameterize}_#{Time.now.strftime "%y%m%d%H%M"}", logs_output_dir: "./log/exporters/", timelapse: 90)      referential.switch @@ -51,13 +51,47 @@ namespace :export do      if journeys.count == 0        puts "No maching journeys were found".red      else -        exporter = SimpleExporter.create configuration_name: "#{args[:configuration_name]}_journeys", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_journeys.csv"        exporter.configure do |config|          config.collection = journeys        end        SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args +      return unless exporter.status == :success + +      exporter = SimpleExporter.create configuration_name: "#{args[:configuration_name]}_schedules", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_schedules.csv" +      exporter.configure do |config| +        config.collection = journeys +      end + +      SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args +      return unless exporter.status == :success + +      exporter = SimpleExporter.create configuration_name: "#{args[:configuration_name]}_routes", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_routes.csv" +      exporter.configure do |config| +        config.collection = Chouette::JourneyPattern.where(id: journeys.pluck(:journey_pattern_id).uniq) +      end + +      SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args +      return unless exporter.status == :success + +      exporter = SimpleExporter.create configuration_name: "#{args[:configuration_name]}_stops", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_stops.csv" +      exporter.configure do |config| +        config.collection = Chouette::StopArea.where(id: journeys.joins(:stop_points).pluck(:"stop_points.stop_area_id").uniq).order('parent_id ASC NULLS FIRST') +      end + +      SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args +      return unless exporter.status == :success + +      exporter = SimpleExporter.create configuration_name: "#{args[:configuration_name]}_companies", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_companies.csv" +      ids = journeys.pluck :company_id +      ids += journeys.joins(route: :line).pluck :"lines.company_id" + +      exporter.configure do |config| +        config.collection = Chouette::Company.where(id: ids.uniq).order('name') +      end + +      SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args      end    end  end | 
