<commit_before>class CompetitionsController < ApplicationController
  load_and_authorize_resource

  def index
  end

  def new
  end

  def create
    if @competition.save
      flash[:success] = t("competition.add.success")
      redirect_to @competition
    else
      render :new
    end
  end

  def show
    @competition = Competition.includes(:brackets, teams: [:rides]).find(params[:id])
    calculator = ParticipationCalculator.new(@competition)
    team_participations = calculator.team_participations
    member_participations = calculator.member_participations
    @brackets = Hash[@competition.brackets.map { |bracket|
      range = bracket.lower_limit..bracket.upper_limit
      tps = team_participations.select { |tp| range.include?(tp.team.business_size) }
      mps = member_participations.select { |mp| range.include?(mp.team.business_size) }
      [
        bracket,
        {
          teams: tps.sort_by { |tp| -tp.participation_percent },
          members: mps.sort_by { |mp| -mp.participation_percent }.first(10)
        }
      ]
    }]
  end

  def edit
    @bracket = Bracket.new
  end

  def update
    if @competition.update_attributes(params[:competition])
      flash[:success] = t("competition.edit.success")
      redirect_to @competition
    else
      render :edit<commit_msg>Eager load members and rides on leaderboard<commit_after>class CompetitionsController < ApplicationController
  load_and_authorize_resource

  def index
  end

  def new
  end

  def create
    if @competition.save
      flash[:success] = t("competition.add.success")
      redirect_to @competition
    else
      render :new
    end
  end

  def show
    @competition = Competition.includes(:brackets, teams: [:rides, { members: [:rides] }]).find(params[:id])
    calculator = ParticipationCalculator.new(@competition)
    team_participations = calculator.team_participations
    member_participations = calculator.member_participations
    @brackets = Hash[@competition.brackets.map { |bracket|
      range = bracket.lower_limit..bracket.upper_limit
      tps = team_participations.select { |tp| range.include?(tp.team.business_size) }
      mps = member_participations.select { |mp| range.include?(mp.team.business_size) }
      [
        bracket,
        {
          teams: tps.sort_by { |tp| -tp.participation_percent },
          members: mps.sort_by { |mp| -mp.participation_percent }.first(10)
        }
      ]
    }]
  end

  def edit
    @bracket = Bracket.new
  end

  def update
    if @competition.update_attributes(params[:competition])
      flash[:success] = t("competition.edit.success")
      redirect_to @competition
    else
      render :edit
{'fraction_non_alphanumeric': 0.1005607476635514, 'fraction_numerical': 0.0014953271028037382, 'mean_word_length': 3.110599078341014, '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': '3942294', 'n_tokens_mistral': 851, 'n_tokens_neox': 802, 'n_words': 158}