<commit_before># frozen_string_literal: true
class Rating::Strictness
  attr_reader :season

  def initialize(season = Season.current)
    @season = season
  end

  def ratings
    @ratings ||= Rating
                  .joins('JOIN applications ON ratings.rateable_id = applications.id')
                  .where(rateable_type: 'Application')
                  .where('applications.season_id' => season.id)
  end

  # @return [Array<Integer>] list of IDs for all rated applications
  def application_ids
    @application_ids ||= ratings.map(&:rateable_id)
  end

  # @return [Array<Application>] all rated applications
  def applications
    @applications ||= Application.includes(:ratings).where(id: application_ids)
  end

  # @return [Array<Integer>] list of IDs for all participating reviewers
  def reviewer_ids
    @reviewer_ids ||= ratings.map(&:user_id).uniq
  end

  # @return [Float] overall rating average
  def average_points_per_reviewer
    @average_points_per_reviewer ||= ratings.sum(&:points) / reviewer_ids.size.to_f
  end

  # Returns a datastructure that maps each application to its
  # strictness-adjusted rating points.
  #
  # @return [Hash{Integer => Float}]
  def adjusted_points_for_applications
    applications.each_with_object({}) do |application, map|
      map[application.id] = application.ratings.sum(&strictness) / application.ratings.count.to_f
    end
  end

  # Returns a datastructure that maps each reviewer_id to their individually
  # calculated strictness.
  #
  # @return [Hash{Integer => Float}]
  def strictness_per_reviewer
    @strictness_per_reviewer ||= reviewer_ids.each_with_object({}) do |id, map|
      map[id] = average_points_per_reviewer / individual_points_for_reviewer(id)
    end
  end
  alias to_h strictness_per_reviewer

  private

  def strictness
    ->(rating) { (rating.points * strictness_per_reviewer[rating.user_id]).to_f }<commit_msg>Reduce public API<commit_after># frozen_string_literal: true
class Rating::Strictness
  attr_reader :season

  def initialize(season = Season.current)
    @season = season
  end

  # Returns a datastructure that maps each application to its
  # strictness-adjusted rating points.
  #
  # @return [Hash{Integer => Float}]
  def adjusted_points_for_applications
    applications.each_with_object({}) do |application, map|
      map[application.id] = application.ratings.sum(&strictness) / application.ratings.count.to_f
    end
  end

  private

  def ratings
    @ratings ||= Rating
                  .joins('JOIN applications ON ratings.rateable_id = applications.id')
                  .where(rateable_type: 'Application')
                  .where('applications.season_id' => season.id)
  end

  # @return [Array<Integer>] list of IDs for all rated applications
  def application_ids
    @application_ids ||= ratings.map(&:rateable_id)
  end

  # @return [Array<Application>] all rated applications
  def applications
    @applications ||= Application.includes(:ratings).where(id: application_ids)
  end

  # @return [Array<Integer>] list of IDs for all participating reviewers
  def reviewer_ids
    @reviewer_ids ||= ratings.map(&:user_id).uniq
  end

  # @return [Float] overall rating average
  def average_points_per_reviewer
    @average_points_per_reviewer ||= ratings.sum(&:points) / reviewer_ids.size.to_f
  end

  # Returns a datastructure that maps each reviewer_id to their individually
  # calculated strictness.
  #
  # @return [Hash{Integer => Float}]
  def strictness_per_reviewer
    @strictness_per_reviewer ||= reviewer_ids.each_with_object({}) do |id, map|
      map[id] = average_points_per_reviewer / individual_points_for_reviewer(id)
    end
  end
  alias to_h strictness_per_reviewer

  def strictness
    ->(rating) { (rating.points * strictness_per_reviewer[rating.user_id]).to_f }
{'fraction_non_alphanumeric': 0.09648662821185107, 'fraction_numerical': 0.0, 'mean_word_length': 3.897304236200257, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4016397', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1141, 'n_words': 280}