<commit_before>class ReviewOfReviewController < ApplicationController
  helper :wiki
  # This method returns the 
  def get_student_directory(directory_path, directory_num)
    # This assumed that the directory num has already been set
    return RAILS_ROOT + "/pg_data/" + directory_path + "/" + directory_num
  end
  
  def find_review_phase(due_dates)
    # Find the next due date (after the current date/time), and then find the type of deadline it is.
    @very_last_due_date = DueDate.find(:all,:order => "due_at DESC", :limit =>1)
    next_due_date = @very_last_due_date[0]
    for due_date in due_dates
      if due_date.due_at > Time.now
        if due_date.due_at < next_due_date.due_at
          next_due_date = due_date
        end
      end
    end
    @review_phase = next_due_date.deadline_type_id;
    return @review_phase
  end   
  
  def list_reviews
    @reviewer_id = session[:user].id
    @assignment_id = params[:id]
    @questions = Question.find(:all,:conditions => ["questionnaire_id = ?", Assignment.find(@assignment_id).review_questionnaire_id])
    @review_mapping = ReviewMapping.find(:all,:conditions => ["reviewer_id = ? and assignment_id = ?", @reviewer_id, @assignment_id])     
  end
  
  def new
    #    @ror_mapping = ReviewOfReviewMapping.find(params[:id])
    @ror_mapping = 
    begin 
      ReviewOfReviewMapping.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      nil    
    end
    
    # if we did'nt find the ror mapping, we must be doing dynamic reviewer assignment
    if (@ror_mapping == nil)    
      
      @assignment = Assignment.find(params[:assignment])
      if (@assignment.team_assignment)
        rm = TeamReviewOfReviewMappingManager.new
      else
        rm = IndividualReviewOfReviewMappingManager.new
      end
      @ror_mapping = rm.generateReviewOfReviewMapping(@assignment, session[:user].id)
      
      if (@ror_mapping == nil)
        flash[:notice] = 'There are no reviews available for review available at this time. Please check back later.'
        redirect_to :controller => 'review', :action => 'list_reviews', :id => @assignment.id 
        return
      end 
      
      # record the timeout value in the session so we can verify that we still own this mapping when we submit it
      session[:review_of_review_timeout] = @ror_mapping.timeout.to_s()
    end
    
    @user = session[:user].id
    @eligible_review = Review.find(@ror_mapping.review_id)
    begin   
      review_mapping = ReviewMapping.find(@ror_mapping.review_mapping_id)
      @eligible_review_mapping = review_mapping
      @links,@review,@mapping_id,@review_scores,@mapping,@assgt,@author,@questions,@questionnaire,@author_first_user_id,@team_members,@author_name,@max,@min,@files,@direc = ReviewController.show_review(@eligible_review.id)
      @current_folder = DisplayOption.new
      @current_folder.name = "/"
      if params[:current_folder]
        @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])
      end
      
      if params['fname']
        view_submitted_file(@current_folder,@author)
      end
      
      
      @ror_questions = Question.find(:all,:conditions => ["questionnaire_id = ?", @assgt.review_of_review_questionnaire_id]) 
      @ror_questionnaire = Questionnaire.find(@assgt.review_of_review_questionnaire_id)
      @ror_max = @ror_questionnaire.max_question_score
      @ror_min = @ror_questionnaire.min_question_score
    rescue
      flash[:notice] = "Review of review cannot be created now. Cause: "+ $!
      redirect_to :controller =>'review', :action => 'list_reviews', :id => @ror_mapping.assignment_id
    end
  end
  
  #follows a link
  #needs to be moved to a separate helper function
  def view_submitted_file(current_folder,author)
    folder_name = FileHelper::sanitize_folder(current_folder.name)
    file_name = FileHelper::sanitize_filename(params['fname'])
    file_split = file_name.split('.')
    if file_split.length > 1 and (file_split[1] == 'htm' or file_split[1] == 'html')
      send_file(RAILS_ROOT + "/pg_data/" + author.assignment.directory_path + "/" + @author.directory_num.to_s + folder_name + "/" + file_name, :type => Mime::HTML.to_s, :disposition => 'inline') 
    else
      send_file(RAILS_ROOT + "/pg_data/" + author.assignment.directory_path + "/" + @author.directory_num.to_s + folder_name + "/" + file_name) 
    end
  end
  
  def get_student_directory(directory_path, directory_num)
    # This assumed that the directory num has already been set
    return RAILS_ROOT + "/pg_data/" + directory_path + "/" + directory_num
  end
  
  def get_submitted_file_list(direc,author,files)
    if(author.directory_num)
      direc = RAILS_ROOT + "/pg_data/" + author.assignment.directory_path + "/" + author.directory_num.to_s
      temp_files = Dir[direc + "/*"]
      for file in temp_files
        if not File.directory?(Dir.pwd + "/" + file) then
          files << file
        end
      end
    end
    return files
  end
  
  def initialize_ror
    @ror_map_id = ReviewOfReview.find(params[:id]).review_of_review_mapping_id
    @review_mapping_id = ReviewOfReviewMapping.find(@ror_map_id).review_mapping_id
    @review = Review.find_by_review_mapping_id(@review_mapping_id)
    @links,@review,@mapping_id,@review_scores,@mapping,@assgt,@author,@questions,@questionnaire,@author_first_user_id,@team_members,@author_name,@max,@min,@current_folder,@files,@direc = ReviewController.process_review(@review.id,params[:current_folder])
    if @assgt.team_assignment 
      @author_first_user_id = TeamsUser.find(:first,:conditions => ["team_id=?", @mapping.team_id]).user_id
      @team_members = TeamsUser.find(:all,:conditions => ["team_id=?", @mapping.team_id])
      @author_name = User.find(@author_first_user_id).name;
      @author = Participant.find(:first,:conditions => ["user_id = ? AND parent_id = ?", @author_first_user_id, @mapping.assignment_id])
    else
      @author_name = User.find(@mapping.author_id).name
      @author = Participant.find(:first,:conditions => ["user_id = ? AND parent_id = ?", @mapping.author_id, @mapping.assignment_id])
    end
    
    @max = @questionnaire.max_question_score
    @min = @questionnaire.min_question_score 
    @current_folder = DisplayOption.new
    @current_folder.name = "/"
    if params[:current_folder]
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])
    end
    if params['fname']
      view_submitted_file(@current_folder,@author)
    end   
    @review_of_review = ReviewOfReview.find(params[:id])
    @ror_review_scores = @review_of_review.review_of_review_scores<commit_msg>changed process_review to show review<commit_after>class ReviewOfReviewController < ApplicationController
  helper :wiki
  # This method returns the 
  def get_student_directory(directory_path, directory_num)
    # This assumed that the directory num has already been set
    return RAILS_ROOT + "/pg_data/" + directory_path + "/" + directory_num
  end
  
  def find_review_phase(due_dates)
    # Find the next due date (after the current date/time), and then find the type of deadline it is.
    @very_last_due_date = DueDate.find(:all,:order => "due_at DESC", :limit =>1)
    next_due_date = @very_last_due_date[0]
    for due_date in due_dates
      if due_date.due_at > Time.now
        if due_date.due_at < next_due_date.due_at
          next_due_date = due_date
        end
      end
    end
    @review_phase = next_due_date.deadline_type_id;
    return @review_phase
  end   
  
  def list_reviews
    @reviewer_id = session[:user].id
    @assignment_id = params[:id]
    @questions = Question.find(:all,:conditions => ["questionnaire_id = ?", Assignment.find(@assignment_id).review_questionnaire_id])
    @review_mapping = ReviewMapping.find(:all,:conditions => ["reviewer_id = ? and assignment_id = ?", @reviewer_id, @assignment_id])     
  end
  
  def new
    #    @ror_mapping = ReviewOfReviewMapping.find(params[:id])
    @ror_mapping = 
    begin 
      ReviewOfReviewMapping.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      nil    
    end
    
    # if we did'nt find the ror mapping, we must be doing dynamic reviewer assignment
    if (@ror_mapping == nil)    
      
      @assignment = Assignment.find(params[:assignment])
      if (@assignment.team_assignment)
        rm = TeamReviewOfReviewMappingManager.new
      else
        rm = IndividualReviewOfReviewMappingManager.new
      end
      @ror_mapping = rm.generateReviewOfReviewMapping(@assignment, session[:user].id)
      
      if (@ror_mapping == nil)
        flash[:notice] = 'There are no reviews available for review available at this time. Please check back later.'
        redirect_to :controller => 'review', :action => 'list_reviews', :id => @assignment.id 
        return
      end 
      
      # record the timeout value in the session so we can verify that we still own this mapping when we submit it
      session[:review_of_review_timeout] = @ror_mapping.timeout.to_s()
    end
    
    @user = session[:user].id
    @eligible_review = Review.find(@ror_mapping.review_id)
    begin   
      review_mapping = ReviewMapping.find(@ror_mapping.review_mapping_id)
      @eligible_review_mapping = review_mapping
      @links,@review,@mapping_id,@review_scores,@mapping,@assgt,@author,@questions,@questionnaire,@author_first_user_id,@team_members,@author_name,@max,@min,@files,@direc = ReviewController.show_review(@eligible_review.id)
      @current_folder = DisplayOption.new
      @current_folder.name = "/"
      if params[:current_folder]
        @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])
      end
      
      if params['fname']
        view_submitted_file(@current_folder,@author)
      end
      
      
      @ror_questions = Question.find(:all,:conditions => ["questionnaire_id = ?", @assgt.review_of_review_questionnaire_id]) 
      @ror_questionnaire = Questionnaire.find(@assgt.review_of_review_questionnaire_id)
      @ror_max = @ror_questionnaire.max_question_score
      @ror_min = @ror_questionnaire.min_question_score
    rescue
      flash[:notice] = "Review of review cannot be created now. Cause: "+ $!
      redirect_to :controller =>'review', :action => 'list_reviews', :id => @ror_mapping.assignment_id
    end
  end
  
  #follows a link
  #needs to be moved to a separate helper function
  def view_submitted_file(current_folder,author)
    folder_name = FileHelper::sanitize_folder(current_folder.name)
    file_name = FileHelper::sanitize_filename(params['fname'])
    file_split = file_name.split('.')
    if file_split.length > 1 and (file_split[1] == 'htm' or file_split[1] == 'html')
      send_file(RAILS_ROOT + "/pg_data/" + author.assignment.directory_path + "/" + @author.directory_num.to_s + folder_name + "/" + file_name, :type => Mime::HTML.to_s, :disposition => 'inline') 
    else
      send_file(RAILS_ROOT + "/pg_data/" + author.assignment.directory_path + "/" + @author.directory_num.to_s + folder_name + "/" + file_name) 
    end
  end
  
  def get_student_directory(directory_path, directory_num)
    # This assumed that the directory num has already been set
    return RAILS_ROOT + "/pg_data/" + directory_path + "/" + directory_num
  end
  
  def get_submitted_file_list(direc,author,files)
    if(author.directory_num)
      direc = RAILS_ROOT + "/pg_data/" + author.assignment.directory_path + "/" + author.directory_num.to_s
      temp_files = Dir[direc + "/*"]
      for file in temp_files
        if not File.directory?(Dir.pwd + "/" + file) then
          files << file
        end
      end
    end
    return files
  end
  
  def initialize_ror
    @ror_map_id = ReviewOfReview.find(params[:id]).review_of_review_mapping_id
    @review_mapping_id = ReviewOfReviewMapping.find(@ror_map_id).review_mapping_id
    @review = Review.find_by_review_mapping_id(@review_mapping_id)
    @links,@review,@mapping_id,@review_scores,@mapping,@assgt,@author,@questions,@questionnaire,@author_first_user_id,@team_members,@author_name,@max,@min,@current_folder,@files,@direc = ReviewController.show_review(@review.id,params[:current_folder])
    if @assgt.team_assignment 
      @author_first_user_id = TeamsUser.find(:first,:conditions => ["team_id=?", @mapping.team_id]).user_id
      @team_members = TeamsUser.find(:all,:conditions => ["team_id=?", @mapping.team_id])
      @author_name = User.find(@author_first_user_id).name;
      @author = Participant.find(:first,:conditions => ["user_id = ? AND parent_id = ?", @author_first_user_id, @mapping.assignment_id])
    else
      @author_name = User.find(@mapping.author_id).name
      @author = Participant.find(:first,:conditions => ["user_id = ? AND parent_id = ?", @mapping.author_id, @mapping.assignment_id])
    end
    
    @max = @questionnaire.max_question_score
    @min = @questionnaire.min_question_score 
    @current_folder = DisplayOption.new
    @current_folder.name = "/"
    if params[:current_folder]
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])
    end
    if params['fname']
      view_submitted_file(@current_folder,@author)
    end   
    @review_of_review = ReviewOfReview.find(params[:id])
    @ror_review_scores = @review_of_review.review_of_review_scores
{'fraction_non_alphanumeric': 0.11257233035244608, 'fraction_numerical': 0.0007514841812579845, 'mean_word_length': 3.8339992735197965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '6605135', 'n_tokens_mistral': 4259, 'n_tokens_neox': 4222, 'n_words': 791}