Skip to content

Commit

Permalink
tweaking reports
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Feb 12, 2020
1 parent 9c52fb1 commit d2a0ae2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 6 additions & 5 deletions app/services/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def initialize(params)

# @return [Array] an array of druids on the storage root
def moab_storage_root_druid_list
druid_array = []
druids = []
PreservedObject
.joins(:complete_moabs)
.where(complete_moabs: { moab_storage_root: storage_root })
.select(:druid)
.order(:druid)
.each_row do |po_hash|
druid_array << po_hash['druid']
druids << po_hash['druid']
end
druid_array
druids
end

# @param [Array] druids - list of druids to output details for
Expand Down Expand Up @@ -73,8 +73,9 @@ def write_to_csv(lines, report_name = nil, filename = nil)
ensure_containing_dir(filename)
CSV.open(filename, 'w') do |csv|
lines.each do |line|
line = line.values if line.is_a? Hash
csv << line
output = line.values if line.is_a? Hash
output = [line] if line.is_a? String
csv << output
end
end

Expand Down
3 changes: 0 additions & 3 deletions lib/tasks/prescat.rake
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ namespace :prescat do
desc 'query for druids on storage root & dump to CSV (2nd arg optional)'
task :msr_druids, [:storage_root_name, :csv_filename] => [:environment] do |_task, args|
reporter = Reporter.new(storage_root_name: args[:storage_root_name])
reporter.moab_storage_root_druid_list
csv_loc = reporter.write_to_csv(reporter.druids, 'msr_druids', args[:csv_filename])
puts "druids for #{args[:storage_root_name]} written to #{csv_loc}"
end

desc 'query for druids on storage root & dump details to CSV (2nd arg optional)'
task :msr_druid_detail, [:storage_root_name, :csv_filename] => [:environment] do |_task, args|
reporter = Reporter.new(storage_root_name: args[:storage_root_name])
reporter.moab_storage_root_druid_list
data = reporter.moab_detail_for(reporter.druids)
csv_loc = reporter.write_to_csv(data, 'msr_druid_detail', args[:csv_filename])
puts "druid details for #{args[:storage_root_name]} written to #{csv_loc}"
Expand All @@ -34,7 +32,6 @@ namespace :prescat do
desc 'query for druids on storage root & dump audit error details to CSV (2nd arg optional)'
task :msr_audit_errors, [:storage_root_name, :csv_filename] => [:environment] do |_task, args|
reporter = Reporter.new(storage_root_name: args[:storage_root_name])
reporter.moab_storage_root_druid_list
data = reporter.moab_detail_for(reporter.druids, errors_only: true)
csv_loc = reporter.write_to_csv(data, 'msr_audit_errors', args[:csv_filename])
puts "druids with errors details for #{args[:storage_root_name]} written to #{csv_loc}"
Expand Down

0 comments on commit d2a0ae2

Please sign in to comment.