* generate CSV and PDF for jamtracks

This commit is contained in:
Seth Call 2015-12-04 08:32:18 -06:00
parent 54a437d6e1
commit 5049e3f813
4 changed files with 124 additions and 9 deletions

View File

@ -446,6 +446,29 @@ module JamRuby
JamTrackTrack.where(jam_track_id: self.id).where(track_type: 'Click').first
end
def has_count_in?
has_count_in = false
if jmep_json
jmep = JSON.parse(jmep_json)
if jmep["Events"]
events = jmep["Events"]
metronome = nil
events.each do |event|
if event.has_key?("metronome")
metronome = event["metronome"]
break
end
end
if metronome
has_count_in = true
end
end
end
has_count_in
end
def master_track
JamTrackTrack.where(jam_track_id: self.id).where(track_type: 'Master').first
end

View File

@ -63,6 +63,7 @@ gem 'haml-rails'
gem 'unf' #optional fog dependency
gem 'devise', '3.3.0' #3.4.0 causes uninitialized constant ActionController::Metal (NameError)
gem 'postgres-copy'
gem 'prawn-table'
#group :libv8 do
# gem 'libv8', "~> 3.11.8"
#end

View File

@ -6,3 +6,5 @@
= render "screen_navigation"
.content-body
= react_component 'JamTrackLandingScreen', {}

View File

@ -66,7 +66,7 @@ namespace :jam_tracks do
JamTrackImporter.storage_format = 'Tency'
end
JamTrackImporter.synchronize_from_meta("#{path}/meta.yml", skip_audio_upload:false)
JamTrackImporter.synchronize_from_meta("#{path}/meta.yml", skip_audio_upload: false)
end
task resync_audio: :environment do |task, args|
@ -77,7 +77,7 @@ namespace :jam_tracks do
exit(1)
end
JamTrackImporter.synchronize_from_meta("audio/#{path}/meta.yml", resync_audio:true, skip_audio_upload:false)
JamTrackImporter.synchronize_from_meta("audio/#{path}/meta.yml", resync_audio: true, skip_audio_upload: false)
end
task tency_genre_dump: :environment do |task, args|
@ -87,12 +87,12 @@ namespace :jam_tracks do
task sync_tency: :environment do |task, args|
JamTrackImporter.storage_format = 'Tency'
JamTrackImporter.synchronize_all(skip_audio_upload:false)
JamTrackImporter.synchronize_all(skip_audio_upload: false)
end
task sync_tim_tracks: :environment do |task, args|
JamTrackImporter.storage_format = 'TimTracks'
JamTrackImporter.synchronize_all(skip_audio_upload:false)
JamTrackImporter.synchronize_all(skip_audio_upload: false)
end
task tency_dups: :environment do |task, args|
@ -115,12 +115,12 @@ namespace :jam_tracks do
end
task sync_all: :environment do |task, args|
JamTrackImporter.synchronize_all(skip_audio_upload:false)
JamTrackImporter.synchronize_all(skip_audio_upload: false)
end
task sync_all_dev: :environment do |task, args|
JamTrackImporter.storage_format = 'default'
JamTrackImporter.synchronize_all(skip_audio_upload:true)
JamTrackImporter.synchronize_all(skip_audio_upload: true)
end
task sync_previews_all: :environment do |task, arg|
@ -196,9 +196,10 @@ namespace :jam_tracks do
mapper.correlate
end
task touch: :environment do |task, arg|
JamTrack.all.each do |jt|
jt.touch # causes jmep re-spin
task touch: :environment do |task, arg|
JamTrack.all.each do |jam_track|
jam_track.jmep_json_generate
jam_track.save!
end
end
@ -226,4 +227,92 @@ namespace :jam_tracks do
end
end
end
task generate_master_listing: :environment do |task, arg|
instruments = Instrument.all
jam_tracks = JamTrack.where(status: 'Production').order('original_artist, name')
Dir.mktmpdir do |tmp_dir|
csv_file = File.join(tmp_dir, "production.csv")
pdf_file = File.join(tmp_dir, "production.pdf")
CSV.open(csv_file, "wb") do |csv|
header = ['Artist', 'Name', 'Link', 'Click Track', 'Count-In', 'Added to Catalog']
instruments.each do |instrument|
header << instrument.description
end
csv << header
jam_tracks.each do |jam_track|
row = []
row << jam_track.original_artist
row << jam_track.name
row << Rails.application.config.external_root_url + Rails.application.routes.url_helpers.individual_jamtrack_path(jam_track.slug)
row << (jam_track.click_track.nil? ? 'no' : 'yes')
row << (jam_track.has_count_in? ? 'yes' : 'no')
row << jam_track.created_at.to_date.to_s
tracks = jam_track.jam_track_tracks
instruments.each do |instrument|
match = false
tracks.each do |track|
if track.track_type == 'Track' && track.instrument_id == instrument.id
match = true
break
end
end
row << (match ? 'yes' : 'no')
end
csv << row
end
end
Prawn::Document.generate(pdf_file) do
text "All JamKazam JamTracks", align: :center, size:18, inline_format: true
move_down 20
text "This PDF was downloaded from <link href=\"https://s3.amazonaws.com/jamkazam-public/public/lists/all-jamkazam-jamtracks.pdf\"><color rgb='0000FF'>here</color></link>.", inline_format: true, font_size:12
move_down 10
text "The CSV version can be downloaded from <link href=\"https://s3.amazonaws.com/jamkazam-public/public/lists/all-jamkazam-jamtracks.csv\"><color rgb='0000FF'>here</color></link>. It also contains instrument info.", inline_format: true, font_size:12
move_down 20
pdf_data= []
header = ['Artist', 'Song Name', 'Site Link', 'Click Track', 'Count In', 'Added to Catalog']
columns = header.length
pdf_data << header
jam_tracks.each do |jam_track|
table_row = []
table_row << jam_track.original_artist
table_row << jam_track.name
table_row << "<link href=\"#{Rails.application.config.external_root_url + Rails.application.routes.url_helpers.individual_jamtrack_path(jam_track.slug)}\"><color rgb='0000FF'>link </color></link>"
table_row << (jam_track.click_track.nil? ? 'no' : 'yes')
table_row << (jam_track.has_count_in? ? 'yes' : 'no')
table_row << jam_track.created_at.to_date.to_s
pdf_data << table_row
end
table(pdf_data, :cell_style => {inline_format: true}, header: true, row_colors: ["D0D0D0", "F0F0F0"])
end
s3_manager = S3Manager.new(Rails.application.config.aws_bucket_public, Rails.application.config.aws_access_key_id, Rails.application.config.aws_secret_access_key)
s3_manager.upload('public/lists/all-jamkazam-jamtracks.csv', csv_file, content_type: 'text/csv')
s3_manager.upload('public/lists/all-jamkazam-jamtracks.pdf', pdf_file, content_type: 'application/pdf')
FileUtils.mv(csv_file, 'tmp/test.csv')
FileUtils.mv(pdf_file, 'tmp/test.pdf')
end
end
end