<commit_before>class GradesController < ApplicationController
  helper :file
  helper :submitted_content
  helper :penalty
  include PenaltyHelper

  def action_allowed?
    case params[:action]
    when 'view_my_scores'
      ['Instructor',
       'Teaching Assistant',
       'Administrator',
       'Super-Administrator',
       'Student'].include? current_role_name and are_needed_authorizations_present?
    else
      ['Instructor',
       'Teaching Assistant',
       'Administrator',
       'Super-Administrator'].include? current_role_name
    end
  end

  #the view grading report provides the instructor with an overall view of all the grades for
  #an assignment. It lists all participants of an assignment and all the reviews they received.
  #It also gives a final score, which is an average of all the reviews and greatest difference
  #in the scores of all the reviews.
  def view
    @assignment = Assignment.find(params[:id])
    @questions = {}
    questionnaires = @assignment.questionnaires_with_questions

    if @assignment.varying_rubrics_by_round?
      questionnaires.each {
        |questionnaire|
        round = AssignmentQuestionnaire.find_by_assignment_id_and_questionnaire_id(@assignment.id, questionnaire.id).used_in_round
        if(round!=nil)
          questionnaire_symbol = (questionnaire.symbol.to_s+round.to_s).to_sym
        else
          questionnaire_symbol = questionnaire.symbol
        end
        @questions[questionnaire_symbol] = questionnaire.questions
      }
    else      #if this assignment does not have "varying rubric by rounds" feature
      questionnaires.each {
        |questionnaire|
        @questions[questionnaire.symbol] = questionnaire.questions
      }
    end
    @scores = @assignment.scores(@questions)
    averages = calculate_average_vector(@scores)
    @average_chart =  bar_chart(averages,300,100,5)
    @avg_of_avg = mean(averages)
    calculate_all_penalties(@assignment.id)
  end

  def view_my_scores
    @participant = AssignmentParticipant.find(params[:id])
    @team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)
    return if redirect_when_disallowed
    @assignment = @participant.assignment
    @questions = {}
    questionnaires = @assignment.questionnaires
    questionnaires.each do |questionnaire|
      round = AssignmentQuestionnaire.where(assignment_id: @assignment.id, questionnaire_id:questionnaire.id).first.used_in_round
      if(round!=nil)
        questionnaire_symbol = (questionnaire.symbol.to_s+round.to_s).to_sym
      else
        questionnaire_symbol = questionnaire.symbol
      end
      @questions[questionnaire_symbol] = questionnaire.questions
    end

    rmaps = ReviewResponseMap.where(reviewee_id: @team_id, reviewed_object_id: @participant.parent_id)
    rmaps.find_each do |rmap|
      rmap.update_attribute :notification_accepted, true
    end

    rmaps = ReviewResponseMap.where(reviewer_id: @participant.id, reviewed_object_id: @participant.parent_id)
    rmaps.find_each do |rmap|
      mmaps = MetareviewResponseMap.where(reviewee_id: rmap.reviewer_id, reviewed_object_id: rmap.map_id)
      mmaps.find_each do |mmap|
        mmap.update_attribute :notification_accepted, true
      end
    end

    @topic = @participant.topic
    @pscore = @participant.scores(@questions)
    make_chart
    @topic_id = SignedUpTeam.topic_id(@participant.assignment.id, @participant.user_id)<commit_msg>Fix participant.topic_id (this has been removed) from grades controller.<commit_after>class GradesController < ApplicationController
  helper :file
  helper :submitted_content
  helper :penalty
  include PenaltyHelper

  def action_allowed?
    case params[:action]
    when 'view_my_scores'
      ['Instructor',
       'Teaching Assistant',
       'Administrator',
       'Super-Administrator',
       'Student'].include? current_role_name and are_needed_authorizations_present?
    else
      ['Instructor',
       'Teaching Assistant',
       'Administrator',
       'Super-Administrator'].include? current_role_name
    end
  end

  #the view grading report provides the instructor with an overall view of all the grades for
  #an assignment. It lists all participants of an assignment and all the reviews they received.
  #It also gives a final score, which is an average of all the reviews and greatest difference
  #in the scores of all the reviews.
  def view
    @assignment = Assignment.find(params[:id])
    @questions = {}
    questionnaires = @assignment.questionnaires_with_questions

    if @assignment.varying_rubrics_by_round?
      questionnaires.each {
        |questionnaire|
        round = AssignmentQuestionnaire.find_by_assignment_id_and_questionnaire_id(@assignment.id, questionnaire.id).used_in_round
        if(round!=nil)
          questionnaire_symbol = (questionnaire.symbol.to_s+round.to_s).to_sym
        else
          questionnaire_symbol = questionnaire.symbol
        end
        @questions[questionnaire_symbol] = questionnaire.questions
      }
    else      #if this assignment does not have "varying rubric by rounds" feature
      questionnaires.each {
        |questionnaire|
        @questions[questionnaire.symbol] = questionnaire.questions
      }
    end
    @scores = @assignment.scores(@questions)
    averages = calculate_average_vector(@scores)
    @average_chart =  bar_chart(averages,300,100,5)
    @avg_of_avg = mean(averages)
    calculate_all_penalties(@assignment.id)
  end

  def view_my_scores
    @participant = AssignmentParticipant.find(params[:id])
    @team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)
    return if redirect_when_disallowed
    @assignment = @participant.assignment
    @questions = {} # A hash containing all the questions in all the questionnaires used in this assignment
    questionnaires = @assignment.questionnaires
    questionnaires.each do |questionnaire|
      round = AssignmentQuestionnaire.where(assignment_id: @assignment.id, questionnaire_id:questionnaire.id).first.used_in_round
      if(round!=nil)
        questionnaire_symbol = (questionnaire.symbol.to_s+round.to_s).to_sym
      else
        questionnaire_symbol = questionnaire.symbol
      end
      @questions[questionnaire_symbol] = questionnaire.questions
    end

    rmaps = ReviewResponseMap.where(reviewee_id: @team_id, reviewed_object_id: @participant.parent_id)
    rmaps.find_each do |rmap|
      rmap.update_attribute :notification_accepted, true
    end

    rmaps = ReviewResponseMap.where(reviewer_id: @participant.id, reviewed_object_id: @participant.parent_id)
    rmaps.find_each do |rmap|
      mmaps = MetareviewResponseMap.where(reviewee_id: rmap.reviewer_id, reviewed_object_id: rmap.map_id)
      mmaps.find_each do |mmap|
        mmap.update_attribute :notification_accepted, true
      end
    end

    @topic = SignedUpTeam.topic_id_by_team_id (@team_id)
    @pscore = @participant.scores(@questions)
    make_chart
    @topic_id = SignedUpTeam.topic_id(@participant.assignment.id, @participant.user_id)
{'fraction_non_alphanumeric': 0.0799943165672066, 'fraction_numerical': 0.0019892014776925265, 'mean_word_length': 3.7528696826468604, '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': '5432651', 'n_tokens_mistral': 2175, 'n_tokens_neox': 2050, 'n_words': 448}