<%inherit file="main.html" />
<%! from django.core.urlresolvers import reverse %>
<%namespace name='static' file='static_content.html'/>

<%block name="js_extra">
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.stack.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.symbol.js')}"></script>
</%block>

<%block name="headextra">
  <%static:css group='course'/>

  <style type="text/css">
  .grade_A {color:green;}
  .grade_B {color:Chocolate;}
  .grade_C {color:DarkSlateGray;}
  .grade_F {color:DimGray;}
  .grade_None {color:LightGray;}
  </style>

</%block>

<%include file="course_navigation.html" args="active_page=''" />

<section class="container">
<div class="gradebook-wrapper">
  <section class="gradebook-content">
    <h1>Gradebook</h1>

    %if len(students) > 0:
    <table>
      <%
      templateSummary = students[0]['grade_summary']
      %>


      <tr> <!-- Header Row -->
        <th>Student</th>
        %for section in templateSummary['section_breakdown']:
          <th>${section['label']}</th>
        %endfor
        <th>Total</th>
      </tr>

      <%def name="percent_data(fraction)">
        <%
          letter_grade = 'None'
          if fraction > 0:
            letter_grade = 'F'
            for grade in ['A', 'B', 'C']:
              if fraction >= course.grade_cutoffs[grade]:
                letter_grade = grade
                break

          data_class = "grade_" + letter_grade
        %>
        <td class="${data_class}" data-percent="${fraction}">${ "{0:.0f}".format( 100 * fraction ) }</td>
      </%def>

      %for student in students:
      <tr>
        <td><a href="${reverse('student_profile',
                               kwargs=dict(course_id=course_id,
                                           student_id=student['id']))}">
                      ${student['username']}</a></td>
        %for section in student['grade_summary']['section_breakdown']:
          ${percent_data( section['percent'] )}
        %endfor
        <th>${percent_data( student['grade_summary']['percent'])}</th>
      </tr>
      %endfor
    </table>
    %endif
  </section>
</div>
</section>
