aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/exports.rake22
-rw-r--r--lib/tasks/helpers/simple_interfaces.rb2
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