<commit_before>class SubmissionsController < ApplicationController
  load_and_authorize_resource :course
  load_and_authorize_resource :mission, through: :course
  load_and_authorize_resource :submission, through: :mission

  skip_load_and_authorize_resource :submission, only: :listall
  skip_load_and_authorize_resource :mission, only: :listall

  before_filter :load_general_course_data, only: [:index, :listall, :show, :new, :create]

  def listall
    @unseen = []
    @sbms = @course.submissions.accessible_by(current_ability) +
            @course.training_submissions.accessible_by(current_ability) +
            @course.quiz_submissions.accessible_by(current_ability)

    if curr_user_course.id
      @unseen = @sbms - curr_user_course.get_seen_sbms
      @unseen.each do |sbm|
        curr_user_course.mark_as_seen(sbm)
      end
    end
    @sbms = @sbms.sort_by(&:created_at).reverse
  end

  def show
    @qadata = {}

    if params[:grading_id]
      @grading = SubmissionGrading.find(grading_id)
    else
      @grading = @submission.final_grading
    end

    @mission.questions.each_with_index do |q, i|
      @qadata[q.id] = { q: q, i: i + 1 }
    end

    @submission.std_answers.each do |sa|
      @qadata[sa.question.id][:a] = sa
    end

    if @grading
      @grading.answer_gradings.each do |ag|
        @qadata[ag.student_answer.question_id][:g] = ag
      end
    end

    puts @qadata

    respond_to do |format|
      format.html { render "submissions/show_question" }
    end
  end

  def new
    @questions = @mission.questions
    respond_to do |format|
      format.html
    end
  end

  def create
    @submission.std_course = curr_user_course
    params[:answers].each do |qid, ans|
      @wq = Question.find(qid)
      sa = @submission.std_answers.build({
        text: ans,
      })
      sa.question = @wq
    end
    if @submission.save
      Activity.attempted_asm(curr_user_course, @mission)
      respond_to do |format|
        format.html { redirect_to course_submissions_url(@course),<commit_msg>student answer should record which student he is so that he can comment on it.<commit_after>class SubmissionsController < ApplicationController
  load_and_authorize_resource :course
  load_and_authorize_resource :mission, through: :course
  load_and_authorize_resource :submission, through: :mission

  skip_load_and_authorize_resource :submission, only: :listall
  skip_load_and_authorize_resource :mission, only: :listall

  before_filter :load_general_course_data, only: [:index, :listall, :show, :new, :create]

  def listall
    @unseen = []
    @sbms = @course.submissions.accessible_by(current_ability) +
            @course.training_submissions.accessible_by(current_ability) +
            @course.quiz_submissions.accessible_by(current_ability)

    if curr_user_course.id
      @unseen = @sbms - curr_user_course.get_seen_sbms
      @unseen.each do |sbm|
        curr_user_course.mark_as_seen(sbm)
      end
    end
    @sbms = @sbms.sort_by(&:created_at).reverse
  end

  def show
    @qadata = {}

    if params[:grading_id]
      @grading = SubmissionGrading.find(grading_id)
    else
      @grading = @submission.final_grading
    end

    @mission.questions.each_with_index do |q, i|
      @qadata[q.id] = { q: q, i: i + 1 }
    end

    @submission.std_answers.each do |sa|
      @qadata[sa.question.id][:a] = sa
    end

    if @grading
      @grading.answer_gradings.each do |ag|
        @qadata[ag.student_answer.question_id][:g] = ag
      end
    end

    puts @qadata

    respond_to do |format|
      format.html { render "submissions/show_question" }
    end
  end

  def new
    @questions = @mission.questions
    respond_to do |format|
      format.html
    end
  end

  def create
    @submission.std_course = curr_user_course
    params[:answers].each do |qid, ans|
      @wq = Question.find(qid)
      sa = @submission.std_answers.build({
        text: ans,
      })
      sa.question = @wq
      sa.student = current_user
    end
    if @submission.save
      Activity.attempted_asm(curr_user_course, @mission)
      respond_to do |format|
        format.html { redirect_to course_submissions_url(@course),
{'fraction_non_alphanumeric': 0.0969595403399569, 'fraction_numerical': 0.00047881254488867607, 'mean_word_length': 3.096078431372549, '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': '6875738', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1411, 'n_words': 283}