<commit_before>class Game < ActiveRecord::Base
  belongs_to :game_type
  has_many :solutions
  has_many :tile_sets
  has_many :tiles, through: :solutions

  validates :name, :game_type, presence: true

  RATINGS = (1..5)

  def no_solutions
    solutions.pluck(:set).count
  end

  def solution_sets
    solutions.includes(:tile).group_by(&:set).map do |set, solutions|
      solutions.map(&:tile)
    end
  end

  def check_solution(solution_tile_ids)
    tile_ids = tiles.pluck(:id)
    max = tile_ids.count

    missing = (tile_ids - solution_tile_ids).size
    redundant = (solution_tile_ids - tile_ids).size

    RATINGS.take(calculate_rating(max, missing, redundant)).last
  end

  def calculate_rating(max, missing, redundant)
    [(correctness(max, missing, redundant) * RATINGS.size).ceil, 1].max
  end

  def correctness(max, missing, redundant)
    (max - missing - redundant) * 1.0 / max
  end
end
<commit_msg>Game distinct fix<commit_after>class Game < ActiveRecord::Base
  belongs_to :game_type
  has_many :solutions
  has_many :tile_sets
  has_many :tiles, through: :solutions

  validates :name, :game_type, presence: true

  RATINGS = (1..5)

  def no_solutions
    solutions.pluck(:set).uniq.count
  end

  def solution_sets
    solutions.includes(:tile).group_by(&:set).map do |set, solutions|
      solutions.map(&:tile)
    end
  end

  def check_solution(solution_tile_ids)
    tile_ids = tiles.pluck(:id)
    max = tile_ids.count

    missing = (tile_ids - solution_tile_ids).size
    redundant = (solution_tile_ids - tile_ids).size

    RATINGS.take(calculate_rating(max, missing, redundant)).last
  end

  def calculate_rating(max, missing, redundant)
    [(correctness(max, missing, redundant) * RATINGS.size).ceil, 1].max
  end

  def correctness(max, missing, redundant)
    (max - missing - redundant) * 1.0 / max
  end
end

{'fraction_non_alphanumeric': 0.10955207771181867, 'fraction_numerical': 0.005396654074473826, 'mean_word_length': 3.753846153846154, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6842147', 'n_tokens_mistral': 674, 'n_tokens_neox': 629, 'n_words': 142}