<commit_before>module Afterburner
  class Medals

    def self.find(id)
      Medal.where(id: id).first
    end

    def self.all
      Medal.all
    end

    def self.all_public
      all_m = Medal.where(secret: false).documents
      return all_m.sort { |a,b| a.sort_key < b.sort_key }
    end

    # returns [ { :medal => Medal, :count => Integer } ]
    def self.awarded_to(user)
      awarded = {}
      for d in user.decorations
        n = d.medal.id
        if awarded[n].nil?
          awarded[n] = {}
          awarded[n][:medal] = d.medal
          awarded[n][:count] = 1
        else
          awarded[n][:count] = awarded[n][:count] + 1
        end
      end
      for m in self.all_public
        if awarded[m.id].nil?
          awarded[m.id] = {}
          awarded[m.id][:medal] = m
          awarded[m.id][:count] = 0
        end
      end
      return awarded.values.sort { |a,b| a[:medal].sort_key <=> b[:medal].sort_key }
    end

  end
end<commit_msg>Move to Medals.all_awarded including secret medals<commit_after>module Afterburner
  class Medals

    def self.find(id)
      Medal.where(id: id).first
    end

    def self.all
      Medal.all
    end

    def self.all_public
      all_m = Medal.where(secret: false).documents
      return all_m.sort { |a,b| a.sort_key < b.sort_key }
    end

    # returns [ { :medal => Medal, :count => Integer } ]
    def self.awarded_to(user)
      awarded = {}
      for d in user.decorations
        n = d.medal.id
        if awarded[n].nil?
          awarded[n] = {}
          awarded[n][:medal] = d.medal
          awarded[n][:count] = 1
        else
          awarded[n][:count] = awarded[n][:count] + 1
        end
      end
      for m in self.all
        if awarded[m.id].nil?
          awarded[m.id] = {}
          awarded[m.id][:medal] = m
          awarded[m.id][:count] = 0
        end
      end
      return awarded.values.sort { |a,b| a[:medal].sort_key <=> b[:medal].sort_key }
    end

  end
end
{'fraction_non_alphanumeric': 0.13133874239350912, 'fraction_numerical': 0.0030425963488843813, 'mean_word_length': 1.806543385490754, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2445997', 'n_tokens_mistral': 704, 'n_tokens_neox': 720, 'n_words': 148}