<commit_before>class Content

  include Mongoid::Document

  def author_with_anonymity(attr=nil, attr_when_anonymous=nil)
    if not attr
      (anonymous || anonymous_to_peers) ? nil : author
    else
      (anonymous || anonymous_to_peers) ? attr_when_anonymous : author.send(attr)
    end
  end

  def self.prolific_metric what
    #take a hash of criteria (where) and return a hash of hashes
    #course => user => count

    count = 10

    contributors = {}

    map =  "function(){emit(this.author_id,1)}"
    reduce  =  "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"

    contributors = []
    self.where(what).map_reduce(map,reduce).out(replace: "results").each do |d|
      contributors << d
    end

    #now sort and limit them

    #first sort destructively
    contributors.sort! {|a,b| -a["value"] <=> -b["value"]}
    #then trim it
    contributors = contributors[0..(count - 1)]

    contributors

  end
  
  def self.summary what
    #take a hash of criteria (where) and return a hash of hashes
    #of total users, votes, comments, endorsements, 
    
    answer = {}
    vote_count = 0
    thread_count = 0
    comment_count = 0
    contributors = []
    content = self.where(what)
    
    content.each do |c|
      contributors << c.author_id
      contributors << c["votes"]["up"]
      contributors << c["votes"]["down"]
      votes += c["votes"]["count"]
      if c._type == "ContentThread"
        thread_count += 1
      elsif c._type == "Comment"
        comment_count += 1
      end
    end

    #uniquify contributors
    contributors = contributors.uniq
    
    #assemble the answer and ship
    
    answer["vote_count"] = vote_count
    answer["thread_count"] = vote_count
    answer["comment_count"] = vote_count
    answer["contributor_count"] = contributor_count
    
    answer
  end
  
  
  
end<commit_msg>bug fix<commit_after>class Content

  include Mongoid::Document

  def author_with_anonymity(attr=nil, attr_when_anonymous=nil)
    if not attr
      (anonymous || anonymous_to_peers) ? nil : author
    else
      (anonymous || anonymous_to_peers) ? attr_when_anonymous : author.send(attr)
    end
  end

  def self.prolific_metric what
    #take a hash of criteria (where) and return a hash of hashes
    #course => user => count

    count = 10

    contributors = {}

    map =  "function(){emit(this.author_id,1)}"
    reduce  =  "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"

    contributors = []
    self.where(what).map_reduce(map,reduce).out(replace: "results").each do |d|
      contributors << d
    end

    #now sort and limit them

    #first sort destructively
    contributors.sort! {|a,b| -a["value"] <=> -b["value"]}
    #then trim it
    contributors = contributors[0..(count - 1)]

    contributors

  end
  
  def self.summary what
    #take a hash of criteria (where) and return a hash of hashes
    #of total users, votes, comments, endorsements, 
    
    answer = {}
    vote_count = 0
    thread_count = 0
    comment_count = 0
    contributors = []
    content = self.where(what)
    
    content.each do |c|
      contributors << c.author_id
      contributors << c["votes"]["up"]
      contributors << c["votes"]["down"]
      vote_count += c["votes"]["count"]
      if c._type == "ContentThread"
        thread_count += 1
      elsif c._type == "Comment"
        comment_count += 1
      end
    end

    #uniquify contributors
    contributors = contributors.uniq
    
    #assemble the answer and ship
    
    answer["vote_count"] = vote_count
    answer["thread_count"] = vote_count
    answer["comment_count"] = vote_count
    answer["contributor_count"] = contributor_count
    
    answer
  end
  
  
  
end
{'fraction_non_alphanumeric': 0.11420982735723771, 'fraction_numerical': 0.0058432934926958835, 'mean_word_length': 2.684931506849315, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1409671', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1204, 'n_words': 320}