Created
          April 4, 2014 16:46 
        
      - 
      
- 
        Save cmorss/9978519 to your computer and use it in GitHub Desktop. 
    Top Genres and Moods for an Artist
  
        
  
    
      This file contains hidden or 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 artist_stats ids | |
| Artist.find(ids).each do |artist| | |
| puts artist.name | |
| tracks = artist.tracks.active | |
| puts "tracks : #{tracks.count}" | |
| puts "streams : #{tracks.map {|t| Track.hits[t.id]}.sum}" | |
| downloads = Filing.joins(:folder).where("filings.track_id in (?) and folders.name = 'Downloads'", tracks.map(&:id)).count | |
| puts "downloads : #{downloads}" | |
| licensings = WorkTrack.where(track_id: tracks.map(&:id)).count | |
| puts "licensings : #{licensings}" | |
| puts "total : #{licensings + downloads}" | |
| genres = artist.tracks.active.map{|t| t.genres.map(&:full_name)}.flatten | |
| b = Hash.new(0) | |
| genres.each {|g| b[g] += 1 } | |
| b.map do |g,c| | |
| ("%02d" % c) + " -> #{g}" | |
| end.sort.reverse.each {|l| puts l} | |
| puts "---------------------------------" | |
| moods = artist.tracks.active.map{|t| t.moods.map(&:name)}.flatten | |
| b = Hash.new(0) | |
| moods.each {|g| b[g] += 1 } | |
| b.map do |g,c| | |
| ("%02d" % c) + " -> #{g}" | |
| end.sort.reverse.each {|l| puts l} | |
| puts "---------------------------------" | |
| end | |
| nil | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment