<!-- @studentx IS THE STUDENT FOR WHOM THE SUMMARY IS PRODUCED HERE 
THIS VIEW LOOPS OVER THE INDIVIDUAL GRADES AND GROUP GRADES FOR THE
GIVEN STUDENT AND PREPARE 2 TABLES + AVERAGE OVERALL GRADE WHICH
IS A SIMPLE AVERAGE OF ALL ASSIGNMENT GRADES DIVIDED BY NUMBER OF
ASSIGNMENTS (NO SPECIAL WEIGHTS TO ANYTHING). THE GROUP OF THE 
STUDENT AS WELL AS RETRIEVING THE GRADES FROM THE MODEL WAS DONE
FOR US IN THE CONTROLLER, SO HERE @igrades and @ggrades ALREADY
CONTAIN THE ARRAY OF GRADES WEE NEED, SO ALL IS LEFT TO PRESENT
THEM AND CALCULATE AVERAGES FOR INDIVIDUAL, GROUP AND OVERALL
-->
<h1>Summary of Assignment grades for:  
	<%=h Student.find(:first, :select => "students.name", 
	    :conditions => "id = #{@studentx} " ).name 
	 %>	
</h1>
<p>Individual grades</p>

<table border="1">	
  <tr>
	<th>Assignment order</th>
    <th>Description</th>
    <th>Grade</th>
  </tr>

<% igrade_accum=0 %>
<% igrade_cnt=0 %>
<% @igrades.each do |igrade| %>
    <tr>
      <td><%=h Assignment.find(:first, :select => "assignments.ordering", 
          :conditions => "id = #{igrade.assignment_id} " ).ordering %>
      <td><%=h Assignment.find(:first, :select => "assignments.description", 
         :conditions => "id = #{igrade.assignment_id} " ).description %>
      </td>
      <td><%=h igrade.grade %></td>
    </tr>
    <% igrade_accum += igrade.grade %>
    <% igrade_cnt += 1 %>
<% end %>
<tr>
	<% if igrade_cnt == 0 %>
	  <td> No Individual grades for student</td>
	  <td>None</td>
	  <td>0</td>
	<% else %>	
	  <td> Average individual grade</td>
	  <td> ======> </td>
	  <td><%=h igrade_accum / igrade_cnt %></td>
	<% end %>
</tr>		    
</table>

<p>Group grades</p>
<table border="1">	
  <tr>
	<th>Assignment order</th>
    <th>Description</th>
    <th>Grade</th>
  </tr>

<% ggrade_accum=0 %>
<% ggrade_cnt=0 %>
<% @ggrades.each do |ggrade| %>
    <tr>
      <td><%=h Assignment.find(:first, :select => "assignments.ordering", 
         :conditions => "id = #{ggrade.assignment_id} " ).ordering %>
      </td>
      <td><%=h Assignment.find(:first, :select => "assignments.description", 
         :conditions => "id = #{ggrade.assignment_id} " ).description %>
      </td>
      <td><%=h ggrade.grade %></td>
    </tr>
    <% ggrade_accum += ggrade.grade %>
    <% ggrade_cnt += 1 %>
<% end %>
<tr>
	<% if ggrade_cnt == 0 %>
	  <td> No Group grades for student</td>
	  <td>None</td>
	  <td>0</td>
	<% else %>
	  <td> Average group grade</td>
	  <td> ======> </td>
  	  <td><%=h ggrade_accum / ggrade_cnt %>
	<% end %>
</tr>
</table>
<% if igrade_cnt > 0 || ggrade_cnt > 0 %>
     <p> Average overall grade: <%=h (igrade_accum + ggrade_accum) / (igrade_cnt + ggrade_cnt) %>
     </p>	
<% else %>
     <p> NO GRADES FOR STUDENT 
     </p>
<% end %>

<br />
