<commit_before>class PracticeController < ApplicationController
  before_filter :signed_in!
  before_filter :find_assignment

  def show
    @rule = Rule.find(params[:id])
    @next_path = assignment_test_practice_path(@assignment, @assignment.chapter.practice_rules.first, step: params[:step])
  end

  def index
    redirect_to assignment_test_practice_path(@assignment, @assignment.chapter.practice_rules.first, step: params[:step])
  end

  def update
    @rule = Rule.find(params[:id])
    @score.update_attributes! lesson_input => merged_lesson_input
    redirect_to next_lesson
  end

  protected

  def lesson_input
    if params[:step] == "practice"
      :practice_lesson_input
    else
      :review_lesson_input
    end
  end

  def merged_lesson_input
    if params[:step] == "practice"
      @score.practice_lesson_input.merge(params[:lesson_input])
    else
      @score.review_lesson_input.merge(params[:lesson_input])
    end
  end

  def next_id
    if params[:step] == "practice"
      @assignment.chapter.rule_position[@assignment.chapter.rule_position.index(params[:id]) + 1]
    else
      @score.missed_rules[@score.missed_rules.index(@rule) + 1]
    end
  end

  def next_lesson
    if next_id.present?
      assignment_test_practice_path @assignment, next_id, step: params[:step]
    else
      step_after_rules_completed
    end
  end

  def step_after_rules_completed
    if params[:step] == "practice"<commit_msg>bugs in practice lessons<commit_after>class PracticeController < ApplicationController
  before_filter :signed_in!
  before_filter :find_assignment

  def show
    @rule = Rule.find(params[:id])
    @next_path = assignment_test_practice_path(@assignment, @assignment.chapter.practice_rules.first, step: params[:step])
  end

  def index
    if @assignment.chapter.practice_rules.empty?
      redirect_to assignment_test_story_path(@assignment)
    else
      redirect_to assignment_test_practice_path(@assignment, @assignment.chapter.practice_rules.first, step: params[:step])
    end
  end

  def update
    @rule = Rule.find(params[:id])
    @score.update_attributes! lesson_input => merged_lesson_input
    redirect_to next_lesson
  end

  protected

  def lesson_input
    if params[:step] == "practice"
      :practice_lesson_input
    else
      :review_lesson_input
    end
  end

  def merged_lesson_input
    if params[:step] == "practice"
      @score.practice_lesson_input.merge(params[:lesson_input])
    else
      @score.review_lesson_input.merge(params[:lesson_input])
    end
  end

  def next_id
    if params[:step] == "practice"
      return nil unless @assignment.chapter.rule_position.index(params[:id]).present?
      @assignment.chapter.rule_position[@assignment.chapter.rule_position.index(params[:id]) + 1]
    else
      return nil unless @score.missed_rules.index(@rule).present?
      @score.missed_rules[@score.missed_rules.index(@rule) + 1]
    end
  end

  def next_lesson
    if next_id.present?
      assignment_test_practice_path @assignment, next_id, step: params[:step]
    else
      step_after_rules_completed
    end
  end

  def step_after_rules_completed
    if params[:step] == "practice"
{'fraction_non_alphanumeric': 0.09492273730684327, 'fraction_numerical': 0.001261431725007884, 'mean_word_length': 4.003154574132492, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6423633', 'n_tokens_mistral': 1076, 'n_tokens_neox': 994, 'n_words': 188}