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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 11 Feb 2004 16:02:37 -0000


matthew		Wed Feb 11 11:02:37 2004 EDT

  Modified files:              
    /loncom/interface/statistics	lonstudentassessment.pm 
  Log:
  Improve spreadsheet output by adding formats and being more explicit about
  where columns are (so errors will be less likely to cascade throughout the 
  sheet).
  
  
Index: loncom/interface/statistics/lonstudentassessment.pm
diff -u loncom/interface/statistics/lonstudentassessment.pm:1.84 loncom/interface/statistics/lonstudentassessment.pm:1.85
--- loncom/interface/statistics/lonstudentassessment.pm:1.84	Tue Feb 10 11:47:25 2004
+++ loncom/interface/statistics/lonstudentassessment.pm	Wed Feb 11 11:02:37 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentassessment.pm,v 1.84 2004/02/10 16:47:25 matthew Exp $
+# $Id: lonstudentassessment.pm,v 1.85 2004/02/11 16:02:37 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -956,9 +956,22 @@
     $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
     $excel_sheet = $excel_workbook->addworksheet($sheetname);
     #
+    # Define some potentially useful formats
+    my $format;
+    $format->{'header'} = $excel_workbook->add_format(bold      => 1, 
+                                                      bottom    => 1,
+                                                      align     => 'center');
+    $format->{'bold'} = $excel_workbook->add_format(bold=>1);
+    $format->{'h1'}   = $excel_workbook->add_format(bold=>1, size=>18);
+    $format->{'h2'}   = $excel_workbook->add_format(bold=>1, size=>16);
+    $format->{'h3'}   = $excel_workbook->add_format(bold=>1, size=>14);
+    $format->{'date'} = $excel_workbook->add_format(num_format=>
+                                                    'mmm d yyyy hh:mm AM/PM');
+    #
     # Put the course description in the header
     $excel_sheet->write($rows_output,$cols_output++,
-                   $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
+                   $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
+                        $format->{'h1'});
     $cols_output += 3;
     #
     # Put a description of the sections listed
@@ -978,15 +991,17 @@
             $sectionstring = "Section ".$Sections[0];
         }
     }
-    $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
+    $excel_sheet->write($rows_output,$cols_output++,$sectionstring,
+                        $format->{'h3'});
     $cols_output += scalar(@Sections);
     #
     # Put the date in there too
     $excel_sheet->write($rows_output++,$cols_output++,
-                        'Compiled on '.localtime(time));
+                        'Compiled on '.localtime(time),$format->{'h3'});
     #
     $cols_output = 0;
-    $excel_sheet->write($rows_output++,$cols_output++,$datadescription);
+    $excel_sheet->write($rows_output++,$cols_output++,$datadescription,
+                        $format->{'h3'});
     #
     if ($data eq 'tries' || $data eq 'scores') {
         $rows_output++;
@@ -995,7 +1010,8 @@
     # Add the student headers
     $cols_output = 0;
     foreach my $field (&get_student_fields_to_show()) {
-        $excel_sheet->write($rows_output,$cols_output++,$field);
+        $excel_sheet->write($rows_output,$cols_output++,$field,
+                            $format->{'bold'});
     }
     my $row_offset = 0;
     if ($data eq 'tries' || $data eq 'scores') {
@@ -1006,7 +1022,7 @@
     my $total_formula_string = '=0';
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
         $excel_sheet->write($rows_output+$row_offset,
-                            $cols_output,$seq->{'title'});
+                            $cols_output,$seq->{'title'},$format->{'h3'});
         if ($data eq 'tries' || $data eq 'scores') {
             # Determine starting cell
             $seq->{'Excel:startcell'}=
@@ -1026,12 +1042,13 @@
                     foreach my $part (@{$res->{'parts'}}) {
                         $excel_sheet->write($rows_output,
                                             $cols_output++,
-                                            $res->{'title'}.' part '.$part);
+                                            $res->{'title'}.' part '.$part,
+                                            $format->{'bold'});
                     }
                 } else {
                     $excel_sheet->write($rows_output,
                                         $cols_output++,
-                                        $res->{'title'});
+                                        $res->{'title'},$format->{'bold'});
                 }
                 $count++;
             }
@@ -1060,17 +1077,21 @@
             ($rows_output,$cols_output);
         $seq->{'Excel:scorecol'}=$cols_output;
         if ($data eq 'parts correct total') {
-            $excel_sheet->write($rows_output,$cols_output++,'parts correct');
+            $excel_sheet->write($rows_output,$cols_output++,'parts correct',
+                                $format->{'bold'});
         } else {
-            $excel_sheet->write($rows_output,$cols_output++,'score');
+            $excel_sheet->write($rows_output,$cols_output++,'score',
+                                $format->{'bold'});
         }
         #
         $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++,'maximum',
+                            $format->{'bold'});
     }
-    $excel_sheet->write($rows_output,$cols_output++,'Grand Total');
+    $excel_sheet->write($rows_output,$cols_output++,'Grand Total',
+                        $format->{'bold'});
     $total_formula = $excel_sheet->store_formula($total_formula_string);
     #
     # Bookkeeping
@@ -1085,7 +1106,8 @@
     foreach my $field (&get_student_fields_to_show()) {
         if ($field eq 'username' || $field eq 'fullname' || 
             $field eq 'id') {
-            $excel_sheet->write($rows_output,$cols_output++,'Maximum');
+            $excel_sheet->write($rows_output,$cols_output++,'Maximum',
+                                $format->{'bold'});
         } else {
             $excel_sheet->write($rows_output,$cols_output++,'');
         }
@@ -1152,10 +1174,17 @@
     #
     # Let the user know what we are doing
     my $studentcount = scalar(@Apache::lonstatistics::Students); 
-    $r->print("<h1>Compiling Excel spreadsheet for ".
-              $studentcount.' student');
-    $r->print('s') if ($studentcount > 1);
-    $r->print("</h1>\n");
+    if ($ENV{'form.SelectedStudent'}) {
+        $studentcount = '1';
+    }
+    if ($studentcount > 1) {
+        $r->print('<h1>'.&mt('Compiling Excel spreadsheet for [_1] students',
+                             $studentcount)."</h1>\n");
+    } else {
+        $r->print('<h1>'.
+                  &mt('Compiling Excel spreadsheet for 1 student').
+                  "</h1>\n");
+    }
     $r->rflush();
     #
     # Initialize progress window
@@ -1193,6 +1222,7 @@
     # Write out sequence scores and totals data
     my %total_cell_translation;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+        $cols_output = $seq->{'Excel:startcol'};
         # Keep track of cells to translate in total cell
         $total_cell_translation{$seq->{'Excel:scorecell'}} = 
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
@@ -1244,7 +1274,6 @@
     $excel_sheet->repeat_formula($rows_output,$cols_output++,
                                  $total_formula,undef,
                                  %total_cell_translation);
-
     #
     # Bookkeeping
     $rows_output++;