Created
February 14, 2012 20:31
-
-
Save thoughtpunch/1830120 to your computer and use it in GitHub Desktop.
A query to get all the writer duplicates as well as their writing credit counts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def duplicate_writers(artist_list) | |
FasterCSV.open("duplicate_writers_report.csv", "wb") do |csv| | |
csv << ["WRITER_ID","WRITER_NAME","ARTIST_BAND","WRITER_PRO_ID","WRITER_PRO_NUMBER","WRITING_CREDITS_COUNT"] | |
artist_list.each do |id| | |
artist = User.find(id) | |
writer_names = artist.writers.collect {|writer| writer.old_name.gsub(/\W+/,"").downcase} | |
artist.writers.each do |person| | |
#make their name downcase | |
compare_name = person.old_name.gsub(/\W+/,"").downcase | |
#count how many times they appear in the old array | |
if writer_names.count(compare_name) > 1 | |
csv << ["#{person.id},#{person.first_name} #{person.last_name},#{artist.band_name},#{person.pro_id},#{person.pro_number},#{person.writing_credits.count}"] | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment