<commit_before>class ReviewableSolutionFinder
  def initialize(challenge, user)
    @challenge = challenge
    @user = user
  end


  def find_review
    started_reviews = @challenge.reviews.where(reviewer: @user, status: :draft)
    return started_reviews.first unless started_reviews.empty?

    reviewed_solutions = @challenge.reviews.where(reviewer: @user).map(&:solution)
    reviewable_solutions = @challenge.solutions.where(status: :final).where.not(id: reviewed_solutions.map(&:id), author: @user)

    unless reviewable_solutions.empty?
      solution = reviewable_solutions.sample
      PeerReview::Review.create(solution: solution, reviewer: @user, status: :draft)
    else
      nil
    end
  end
end<commit_msg>PeerReviews now prioritize less reviewed solutions<commit_after>class ReviewableSolutionFinder
  def initialize(challenge, user)
    @challenge = challenge
    @user = user
  end


  def find_review
    started_reviews = @challenge.reviews.where(reviewer: @user, status: :draft)
    return started_reviews.first unless started_reviews.empty?

    reviewed_solutions = @challenge.reviews.where(reviewer: @user).map(&:solution)
    reviewable_solutions = @challenge.solutions.where(status: :final).where.not(id: reviewed_solutions.map(&:id), author: @user)

    unless reviewable_solutions.empty?
      solution = reviewable_solutions.sort { |sol| sol.reviews.count }.first
      PeerReview::Review.create(solution: solution, reviewer: @user, status: :draft)
    else
      nil
    end
  end
end
{'fraction_non_alphanumeric': 0.1021753460777851, 'fraction_numerical': 0.0, 'mean_word_length': 4.52, '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': '6876641', 'n_tokens_mistral': 486, 'n_tokens_neox': 449, 'n_words': 97}