<commit_before><% 
  js_bundle :grade_summary, :rubric_assessment
  jammit_css :grade_summary 
  content_for :page_title, join_title(t(:page_title, "Grades for %{student}", :student => @student.name), @context.name)
  editable = @current_user == @student && !@no_calculations
%>

<% content_for :right_side do %>
  <div class="rs-margin-all">
    <% if @domain_root_account.try_rescue(:enable_user_notes) and can_do(@user, @current_user, :read_user_notes) %>
      <a href="<%= user_user_notes_path(@user) %>" class="button button-sidebar-wide"><%= t(:faculty_journal, "Faculty Journal for %{user}", :user => context_user_name(@context, @user)) %></a>
    <% end %>
    <% if @context.settings[:hide_final_grade] %>
      <div class="student_assignment final_grade" style="font-size: 1.2em;">
        <%= t('labels.final_grade_hidden', "Calculation of totals has been disabled") %>
      </div>
    <% else %>
      <div class="student_assignment final_grade" style="font-size: 1.2em;">
        <%= before_label(:total, "Total") %> <%= raw(number_to_percentage(100, :precision => 0).sub(/100/, '<span class="grade"></span>')) %>
        <% if @context.grading_standard_enabled? %>
          <span class="final_letter_grade">
            (<span class="grade" id="final_letter_grade_text">-</span>)
          </span>
        <% end %>
      </div>
    <% end %>
    <% if editable %>
        <div class="show_guess_grades" style="display: none; margin-bottom: 10px; font-size: 0.8em;">
          <button type="button" class="button button-sidebar-wide show_guess_grades_link"><%= image_tag "grading_icon.png" %> <%= t('buttons.show_what_if', "Show Saved \"What-If\" Scores") %></button>
        </div>
        <div class="revert_all_scores" style="font-size: 0.8em; padding-left: 10px; display: none;">
          <%= t(:not_official, "*NOTE*: This is NOT your official score.") %><br/>
          <a href="#" class="button revert_all_scores_link"><%= image_tag "back.png" %> <%= t('links.revert_score', "Revert to Actual Score") %></a>
        </div>
    <% end %>
    <div class="show_all_details" style="font-size: 0.8em; margin-top: 10px;">
      <a href="#" class="button" id="show_all_details_link"><%= t('links.show_details', "Show All Details") %></a>
    </div>
    <div style="margin-top: 10px;">
      <%= render :partial => "courses/sidebar_weighting", :object => @groups %>
      <% unless @no_calculations %>
        <div style="font-size: 0.8em;">
          <input type="checkbox" id="only_consider_graded_assignments" checked="true"/>
          <label for="only_consider_graded_assignments"><%= t('labels.only_graded', "Calculate based only on graded assignments") %></label>
        </div>
      <% end %>
    </div>
    <% if editable %>
      <div style="margin-top: 10px;">
        <%= t(:change_score_instructions, "Click any score and enter a new value to see how the change will affect your total.") %>
      </div>
    <% end %>
  </div>
<% end %>

<h2>
<% ot('headers.grades', "Grades For %{student}", :student => capture { %>
 <% if !@observed_students || @observed_students.keys.length <= 1 %>
   <%= @student.name %>
 <% else %>
  <select id="observer_user_url">
    <% @observed_students.each do |student, enrollments| %>
      <%
        next unless enrollments.all? { |e| e.grants_right?(@current_user, nil, :read_grades) }
        url = context_url(@context, :context_student_grades_url, student.id)
      %>
      <option value="<%= url %>" <%= 'selected' if student == @student %>><%= student.name %></option>
    <% end %>
  </select>
 <% end %>
<% }) %>
</h2>
<% if @courses_with_grades && @courses_with_grades.length > 1 %>
  <div style="margin-left: 10px;">
  <%= t(:for_course, "For the course,") %>
  <select id="course_url">
    <% @courses_with_grades.each do |course| %>
      <%
         student_enrollment = course.all_student_enrollments.find_by_user_id(@student.id)
         next unless student_enrollment.grants_right?(@current_user, nil, :read_grades)
         if course.grants_rights?(@current_user, nil, :manage_grades, :view_all_grades).values.any?
           url = context_url(course, :context_student_grades_url, @student.id)
         else
           url = context_url(course, :context_grades_url)
         end
      %>
      <option value="<%= url %>" <%= 'selected' if course == @context %>><%= course.name %></option>
    <% end %>
  </select>
  </div>
  <% js_block do %>
    <script>
    require([
      'jquery' /* $ */
    ], function($) {
      $(document).ready(function() {
        $("#course_url").change(function() {
          if(location.href != $(this).val()) {
            location.href = $(this).val();
          }
        });
      });
    });
    </script>
  <% end %>
<% end %>
</h2>
<table style="width: 100%;" id="grades_summary" class="<%= 'editable' if editable %>">
  <thead>
    <tr>
      <th><%= t('headers.name', "Name") %></th>
      <th><%= t('headers.due', "Due") %></th>
      <th><%= t('headers.score', "Score") %></th>
      <th style="text-align: right; white-space: nowrap;"><%= t('headers.out_of', "Out of") %></th>
      <th>&nbsp;</th>
    </tr>
  </thead>
<% turnitin_enabled = @context.turnitin_enabled? && @assignments.any?(&:turnitin_enabled) %>
<% @assignments.each do |assignment| %>
  <%
     submission = @submissions.find {|s| s.assignment_id == assignment.id }
     # load up the object to avoid a database query (assignment was loaded with a broad query,
     # so this wouldn't hit the query cache)
     submission.assignment = assignment if submission
     visible_rubric_assessments = []
     visible_rubric_assessments = submission.rubric_assessments.select{|a| a.grants_rights?(@current_user, :read)[:read]}.sort_by{|a| [a.assessment_type == 'grading' ? '0' : '1', a.assessor_name] } if submission && !assignment.muted?
  %>
  <tr class="student_assignment <%= 'assignment_graded' if submission && submission.grade && !assignment.muted? %> <%= assignment.special_class ? ("hard_coded " + assignment.special_class) : "editable" %>" data-muted="<%= assignment.muted? %>" id="<%= "submission_" + assignment.id.to_s %>">
    <td class="title">
      <% if assignment.class.to_s == "Assignment" %>
        <a href="<%= context_url(@context, :context_assignment_submission_url, assignment, @student.id) %>"><%= assignment.title %></a>
      <% else %>
        <%= assignment.title %>
      <% end %>
      <% if assignment && assignment.assignment_group %>
        <div class="context"><%= assignment.assignment_group.name %></div>
      <% end %>
    </td>
    <td class="due">
      <% if !(assignment.group_weight rescue false) %>
        <%= datetime_string(assignment.due_at, :due_date) rescue "" %>
      <% end %>
    </td>
    <td class="assignment_score" title="<%= t(:click_to_change, "Click to test a different score") unless (!editable || assignment.special_class) %>">
      <div style="position: relative; height: 100%;" class="score_holder">
        <span class="tooltip">
          <span class="tooltip_wrap right">
            <% if editable || assignment.special_class %>
              <span class="tooltip_text score_teaser">
                <% if assignment.muted? %>
                  <%= t(:student_mute_notification, "Instructor is working on grades") %>
                <% elsif assignment.special_class %>
                  <%= t(:percent, "Percent") %>
                <% else %>
                  <%= t(:click_to_change, "Click to test a different score") %>
                <% end %>
              </span>
            <% end %>
          </span>
          <span class="grade">
            <% if assignment.muted? %>
              <%= image_tag "sound_mute.png", :alt => t("#gradebooks.grade.muted", "Muted"), :class => "muted_icon" %>
            <% else %>
              <%= render :partial => 'submission_score', :object => submission, :locals => {:student_score => !can_do(@context, @current_user, :manage_grades)} %>
            <% end %>
          </span>
          <% if assignment.grading_type == 'letter_grade' %>
            <span class="score_value" style="font-size: 0.8em; color: #aaa;">
              <% unless assignment.muted? || submission.nil? %>
                <%= submission.published_score %>
                (<%= submission.published_grade %>)
              <% end %>
            </span>
          <% end %>
          <%= "%" if assignment.special_class %>
        </span>
        <div style="display: none;">
          <span class="original_score">
            <% unless assignment.muted? || submission.nil? %>
              <%= submission.published_score %>
              <%= assignment.grading_type == 'letter_grade' ? "(#{submission.published_grade})" : '' %>
            <% end %>
          </span>
          <span class="score">
            <% unless assignment.muted? || submission.nil? %>
              <%= submission.published_score %>
              <%= assignment.grading_type == 'letter_grade' ? "(#{submission.published_grade})" : '' %>
            <% end %>
          </span>
          <span class="assignment_group_id"><%= assignment.assignment_group_id rescue "" %></span>
          <span class="assignment_id"><%= assignment.id.to_s %></span>
          <span class="group_weight"><%= assignment.group_weight rescue "" %></span>
          <span class="student_entered_score"><%= submission.student_entered_score rescue "" %></span>
          <span class="rules"><%= assignment.rules rescue "" %></span>
        </div>
      </div>
    </td>
    <td class="possible points_possible" <%= "colspan='2'" if assignment.special_class %>><%= assignment.points_possible %></td>
    <% if !assignment.special_class %>
    <td style="padding-left: 10px; white-space: nowrap;">
      <% has_comments = submission && submission.visible_submission_comments && !submission.visible_submission_comments.empty? %>
      <a href="#" class="toggle_comments_link tooltip" aria-role="button" aria-controls="grade_info_<%= assignment.id %>" title="<%= t(:view_comments, "View comments and scoring details") %>" style="<%= 'visibility: hidden;' unless has_comments %>">
        <span class="tooltip_wrap right">
          <span class="tooltip_text"><%= t(:comment_count, "comment", :count => (submission.visible_submission_comments.size rescue 0)) %></span>
        </span>
        <%= image_tag "word_bubble.png" %>
      </a>
      <% has_scoring_details = submission && submission.score && assignment.points_possible && assignment.points_possible > 0 && !assignment.muted? %>
      <a href="#" class="toggle_comments_link tooltip" aria-role="button" aria-controls="grade_info_<%= assignment.id %>" title="<%= t 'titles.view_scoring_details', 'View Scoring Details' %>" style="<%= 'visibility: hidden;' unless has_scoring_details %>">
        <span class="tooltip_wrap right">
          <span class="tooltip_text"><%= t(:see_scoring_details, "See scoring details") %></span>
        </span>
        <%= image_tag "grading_icon.png", :style => "opacity: 0.5;", :alt => t('titles.view_scoring_details', 'View Scoring Details') %>
      </a>
      <a href="#" class="toggle_rubric_assessments_link tooltip" title="<%= t 'titles.view_rubric_evaluation', 'View Rubric Evaluation' %>" style="<%= 'visibility: hidden;' if visible_rubric_assessments.empty? %>">
        <span class="tooltip_wrap right">
          <span class="tooltip_text"><%= t(:see_rubric_results, "See rubric results") %></span>
        </span>
        <%= image_tag "rubric.png" %>
      </a>
      <% if turnitin_enabled %>
        <%
          turntitin = nil
          url = '#'
          if can_do(submission, @current_user, :view_turnitin_report)
            if submission.submission_type == 'online_text_entry'
              turnitin = submission.turnitin_data && submission.turnitin_data[submission.asset_string]
              url = context_url(@context, :context_assignment_submission_turnitin_report_url, assignment.id, @student.id, submission.asset_string)
            elsif submission.submission_type == 'online_upload'
              file = submission.attachments.select{|a| submission.turnitin_data && submission.turnitin_data[a.asset_string] }.first
              if file
                turnitin = submission.turnitin_data[file.asset_string]
                url = context_url(@context, :context_assignment_submission_turnitin_report_url, assignment.id, @student.id, file.asset_string)
              end
            end
            turnitin = nil unless turnitin.try(:[], :state)
          end
        %>
        <a class="tooltip" title="<%= t('titles.turnitin_score', "Turnitin similarity score -- more information") %>" href="<%= url %>" style="<%= 'visibility: hidden;' if !turnitin %>" target="_blank">
          <%= turnitin ? image_tag("turnitin_#{turnitin && turnitin[:state]}_score.png") : image_tag("blank.png", :alt => '') %>
          <span class="tooltip_wrap right">
            <span class="tooltip_text"><%= t(:see_turnitin_results, "See Turnitin results") %></span>
          </span>
        </a>
      <% end %>
    </td>
    <% end %>
  </tr>
  <%# always add row (even if empty) so javascript references work %>
  <tr id="grade_info_<%= assignment.id %>" aria-expanded="false" role="region" class="comments <%= 'assignment_graded' if submission && submission.grade && !assignment.muted? %>" style="display: none;">
    <% if !assignment.special_class && (has_comments || has_scoring_details) %>
      <td colspan="5" style="padding-bottom: 20px;">
        <% if assignment && assignment.points_possible && assignment.points_possible > 0 && !assignment.muted? %>
        <% high, low, mean = assignment.grade_distribution(@all_submissions.select { |s| s.assignment_id == assignment.id }) %>
        <% title = "" %>
        <% title += " " + before_label(:mean_score, "Mean") + " " + (mean.round(1) rescue 0).to_s %>
        <% title += " " + before_label(:high_score, "High") + " " + high.to_s unless assignment && assignment.hide_max_scores_for_assignments %>
        <% title += " " + before_label(:low_score, "Low") + " " + low.to_s unless assignment && assignment.hide_min_scores_for_assignments %>
        <% if mean && high && low %>
        <div tabindex="0" class="tooltip" style="cursor: pointer; float: right; height: 30px; margin-left: 20px; width: 160px; position: relative; margin-right: 30px;" title="<%= title %>">
          <span class="tooltip_wrap right" style="z-index: 11; bottom: 35px;">
            <span class="tooltip_text">
              <table>
                <% if submission && submission.score %>
                <tr>
                  <td><b><%= before_label(:your_score, "Your Score") %></b></td>
                  <%# see below for why using wrapper explicitly %>
                  <td><%= t(:submission_score, "*%{score}* out of %{possible}", :wrapper => '<b>\1</b>', :score => submission.score, :possible => assignment.points_possible) %></td>
                </tr>
                <% end %>
                <tr>
                  <td><%= before_label(:mean, "Mean") %></td>
                  <td><%= mean.round(1) %> </td>
                </tr><tr>
                  <td><%= before_label(:high, "High") %></td>
                  <td><% if assignment && assignment.hide_max_scores_for_assignments %>disabled<% else %><%= high %><% end %></td>
                </tr><tr>
                  <td><%= before_label(:low, "Low") %></td>
                  <td><% if assignment && assignment.hide_min_scores_for_assignments %>disabled<% else %><%= low %><% end %></td>
                </tr>
              </table>
            </span>
          </span>
          &nbsp;
          <% if assignment && !assignment.hide_min_scores_for_assignments && !assignment.hide_max_scores_for_assignments %>
            <div style="position: absolute; top: 0; left: 0; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-right-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: 0px; width: <%= (low.to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 0px; margin-top: 10px; border-bottom: 2px solid #aaa; overflow: hidden; border-top-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: <%= (high.to_f / assignment.points_possible.to_f * 150.0).round %>px; width: <%= ((assignment.points_possible - high).to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 0px; margin-top: 10px; border-bottom: 2px solid #aaa; overflow: hidden;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: <%= (low.to_f / assignment.points_possible.to_f * 150.0).round %>px; width: <%= ((mean - low).to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 20px; border: 2px solid #aaa; overflow: hidden; -moz-border-radius-topleft: 3px; -moz-border-radius-bottomleft: 3px; border-right-width: 0; background: #fff;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: <%= (mean.to_f / assignment.points_possible.to_f * 150.0).round %>px; width: <%= ((high - mean).to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 20px; border: 2px solid #aaa; overflow: hidden; -moz-border-radius-topright: 3px; -moz-border-radius-bottomright: 3px; background: #fff;">&nbsp;</div>
            <% left = [150, (high.to_f / assignment.points_possible.to_f * 150.0).round + 3].max %>
            <div style="position: absolute; top: 0; left: <%= left %>px; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-left-width: 0;">&nbsp;</div>
          <% else %>
            <div style="position: absolute; top: 0; left: 0; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-right-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: 0px; width: 150px; height: 0px; margin-top: 10px; border-bottom: 2px solid #aaa; overflow: hidden; border-top-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: 150px; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-left-width: 0;">&nbsp;</div>
          <% end %>
          <% if submission && submission.score %>
            <div style="position: absolute; top: 5px; height: 10px; width: 10px; left: <%= (submission.score.to_f / assignment.points_possible.to_f * 150.0).round - 5 %>px; border: 2px solid #248; background-color: #abd; overflow: hidden; -moz-border-radius: 3px;" title="<%= before_label(:your_score, "Your Score") %> <%= t(:submission_score, "*%{score}* out of %{possible}", :wrapper => '\1', :score => submission.score, :possible => assignment.points_possible) %>">&nbsp;</div>
          <% end %>
        </div>
        <% end %>
        <% end %>
        <% if submission && submission.visible_submission_comments %>
          <% submission.visible_submission_comments.each do |comment| %>
            <div>
              <% if comment.media_comment_id && comment.media_comment_type %>
                <div class="comment_media">
                  <%= t(:media_comment, "This is a media comment,") %><br/>
                  <a href="#" class="play_comment_link media-comment"><%= t('links.click_to_view', "click here to view") %></a>
                  <span class="media_comment_id" style="display: none;"><%= comment.media_comment_id %></span>
                  <div class="media_comment_content">
                  </div>
                </div>
              <% else %>
                <span style="white-space: pre-wrap;"><%= comment.comment %></span>
              <% end %>
              <div style="text-align: right; font-size: 0.8em; margin-right: 10px; clear: both;">
                <% comment.attachments.each do |attachment| %>
                  <div>
                    <a href="<%= context_url(@context, :context_assignment_submission_url, submission.assignment_id, submission.user_id, :download => attachment.id, :comment_id => comment.id) %>"><%= image_tag "file.png", :style => "height: 12px;" %><%= t('links.download', "Download %{attachment}", :attachment => attachment.display_name) %></a>
                  </div>
                <% end %>
              </div>
              <div style="text-align: right; font-size: 0.8em;">
                <%= comment.author_name %>, <%= datetime_string(comment.created_at) %>
              </div>
            </div>
          <% end %>
        <% end %>
      </td>
    <% end %>
  </tr>
  <tr class="rubric_assessments <%= 'assignment_graded' if submission && submission.grade %>" style="display: none;">
    <% unless visible_rubric_assessments.empty? %>
      <td colspan="5">
        <% visible_rubric_assessments.each do |assessment| %>
          <div class="assessor" style="text-align: right; margin-bottom: 5px"><%= t(:assessment_by, "Assessment by %{name}", :name => assessment.assessor_name) %></div>
          <%= render :partial => "shared/rubric", :object => assessment.rubric, :locals => { :assessment => assessment } %>
        <% end %>
      </td>
    <% end %>
  </tr>
<% end %>
</table>
<% muted_assignment_count = @assignments.inject(0) { |i, a| if a.muted? then i + 1 else i end } %>
<% if muted_assignment_count > 0 %>
  <small><%= image_tag "sound_mute.png" %><%= t(:student_mute_legend, "Your instructor is working on grades. While your instructor is working on grades, grade and comment information is unavailable.") %></small>
<% end %>
<% total_weight = 0
  if @context.group_weighting_scheme == "percent"
    @groups.each {|g| total_weight = total_weight + g.group_weight}
  end
%>
<div id="total_groups_weight" style="display: none;"><%= total_weight %></div>
<%= render :partial => "shared/rubric_criterion_dialog" %>
<input type="text" style="width: 40px; display: none;" id="grade_entry"/>
<a href="#" id="revert_score_template" class="revert_score_link" title="<%= t('titles.revert_score', "Revert to original score") %>"><%= image_tag "back.png" %></a>
<a href="<%= context_url(@context, :context_assignment_submission_url, "{{ assignment_id }}", @student.id) %>" class="update_submission_url" style="display: none;">&nbsp;</a>
<% if @context.grading_standard_enabled? %>
  <% js_block do %>
  <script>
    var grading_scheme = <%= raw((@context.grading_standard.try(:data) || GradingStandard.default_grading_standard).to_json) %>;
  </script>
  <% end %>
<% end %>
<commit_msg>scope column headers in student grade table. fixes #9195<commit_after><% 
  js_bundle :grade_summary, :rubric_assessment
  jammit_css :grade_summary 
  content_for :page_title, join_title(t(:page_title, "Grades for %{student}", :student => @student.name), @context.name)
  editable = @current_user == @student && !@no_calculations
%>

<% content_for :right_side do %>
  <div class="rs-margin-all">
    <% if @domain_root_account.try_rescue(:enable_user_notes) and can_do(@user, @current_user, :read_user_notes) %>
      <a href="<%= user_user_notes_path(@user) %>" class="button button-sidebar-wide"><%= t(:faculty_journal, "Faculty Journal for %{user}", :user => context_user_name(@context, @user)) %></a>
    <% end %>
    <% if @context.settings[:hide_final_grade] %>
      <div class="student_assignment final_grade" style="font-size: 1.2em;">
        <%= t('labels.final_grade_hidden', "Calculation of totals has been disabled") %>
      </div>
    <% else %>
      <div class="student_assignment final_grade" style="font-size: 1.2em;">
        <%= before_label(:total, "Total") %> <%= raw(number_to_percentage(100, :precision => 0).sub(/100/, '<span class="grade"></span>')) %>
        <% if @context.grading_standard_enabled? %>
          <span class="final_letter_grade">
            (<span class="grade" id="final_letter_grade_text">-</span>)
          </span>
        <% end %>
      </div>
    <% end %>
    <% if editable %>
        <div class="show_guess_grades" style="display: none; margin-bottom: 10px; font-size: 0.8em;">
          <button type="button" class="button button-sidebar-wide show_guess_grades_link"><%= image_tag "grading_icon.png" %> <%= t('buttons.show_what_if', "Show Saved \"What-If\" Scores") %></button>
        </div>
        <div class="revert_all_scores" style="font-size: 0.8em; padding-left: 10px; display: none;">
          <%= t(:not_official, "*NOTE*: This is NOT your official score.") %><br/>
          <a href="#" class="button revert_all_scores_link"><%= image_tag "back.png" %> <%= t('links.revert_score', "Revert to Actual Score") %></a>
        </div>
    <% end %>
    <div class="show_all_details" style="font-size: 0.8em; margin-top: 10px;">
      <a href="#" class="button" id="show_all_details_link"><%= t('links.show_details', "Show All Details") %></a>
    </div>
    <div style="margin-top: 10px;">
      <%= render :partial => "courses/sidebar_weighting", :object => @groups %>
      <% unless @no_calculations %>
        <div style="font-size: 0.8em;">
          <input type="checkbox" id="only_consider_graded_assignments" checked="true"/>
          <label for="only_consider_graded_assignments"><%= t('labels.only_graded', "Calculate based only on graded assignments") %></label>
        </div>
      <% end %>
    </div>
    <% if editable %>
      <div style="margin-top: 10px;">
        <%= t(:change_score_instructions, "Click any score and enter a new value to see how the change will affect your total.") %>
      </div>
    <% end %>
  </div>
<% end %>

<h2>
<% ot('headers.grades', "Grades For %{student}", :student => capture { %>
 <% if !@observed_students || @observed_students.keys.length <= 1 %>
   <%= @student.name %>
 <% else %>
  <select id="observer_user_url">
    <% @observed_students.each do |student, enrollments| %>
      <%
        next unless enrollments.all? { |e| e.grants_right?(@current_user, nil, :read_grades) }
        url = context_url(@context, :context_student_grades_url, student.id)
      %>
      <option value="<%= url %>" <%= 'selected' if student == @student %>><%= student.name %></option>
    <% end %>
  </select>
 <% end %>
<% }) %>
</h2>
<% if @courses_with_grades && @courses_with_grades.length > 1 %>
  <div style="margin-left: 10px;">
  <%= t(:for_course, "For the course,") %>
  <select id="course_url">
    <% @courses_with_grades.each do |course| %>
      <%
         student_enrollment = course.all_student_enrollments.find_by_user_id(@student.id)
         next unless student_enrollment.grants_right?(@current_user, nil, :read_grades)
         if course.grants_rights?(@current_user, nil, :manage_grades, :view_all_grades).values.any?
           url = context_url(course, :context_student_grades_url, @student.id)
         else
           url = context_url(course, :context_grades_url)
         end
      %>
      <option value="<%= url %>" <%= 'selected' if course == @context %>><%= course.name %></option>
    <% end %>
  </select>
  </div>
  <% js_block do %>
    <script>
    require([
      'jquery' /* $ */
    ], function($) {
      $(document).ready(function() {
        $("#course_url").change(function() {
          if(location.href != $(this).val()) {
            location.href = $(this).val();
          }
        });
      });
    });
    </script>
  <% end %>
<% end %>
</h2>
<table style="width: 100%;" id="grades_summary" class="<%= 'editable' if editable %>">
  <thead>
    <tr>
      <th scope="row"><%= t('headers.name', "Name") %></th>
      <th scope="row"><%= t('headers.due', "Due") %></th>
      <th scope="row"><%= t('headers.score', "Score") %></th>
      <th scope="row" style="text-align: right; white-space: nowrap;"><%= t('headers.out_of', "Out of") %></th>
      <th scope="row"></th>
    </tr>
  </thead>
<% turnitin_enabled = @context.turnitin_enabled? && @assignments.any?(&:turnitin_enabled) %>
<% @assignments.each do |assignment| %>
  <%
     submission = @submissions.find {|s| s.assignment_id == assignment.id }
     # load up the object to avoid a database query (assignment was loaded with a broad query,
     # so this wouldn't hit the query cache)
     submission.assignment = assignment if submission
     visible_rubric_assessments = []
     visible_rubric_assessments = submission.rubric_assessments.select{|a| a.grants_rights?(@current_user, :read)[:read]}.sort_by{|a| [a.assessment_type == 'grading' ? '0' : '1', a.assessor_name] } if submission && !assignment.muted?
  %>
  <tr class="student_assignment <%= 'assignment_graded' if submission && submission.grade && !assignment.muted? %> <%= assignment.special_class ? ("hard_coded " + assignment.special_class) : "editable" %>" data-muted="<%= assignment.muted? %>" id="<%= "submission_" + assignment.id.to_s %>">
    <td class="title">
      <% if assignment.class.to_s == "Assignment" %>
        <a href="<%= context_url(@context, :context_assignment_submission_url, assignment, @student.id) %>"><%= assignment.title %></a>
      <% else %>
        <%= assignment.title %>
      <% end %>
      <% if assignment && assignment.assignment_group %>
        <div class="context"><%= assignment.assignment_group.name %></div>
      <% end %>
    </td>
    <td class="due">
      <% if !(assignment.group_weight rescue false) %>
        <%= datetime_string(assignment.due_at, :due_date) rescue "" %>
      <% end %>
    </td>
    <td class="assignment_score" title="<%= t(:click_to_change, "Click to test a different score") unless (!editable || assignment.special_class) %>">
      <div style="position: relative; height: 100%;" class="score_holder">
        <span class="tooltip">
          <span class="tooltip_wrap right">
            <% if editable || assignment.special_class %>
              <span class="tooltip_text score_teaser">
                <% if assignment.muted? %>
                  <%= t(:student_mute_notification, "Instructor is working on grades") %>
                <% elsif assignment.special_class %>
                  <%= t(:percent, "Percent") %>
                <% else %>
                  <%= t(:click_to_change, "Click to test a different score") %>
                <% end %>
              </span>
            <% end %>
          </span>
          <span class="grade">
            <% if assignment.muted? %>
              <%= image_tag "sound_mute.png", :alt => t("#gradebooks.grade.muted", "Muted"), :class => "muted_icon" %>
            <% else %>
              <%= render :partial => 'submission_score', :object => submission, :locals => {:student_score => !can_do(@context, @current_user, :manage_grades)} %>
            <% end %>
          </span>
          <% if assignment.grading_type == 'letter_grade' %>
            <span class="score_value" style="font-size: 0.8em; color: #aaa;">
              <% unless assignment.muted? || submission.nil? %>
                <%= submission.published_score %>
                (<%= submission.published_grade %>)
              <% end %>
            </span>
          <% end %>
          <%= "%" if assignment.special_class %>
        </span>
        <div style="display: none;">
          <span class="original_score">
            <% unless assignment.muted? || submission.nil? %>
              <%= submission.published_score %>
              <%= assignment.grading_type == 'letter_grade' ? "(#{submission.published_grade})" : '' %>
            <% end %>
          </span>
          <span class="score">
            <% unless assignment.muted? || submission.nil? %>
              <%= submission.published_score %>
              <%= assignment.grading_type == 'letter_grade' ? "(#{submission.published_grade})" : '' %>
            <% end %>
          </span>
          <span class="assignment_group_id"><%= assignment.assignment_group_id rescue "" %></span>
          <span class="assignment_id"><%= assignment.id.to_s %></span>
          <span class="group_weight"><%= assignment.group_weight rescue "" %></span>
          <span class="student_entered_score"><%= submission.student_entered_score rescue "" %></span>
          <span class="rules"><%= assignment.rules rescue "" %></span>
        </div>
      </div>
    </td>
    <td class="possible points_possible" <%= "colspan='2'" if assignment.special_class %>><%= assignment.points_possible %></td>
    <% if !assignment.special_class %>
    <td style="padding-left: 10px; white-space: nowrap;">
      <% has_comments = submission && submission.visible_submission_comments && !submission.visible_submission_comments.empty? %>
      <a href="#" class="toggle_comments_link tooltip" aria-role="button" aria-controls="grade_info_<%= assignment.id %>" title="<%= t(:view_comments, "View comments and scoring details") %>" style="<%= 'visibility: hidden;' unless has_comments %>">
        <span class="tooltip_wrap right">
          <span class="tooltip_text"><%= t(:comment_count, "comment", :count => (submission.visible_submission_comments.size rescue 0)) %></span>
        </span>
        <%= image_tag "word_bubble.png" %>
      </a>
      <% has_scoring_details = submission && submission.score && assignment.points_possible && assignment.points_possible > 0 && !assignment.muted? %>
      <a href="#" class="toggle_comments_link tooltip" aria-role="button" aria-controls="grade_info_<%= assignment.id %>" title="<%= t 'titles.view_scoring_details', 'View Scoring Details' %>" style="<%= 'visibility: hidden;' unless has_scoring_details %>">
        <span class="tooltip_wrap right">
          <span class="tooltip_text"><%= t(:see_scoring_details, "See scoring details") %></span>
        </span>
        <%= image_tag "grading_icon.png", :style => "opacity: 0.5;", :alt => t('titles.view_scoring_details', 'View Scoring Details') %>
      </a>
      <a href="#" class="toggle_rubric_assessments_link tooltip" title="<%= t 'titles.view_rubric_evaluation', 'View Rubric Evaluation' %>" style="<%= 'visibility: hidden;' if visible_rubric_assessments.empty? %>">
        <span class="tooltip_wrap right">
          <span class="tooltip_text"><%= t(:see_rubric_results, "See rubric results") %></span>
        </span>
        <%= image_tag "rubric.png" %>
      </a>
      <% if turnitin_enabled %>
        <%
          turntitin = nil
          url = '#'
          if can_do(submission, @current_user, :view_turnitin_report)
            if submission.submission_type == 'online_text_entry'
              turnitin = submission.turnitin_data && submission.turnitin_data[submission.asset_string]
              url = context_url(@context, :context_assignment_submission_turnitin_report_url, assignment.id, @student.id, submission.asset_string)
            elsif submission.submission_type == 'online_upload'
              file = submission.attachments.select{|a| submission.turnitin_data && submission.turnitin_data[a.asset_string] }.first
              if file
                turnitin = submission.turnitin_data[file.asset_string]
                url = context_url(@context, :context_assignment_submission_turnitin_report_url, assignment.id, @student.id, file.asset_string)
              end
            end
            turnitin = nil unless turnitin.try(:[], :state)
          end
        %>
        <a class="tooltip" title="<%= t('titles.turnitin_score', "Turnitin similarity score -- more information") %>" href="<%= url %>" style="<%= 'visibility: hidden;' if !turnitin %>" target="_blank">
          <%= turnitin ? image_tag("turnitin_#{turnitin && turnitin[:state]}_score.png") : image_tag("blank.png", :alt => '') %>
          <span class="tooltip_wrap right">
            <span class="tooltip_text"><%= t(:see_turnitin_results, "See Turnitin results") %></span>
          </span>
        </a>
      <% end %>
    </td>
    <% end %>
  </tr>
  <%# always add row (even if empty) so javascript references work %>
  <tr id="grade_info_<%= assignment.id %>" aria-expanded="false" role="region" class="comments <%= 'assignment_graded' if submission && submission.grade && !assignment.muted? %>" style="display: none;">
    <% if !assignment.special_class && (has_comments || has_scoring_details) %>
      <td colspan="5" style="padding-bottom: 20px;">
        <% if assignment && assignment.points_possible && assignment.points_possible > 0 && !assignment.muted? %>
        <% high, low, mean = assignment.grade_distribution(@all_submissions.select { |s| s.assignment_id == assignment.id }) %>
        <% title = "" %>
        <% title += " " + before_label(:mean_score, "Mean") + " " + (mean.round(1) rescue 0).to_s %>
        <% title += " " + before_label(:high_score, "High") + " " + high.to_s unless assignment && assignment.hide_max_scores_for_assignments %>
        <% title += " " + before_label(:low_score, "Low") + " " + low.to_s unless assignment && assignment.hide_min_scores_for_assignments %>
        <% if mean && high && low %>
        <div tabindex="0" class="tooltip" style="cursor: pointer; float: right; height: 30px; margin-left: 20px; width: 160px; position: relative; margin-right: 30px;" title="<%= title %>">
          <span class="tooltip_wrap right" style="z-index: 11; bottom: 35px;">
            <span class="tooltip_text">
              <table>
                <% if submission && submission.score %>
                <tr>
                  <td><b><%= before_label(:your_score, "Your Score") %></b></td>
                  <%# see below for why using wrapper explicitly %>
                  <td><%= t(:submission_score, "*%{score}* out of %{possible}", :wrapper => '<b>\1</b>', :score => submission.score, :possible => assignment.points_possible) %></td>
                </tr>
                <% end %>
                <tr>
                  <td><%= before_label(:mean, "Mean") %></td>
                  <td><%= mean.round(1) %> </td>
                </tr><tr>
                  <td><%= before_label(:high, "High") %></td>
                  <td><% if assignment && assignment.hide_max_scores_for_assignments %>disabled<% else %><%= high %><% end %></td>
                </tr><tr>
                  <td><%= before_label(:low, "Low") %></td>
                  <td><% if assignment && assignment.hide_min_scores_for_assignments %>disabled<% else %><%= low %><% end %></td>
                </tr>
              </table>
            </span>
          </span>
          &nbsp;
          <% if assignment && !assignment.hide_min_scores_for_assignments && !assignment.hide_max_scores_for_assignments %>
            <div style="position: absolute; top: 0; left: 0; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-right-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: 0px; width: <%= (low.to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 0px; margin-top: 10px; border-bottom: 2px solid #aaa; overflow: hidden; border-top-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: <%= (high.to_f / assignment.points_possible.to_f * 150.0).round %>px; width: <%= ((assignment.points_possible - high).to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 0px; margin-top: 10px; border-bottom: 2px solid #aaa; overflow: hidden;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: <%= (low.to_f / assignment.points_possible.to_f * 150.0).round %>px; width: <%= ((mean - low).to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 20px; border: 2px solid #aaa; overflow: hidden; -moz-border-radius-topleft: 3px; -moz-border-radius-bottomleft: 3px; border-right-width: 0; background: #fff;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: <%= (mean.to_f / assignment.points_possible.to_f * 150.0).round %>px; width: <%= ((high - mean).to_f / assignment.points_possible.to_f * 150.0).round %>px; height: 20px; border: 2px solid #aaa; overflow: hidden; -moz-border-radius-topright: 3px; -moz-border-radius-bottomright: 3px; background: #fff;">&nbsp;</div>
            <% left = [150, (high.to_f / assignment.points_possible.to_f * 150.0).round + 3].max %>
            <div style="position: absolute; top: 0; left: <%= left %>px; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-left-width: 0;">&nbsp;</div>
          <% else %>
            <div style="position: absolute; top: 0; left: 0; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-right-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: 0px; width: 150px; height: 0px; margin-top: 10px; border-bottom: 2px solid #aaa; overflow: hidden; border-top-width: 0;">&nbsp;</div>
            <div style="position: absolute; top: 0; left: 150px; width: 0px; height: 10px; margin: 5px 0px; border: 2px solid #aaa; overflow: hidden; border-left-width: 0;">&nbsp;</div>
          <% end %>
          <% if submission && submission.score %>
            <div style="position: absolute; top: 5px; height: 10px; width: 10px; left: <%= (submission.score.to_f / assignment.points_possible.to_f * 150.0).round - 5 %>px; border: 2px solid #248; background-color: #abd; overflow: hidden; -moz-border-radius: 3px;" title="<%= before_label(:your_score, "Your Score") %> <%= t(:submission_score, "*%{score}* out of %{possible}", :wrapper => '\1', :score => submission.score, :possible => assignment.points_possible) %>">&nbsp;</div>
          <% end %>
        </div>
        <% end %>
        <% end %>
        <% if submission && submission.visible_submission_comments %>
          <% submission.visible_submission_comments.each do |comment| %>
            <div>
              <% if comment.media_comment_id && comment.media_comment_type %>
                <div class="comment_media">
                  <%= t(:media_comment, "This is a media comment,") %><br/>
                  <a href="#" class="play_comment_link media-comment"><%= t('links.click_to_view', "click here to view") %></a>
                  <span class="media_comment_id" style="display: none;"><%= comment.media_comment_id %></span>
                  <div class="media_comment_content">
                  </div>
                </div>
              <% else %>
                <span style="white-space: pre-wrap;"><%= comment.comment %></span>
              <% end %>
              <div style="text-align: right; font-size: 0.8em; margin-right: 10px; clear: both;">
                <% comment.attachments.each do |attachment| %>
                  <div>
                    <a href="<%= context_url(@context, :context_assignment_submission_url, submission.assignment_id, submission.user_id, :download => attachment.id, :comment_id => comment.id) %>"><%= image_tag "file.png", :style => "height: 12px;" %><%= t('links.download', "Download %{attachment}", :attachment => attachment.display_name) %></a>
                  </div>
                <% end %>
              </div>
              <div style="text-align: right; font-size: 0.8em;">
                <%= comment.author_name %>, <%= datetime_string(comment.created_at) %>
              </div>
            </div>
          <% end %>
        <% end %>
      </td>
    <% end %>
  </tr>
  <tr class="rubric_assessments <%= 'assignment_graded' if submission && submission.grade %>" style="display: none;">
    <% unless visible_rubric_assessments.empty? %>
      <td colspan="5">
        <% visible_rubric_assessments.each do |assessment| %>
          <div class="assessor" style="text-align: right; margin-bottom: 5px"><%= t(:assessment_by, "Assessment by %{name}", :name => assessment.assessor_name) %></div>
          <%= render :partial => "shared/rubric", :object => assessment.rubric, :locals => { :assessment => assessment } %>
        <% end %>
      </td>
    <% end %>
  </tr>
<% end %>
</table>
<% muted_assignment_count = @assignments.inject(0) { |i, a| if a.muted? then i + 1 else i end } %>
<% if muted_assignment_count > 0 %>
  <small><%= image_tag "sound_mute.png" %><%= t(:student_mute_legend, "Your instructor is working on grades. While your instructor is working on grades, grade and comment information is unavailable.") %></small>
<% end %>
<% total_weight = 0
  if @context.group_weighting_scheme == "percent"
    @groups.each {|g| total_weight = total_weight + g.group_weight}
  end
%>
<div id="total_groups_weight" style="display: none;"><%= total_weight %></div>
<%= render :partial => "shared/rubric_criterion_dialog" %>
<input type="text" style="width: 40px; display: none;" id="grade_entry"/>
<a href="#" id="revert_score_template" class="revert_score_link" title="<%= t('titles.revert_score', "Revert to original score") %>"><%= image_tag "back.png" %></a>
<a href="<%= context_url(@context, :context_assignment_submission_url, "{{ assignment_id }}", @student.id) %>" class="update_submission_url" style="display: none;">&nbsp;</a>
<% if @context.grading_standard_enabled? %>
  <% js_block do %>
  <script>
    var grading_scheme = <%= raw((@context.grading_standard.try(:data) || GradingStandard.default_grading_standard).to_json) %>;
  </script>
  <% end %>
<% end %>

{'fraction_non_alphanumeric': 0.17931479708822154, 'fraction_numerical': 0.009661405578682575, 'mean_word_length': 3.055430170623815, 'pattern_counts': {'":': 0, '<': 933, '<?xml version=': 0, '>': 1003, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2129069', 'n_tokens_mistral': 15173, 'n_tokens_neox': 13693, 'n_words': 3041}