<commit_before>module SubmissionsHelper
  
  def find_appropriate_grouping(assignment_id, params)
    if current_user.admin? || current_user.ta?
      return Grouping.find(params[:grouping_id])
    else
      return current_user.accepted_grouping_for(assignment_id)
    end
  end
  
  def construct_file_manager_dir_table_row(directory_name, directory)
    table_row = {}
    table_row[:id] = directory.id
    table_row[:filter_table_row_contents] = render_to_string :partial => 'submissions/table_row/directory_table_row', :locals => {:directory_name => directory_name, :directory => directory}
    table_row[:filename] = directory_name
    table_row[:last_modified_date_unconverted] = directory.last_modified_date.strftime('%b %d, %Y %H:%M')
    table_row[:revision_by] = directory.user_id
    return table_row
    
  end
  
  def construct_file_manager_table_row(file_name, file)
    table_row = {}
    table_row[:id] = file.id
    table_row[:filter_table_row_contents] = render_to_string :partial => 'submissions/table_row/filter_table_row', :locals => {:file_name => file_name, :file => file}
    
    table_row[:filename] = file_name
    
    table_row[:last_modified_date] = file.last_modified_date.strftime('%d %B, %l:%M%p')

    table_row[:last_modified_date_unconverted] = file.last_modified_date.strftime('%b %d, %Y %H:%M')

    table_row[:revision_by] = file.user_id

    return table_row
  end
  
  
  def construct_file_manager_table_rows(files)
    result = {}
    files.each do |file_name, file|
      result[file.id] = construct_file_manager_table_row(file_name, file)
    end
    return result
  end
  
  
 def construct_submissions_table_row(grouping, assignment)
    table_row = {}
    table_row[:id] = grouping.id
   table_row[:filter_table_row_contents] = render_to_string :partial => 'submissions/submissions_table_row/filter_table_row', :locals => {:grouping => grouping, :assignment => assignment}
    
    table_row[:group_name] = grouping.group.group_name
  
    table_row[:repository] = grouping.group.repository_name

    if !@details.nil?
      assignment.rubric_criteria.each_with_index do |criterion, index|
        if grouping.has_submission?
          mark = grouping.get_submission_used.result.marks.find_by_rubric_criterion_id(criterion.id)
          if mark.nil? || mark.mark.nil?
            table_row['criterion_' + index.to_s] = '0'
          else
            table_row['criterion_' + index.to_s] = mark.mark
          end<commit_msg>Ticket 457: Makes polymorphic association into marks table <commit_after>module SubmissionsHelper
  
  def find_appropriate_grouping(assignment_id, params)
    if current_user.admin? || current_user.ta?
      return Grouping.find(params[:grouping_id])
    else
      return current_user.accepted_grouping_for(assignment_id)
    end
  end
  
  def construct_file_manager_dir_table_row(directory_name, directory)
    table_row = {}
    table_row[:id] = directory.id
    table_row[:filter_table_row_contents] = render_to_string :partial => 'submissions/table_row/directory_table_row', :locals => {:directory_name => directory_name, :directory => directory}
    table_row[:filename] = directory_name
    table_row[:last_modified_date_unconverted] = directory.last_modified_date.strftime('%b %d, %Y %H:%M')
    table_row[:revision_by] = directory.user_id
    return table_row
    
  end
  
  def construct_file_manager_table_row(file_name, file)
    table_row = {}
    table_row[:id] = file.id
    table_row[:filter_table_row_contents] = render_to_string :partial => 'submissions/table_row/filter_table_row', :locals => {:file_name => file_name, :file => file}
    
    table_row[:filename] = file_name
    
    table_row[:last_modified_date] = file.last_modified_date.strftime('%d %B, %l:%M%p')

    table_row[:last_modified_date_unconverted] = file.last_modified_date.strftime('%b %d, %Y %H:%M')

    table_row[:revision_by] = file.user_id

    return table_row
  end
  
  
  def construct_file_manager_table_rows(files)
    result = {}
    files.each do |file_name, file|
      result[file.id] = construct_file_manager_table_row(file_name, file)
    end
    return result
  end
  
  
 def construct_submissions_table_row(grouping, assignment)
    table_row = {}
    table_row[:id] = grouping.id
   table_row[:filter_table_row_contents] = render_to_string :partial => 'submissions/submissions_table_row/filter_table_row', :locals => {:grouping => grouping, :assignment => assignment}
    
    table_row[:group_name] = grouping.group.group_name
  
    table_row[:repository] = grouping.group.repository_name

    if !@details.nil?
      assignment.rubric_criteria.each_with_index do |criterion, index|
        if grouping.has_submission?
          mark = grouping.get_submission_used.result.marks.find_by_markable_id_and_markable_type(criterion.id, criterion.class.name)
          if mark.nil? || mark.mark.nil?
            table_row['criterion_' + index.to_s] = '0'
          else
            table_row['criterion_' + index.to_s] = mark.mark
          end
{'fraction_non_alphanumeric': 0.10664544369279745, 'fraction_numerical': 0.0009948269001193793, 'mean_word_length': 4.140081799591002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '5980521', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1667, 'n_words': 262}