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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 11 Dec 2003 15:48:56 -0000


matthew		Thu Dec 11 10:48:56 2003 EDT

  Modified files:              
    /loncom/interface/statistics	lonstudentassessment.pm 
  Log:
  Bug 2475: chart blows up on Excel output for some "Output Data" choices.
  Fixed.  The issue was using Excel formulas when they were not defined.
  Should be in 1.1 release.
  
  
Index: loncom/interface/statistics/lonstudentassessment.pm
diff -u loncom/interface/statistics/lonstudentassessment.pm:1.78 loncom/interface/statistics/lonstudentassessment.pm:1.79
--- loncom/interface/statistics/lonstudentassessment.pm:1.78	Tue Dec  9 12:00:07 2003
+++ loncom/interface/statistics/lonstudentassessment.pm	Thu Dec 11 10:48:56 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentassessment.pm,v 1.78 2003/12/09 17:00:07 matthew Exp $
+# $Id: lonstudentassessment.pm,v 1.79 2003/12/11 15:48:56 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1035,40 +1035,28 @@
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                                              ($rows_output,$cols_output-1);
             $seq->{'Excel:endcol'}=$cols_output-1;
-            # Determine cell the score is held in
-            $seq->{'Excel:scorecell'} = 
-                &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
-                                             ($rows_output,$cols_output);
-            $seq->{'Excel:scorecol'}=$cols_output;
-            $excel_sheet->write($rows_output,$cols_output++,'score');
             # Create the formula for summing up this sequence
             $seq->{'Excel:sum'}= $excel_sheet->store_formula
                                         ('=SUM('.$seq->{'Excel:startcell'}.
                                              ':'.$seq->{'Excel:endcell'}.')');
-            #
-            $total_formula_string.='+'.
-                &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
-                                        ($rows_output,$cols_output-1);
-            $excel_sheet->write($rows_output,$cols_output++,'maximum');
-        } elsif ($data eq 'sum and total') {
-            $excel_sheet->write($rows_output+1,$cols_output,'score');
-            $total_formula_string.='+'.
-                &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
-                                        ($rows_output+1,$cols_output);
-            $excel_sheet->write($rows_output+1,$cols_output+1,'maximum');
-            $cols_output += 2;
-        } elsif ($data eq 'parts correct total') {
-            $excel_sheet->write($rows_output+1,$cols_output,'parts correct');
-            $total_formula_string.='+'.
-                &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
-                                        ($rows_output+1,$cols_output);
-            $excel_sheet->write($rows_output+1,$cols_output+1,'maximum');
-            $cols_output += 2;
+        }
+        # Determine cell the score is held in
+        $seq->{'Excel:scorecell'} = 
+            &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+            ($rows_output,$cols_output);
+        $seq->{'Excel:scorecol'}=$cols_output;
+        if ($data eq 'parts correct total') {
+            $excel_sheet->write($rows_output,$cols_output++,'parts correct');
         } else {
-            $cols_output++;
+            $excel_sheet->write($rows_output,$cols_output++,'score');
         }
+        #
+        $total_formula_string.='+'.
+            &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+            ($rows_output,$cols_output-1);
+        $excel_sheet->write($rows_output,$cols_output++,'maximum');
     }
-    $excel_sheet->write($rows_output,$cols_output,'Grand Total');
+    $excel_sheet->write($rows_output,$cols_output++,'Grand Total');
     $total_formula = $excel_sheet->store_formula($total_formula_string);
     #
     # Bookkeeping
@@ -1091,6 +1079,7 @@
     #
     # Add the maximums for each sequence or assessment
     my %total_cell_translation;
+    my $grand_total = 0;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
         $total_cell_translation{$seq->{'Excel:scorecell'}} = 
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
@@ -1120,20 +1109,31 @@
         if (! ($data eq 'sum only' || $data eq 'parts correct')) {
             $excel_sheet->write($rows_output,$cols_output++,'');
         }
-        my %replaceCells;
-        $replaceCells{$seq->{'Excel:startcell'}} = 
-            &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
-                                   ($rows_output,$seq->{'Excel:startcol'});
-        $replaceCells{$seq->{'Excel:endcell'}} = 
-            &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
-                                   ($rows_output,$seq->{'Excel:endcol'});
+        #
+        if ($data eq 'tries' || $data eq 'scores') {
+            my %replaceCells;
+            $replaceCells{$seq->{'Excel:startcell'}} = 
+                &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+                ($rows_output,$seq->{'Excel:startcol'});
+            $replaceCells{$seq->{'Excel:endcell'}} = 
+                &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+                ($rows_output,$seq->{'Excel:endcol'});
+            $excel_sheet->repeat_formula($rows_output,$cols_output++,
+                                         $seq->{'Excel:sum'},undef,
+                                         %replaceCells);
+        } else {
+            $excel_sheet->write($rows_output,$cols_output++,
+                                $max);
+        }
+        $grand_total+=$max;
+    }
+    if ($data eq 'tries' || $data eq 'scores') {
         $excel_sheet->repeat_formula($rows_output,$cols_output++,
-                                     $seq->{'Excel:sum'},undef,
-                                     %replaceCells);
+                                     $total_formula,undef,
+                                     %total_cell_translation);
+    } else {
+        $excel_sheet->write($rows_output,$cols_output++,$grand_total);
     }
-    $excel_sheet->repeat_formula($rows_output,$cols_output++,
-                                 $total_formula,undef,
-                                 %total_cell_translation);
     $rows_output++;
     #
     # Let the user know what we are doing