<commit_before>class Match
  include Mongoid::Document
  include Mongoid::Attributes::Dynamic

  field :matchId, type: Integer
  field :region, type: String
  field :queueType, type: String

  embeds_many :teams
  embeds_many :participants
end<commit_msg>optimize team lookups for a match<commit_after>class Match
  include Mongoid::Document
  include Mongoid::Attributes::Dynamic

  field :matchId, type: Integer
  field :region, type: String
  field :queueType, type: String

  embeds_many :teams
  embeds_many :participants

  def blue_team
    teams[0]
  end

  def red_team
    teams[1]
  end

  def blue_participants
    #participants.where(teamId: 100)
    # optimization: blue team is always the first 5
    participants[0..4]
  end

  def red_participants
    # participants.where(teamId: 200)
    participants[5..9]
  end

  def champions
    participants.map(&:champion)
  end

  def blue_characters
    blue_participants.map(&:champion)
  end

  def red_characters
    red_participants.map(&:champion)
  end

  def winner
    blue_team.winner ? :blue : :red
  end

  def combined_levels
    participants.map(&:estimated_level).reduce(:+)
  end
end
{'fraction_non_alphanumeric': 0.0811044003451251, 'fraction_numerical': 0.011216566005176877, 'mean_word_length': 3.8132780082987554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5141338', 'n_tokens_mistral': 398, 'n_tokens_neox': 377, 'n_words': 100}