Skip to content

Instantly share code, notes, and snippets.

@thoughtpunch
Created February 14, 2012 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoughtpunch/1830120 to your computer and use it in GitHub Desktop.
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
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