diff options
| author | Zog | 2018-03-05 09:11:34 +0100 |
|---|---|---|
| committer | Zog | 2018-03-05 09:11:34 +0100 |
| commit | ea3de6035cdf9fbbcd92f51c90e5a2c5c3400cb3 (patch) | |
| tree | d35feb918791f94d69ebb97bf1224d8a96b60796 /lib | |
| parent | c1ac12174b9aff7535a84af9f76d1cda95b750f4 (diff) | |
| download | chouette-core-ea3de6035cdf9fbbcd92f51c90e5a2c5c3400cb3.tar.bz2 | |
Refs #6068; Export VehicleJourneys
Add a mechanism to allow for several rows in the csv per single object
in the collection.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tasks/exports.rake | 22 | ||||
| -rw-r--r-- | lib/tasks/helpers/simple_interfaces.rb | 2 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/tasks/exports.rake b/lib/tasks/exports.rake index 036d96b11..6ff73dac0 100644 --- a/lib/tasks/exports.rake +++ b/lib/tasks/exports.rake @@ -40,8 +40,24 @@ namespace :export do SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args end - desc "export a complete offer from the gicen referential in the given X next days" - task :full_offer, [:referential_id, :timelapse, :configuration_name, :output_dir, :logs_output_dir] => :environment do |t, args| - args.with_defaults(filepath: "./companies.csv", logs_output_dir: "./log/exporters/") + 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) + + referential.switch + + journeys = Chouette::VehicleJourney.with_matching_timetable (Time.now.to_date..args[:timelapse].to_i.days.from_now.to_date) + 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 + end end end diff --git a/lib/tasks/helpers/simple_interfaces.rb b/lib/tasks/helpers/simple_interfaces.rb index 68e02e818..1dc051575 100644 --- a/lib/tasks/helpers/simple_interfaces.rb +++ b/lib/tasks/helpers/simple_interfaces.rb @@ -2,7 +2,7 @@ module SimpleInterfacesHelper def self.interface_output_to_csv interface, output_dir filepath = File.join output_dir, + "#{interface.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}_out.csv" cols = %w(line kind event message error) - if interface.reload.journal.size > 0 + if interface.reload.journal.size > 0 && interface.journal.first["row"].present? keys = interface.journal.first["row"].map(&:first) CSV.open(filepath, "w") do |csv| csv << cols + keys |
