<commit_before>class PeerReviewsController < ApplicationController
  include GroupsHelper
  include PeerReviewHelper
  include RandomAssignHelper

  before_action :set_peer_review, only: [:show, :edit, :update, :destroy]

  before_filter :authorize_only_for_admin, except: [:show_reviews, :show_result]
  before_filter :authorize_for_user, only: [:show_reviews, :show_result]

  def index
    @assignment = Assignment.find(params[:assignment_id])
    @section_column = ''
    if Section.all.size > 0
      @section_column = "{
        id: 'section',
        content: '#{t('summaries_index.section')}',
        sortable: true
      },"
    end
  end

  def populate
    @assignment = Assignment.find(params[:assignment_id])

    reviewer_groups = get_groupings_table_info()
    reviewee_groups = get_groupings_table_info(@assignment.parent_assignment)

    reviewee_to_reviewers_map = create_map_reviewee_to_reviewers(reviewer_groups, reviewee_groups)
    id_to_group_names_map = create_map_group_id_to_name(reviewer_groups, reviewee_groups)
    num_reviews_map = PeerReview.group(:reviewer_id).having(reviewer_id: reviewer_groups.map { |g| g['id'] }).count

    render json: [reviewer_groups, reviewee_groups, reviewee_to_reviewers_map,
                  id_to_group_names_map, num_reviews_map]
  end

  def show_reviews
    assignment = Assignment.find(params[:assignment_id])
    # grab the first peer review of the reviewee group
    pr = @current_user.grouping_for(assignment.id).peer_reviews.first

    if !pr.nil?<commit_msg>Added redirection if switching from PR tab to a non-PR assignment<commit_after>class PeerReviewsController < ApplicationController
  include GroupsHelper
  include PeerReviewHelper
  include RandomAssignHelper

  before_action :set_peer_review, only: [:show, :edit, :update, :destroy]

  before_filter :authorize_only_for_admin, except: [:show_reviews, :show_result]
  before_filter :authorize_for_user, only: [:show_reviews, :show_result]

  def index
    @assignment = Assignment.find(params[:assignment_id])
    
    unless @assignment.is_peer_review?
      redirect_to edit_assignment_path(@assignment)
      return
    end

    @section_column = ''
    if Section.all.size > 0
      @section_column = "{
        id: 'section',
        content: '#{t('summaries_index.section')}',
        sortable: true
      },"
    end
  end

  def populate
    @assignment = Assignment.find(params[:assignment_id])

    reviewer_groups = get_groupings_table_info()
    reviewee_groups = get_groupings_table_info(@assignment.parent_assignment)

    reviewee_to_reviewers_map = create_map_reviewee_to_reviewers(reviewer_groups, reviewee_groups)
    id_to_group_names_map = create_map_group_id_to_name(reviewer_groups, reviewee_groups)
    num_reviews_map = PeerReview.group(:reviewer_id).having(reviewer_id: reviewer_groups.map { |g| g['id'] }).count

    render json: [reviewer_groups, reviewee_groups, reviewee_to_reviewers_map,
                  id_to_group_names_map, num_reviews_map]
  end

  def show_reviews
    assignment = Assignment.find(params[:assignment_id])
    # grab the first peer review of the reviewee group
    pr = @current_user.grouping_for(assignment.id).peer_reviews.first

    if !pr.nil?
{'fraction_non_alphanumeric': 0.08879950495049505, 'fraction_numerical': 0.0006188118811881188, 'mean_word_length': 4.6031195840554595, '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': '6803943', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1069, 'n_words': 191}