[LON-CAPA-cvs] cvs: loncom /interface lonquickgrades.pm

www www@source.lon-capa.org
Mon, 29 Nov 2010 22:37:27 -0000


www		Mon Nov 29 22:37:27 2010 EDT

  Modified files:              
    /loncom/interface	lonquickgrades.pm 
  Log:
  Cleaning up: disentangling computation and display
  
  
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.50 loncom/interface/lonquickgrades.pm:1.51
--- loncom/interface/lonquickgrades.pm:1.50	Sat Nov 27 20:51:26 2010
+++ loncom/interface/lonquickgrades.pm	Mon Nov 29 22:37:26 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Quick Student Grades Display
 #
-# $Id: lonquickgrades.pm,v 1.50 2010/11/27 20:51:26 www Exp $
+# $Id: lonquickgrades.pm,v 1.51 2010/11/29 22:37:26 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -72,19 +72,6 @@
         $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
 
 
-    # Create the nav map
-    my $navmap = Apache::lonnavmaps::navmap->new();
-
-    if (!defined($navmap)) {
-        my $requrl = $r->uri;
-        $env{'user.error.msg'} = "$requrl:bre:0:0:Navamp initialization failed.";
-        return HTTP_NOT_ACCEPTABLE;
-    }
-
-    # Keep this hash in sync with %statusIconMap in lonnavmaps; they
-    # should match color/icon
-    my $res = $navmap->firstResource(); # temp resource to access constants
- 
     # Header
     my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
     my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
@@ -104,8 +91,21 @@
     $r->print('<p class="LC_info">'.&mt('This may take a few moments to display.').'</p>');
 
     $r->rflush();
+    my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=&getData($showPoints);
+    &outputTable($r,$showPoints,$notshowTotals,
+                 $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
+    return OK;
+
+}
 
-    # End navmap using boilerplate
+sub getData {
+
+    my ($showPoints)=@_;
+
+    # Create the nav map
+    my $navmap = Apache::lonnavmaps::navmap->new();
+
+    my $res = $navmap->firstResource(); # temp resource to access constants
 
     my $iterator = $navmap->getIterator(undef, undef, undef, 1);
     my $depth = 1;
@@ -220,11 +220,17 @@
         }
         $curRes = $iterator->next();
     }
+    return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
+}
 
-    $iterator = $navmap->getIterator(undef, undef, undef, 1);
-    $depth = 1;
-    $iterator->next(); # ignore first BEGIN_MAP
-    $curRes = $iterator->next();
+#
+# Outputting everything.
+#
+
+sub outputTable {
+
+    my ($r,$showPoints,$notshowTotals,
+           $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
 
     my @start = (255, 255, 192);
     my @end   = (0, 192, 0);
@@ -235,12 +241,21 @@
     $r->print(&Apache::loncommon::start_data_table()
              .&Apache::loncommon::start_data_table_header_row()
              .'<th>'.&mt('Folder').'</th>');
-    $title = &mt($showPoints ? "Points Scored" : "Done");
+    my $title = &mt($showPoints ? "Points Scored" : "Done");
     if ($totalAttempted) {
-	$title .= " / " . &mt("Attempted");
+        $title .= " / " . &mt("Attempted");
     }
     $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
              .&Apache::loncommon::end_data_table_header_row());
+#
+# Output of folder scores
+#
+
+    my $iterator = $navmap->getIterator(undef, undef, undef, 1);
+    my $depth = 1;
+    $iterator->next(); # ignore first BEGIN_MAP
+    my $curRes = $iterator->next();
+
     while ($depth > 0) {
         if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
         if ($curRes == $iterator->END_MAP()) { $depth--; }
@@ -255,7 +270,7 @@
             if ($total > 0) {
                 my $ratio;
                 $ratio = $correct / $total;
-                my $color = mixColors(\@start, \@end, $ratio);
+                my $color = &mixColors(\@start, \@end, $ratio);
                 $r->print(&Apache::loncommon::start_data_table_row()
                          .'<td style="background-color:'.$color.';">');
                 
@@ -296,28 +311,31 @@
                  .&Apache::loncommon::end_data_table_row());
     }
 
+#
+# show totals (if applicable), close table
+#
     if ($showPoints) {
-	my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
+        my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
 
-	$title = $showPoints ? "Points" : "Parts Done";
-	my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
-	$r->print(&Apache::loncommon::start_data_table_row()
+        $title = $showPoints ? "Points" : "Parts Done";
+        my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
+        $r->print(&Apache::loncommon::start_data_table_row()
                  .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
-	$r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
-	$title = $showPoints ? "Points" : "Parts";
-	$r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
+        $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
+        $title = $showPoints ? "Points" : "Parts";
+        $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
                  .&Apache::loncommon::end_data_table_row());
     }
 
     $r->print(&Apache::loncommon::end_data_table()
              .&Apache::loncommon::end_page());
 
-    return OK;
 }
 
 # Pass this two refs to arrays for the start and end color, and a number
 # from 0 to 1 for how much of the latter you want to mix in. It will
 # return a string ready to show ("#FFC309");
+
 sub mixColors {
     my $start = shift;
     my $end = shift;