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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 20 Sep 2004 19:24:02 -0000


This is a MIME encoded message

--matthew1095708242
Content-Type: text/plain

matthew		Mon Sep 20 15:24:02 2004 EDT

  Modified files:              
    /loncom/interface/statistics	lonstudentsubmissions.pm 
  Log:
  Excel output only still, but added multiple submission output, problem
  grading output.  In case the user has selected too many problems to get
  data for (> 255 cols), we now tell them the last one we can fit in the
  Excel sheet.  Moved much of the inner most loop of excel sheet writing
  to a subroutine, &write_excel_row.
  
  
--matthew1095708242
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040920152402.txt"

Index: loncom/interface/statistics/lonstudentsubmissions.pm
diff -u loncom/interface/statistics/lonstudentsubmissions.pm:1.19 loncom/interface/statistics/lonstudentsubmissions.pm:1.20
--- loncom/interface/statistics/lonstudentsubmissions.pm:1.19	Thu Sep 16 17:54:22 2004
+++ loncom/interface/statistics/lonstudentsubmissions.pm	Mon Sep 20 15:24:02 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentsubmissions.pm,v 1.19 2004/09/16 21:54:22 matthew Exp $
+# $Id: lonstudentsubmissions.pm,v 1.20 2004/09/20 19:24:02 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -152,16 +152,20 @@
     #
     # Determine the number of columns in the spreadsheet
     my $columncount = 3; # username, domain, id
-    my $multiplier = 1;
-    $multiplier ++ if ($ENV{'form.correctans'} eq 'true');
+    my $response_multiplier = 1;
+    $response_multiplier ++   if ($ENV{'form.correctans'} eq 'true');
+    $response_multiplier += 4 if ($ENV{'form.prob_status'} eq 'true');
+    my $lastprob;
     foreach my $prob (@$Problems) {
-        $columncount += ($multiplier * $prob->countResponses);
+        $columncount += ($response_multiplier * $prob->countResponses);
         last if ($columncount > 255);
+        $lastprob = $prob;
     }
     if ($columncount > 255) {
         $r->print('<h1>'.&mt('Unable to complete request').'</h1>'.$/.
                   '<p>'.&mt('LON-CAPA is unable to produce your Excel spreadsheet because your selections will result in more than 255 columns.  Excel allows only 255 columns in a spreadsheet.').'</p>'.$/.
-                  '<p>'.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem.  Or use HTML or CSV output.').'</p>'.$/);
+                  '<p>'.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem.  Or use HTML or CSV output.').'</p>'.$/.
+                  '<p>'.&mt('The last problem that will fit in the current spreadsheet is [_1].',&get_title($lastprob->title,$lastprob->src)).'</p>');
         $r->rflush();
         return;
     }
@@ -236,6 +240,13 @@
                     $worksheet->write($header_row,$cols_output,'Correct');
                     $cols_output++;
                 }
+                if ($ENV{'form.prob_status'} eq 'true') {
+                    $worksheet->write($header_row,$cols_output++,
+                                      'Award Detail');
+                    $worksheet->write($header_row,$cols_output++,'Attempt');
+                    $worksheet->write($header_row,$cols_output++,'Time');
+                    $worksheet->write($header_row,$cols_output++,'Awarded');
+                }
             }
         }
     }
@@ -245,39 +256,51 @@
         ($r,'Excel File Compilation Status',
          'Excel File Compilation Progress', 
          scalar(@$Students),'inline',undef,'Statistics','stats_status');
+    my $max_row = $rows_output;
     foreach my $student (@$Students) {
         last if ($c->aborted());
         $cols_output = 0;
+        my $student_row = $max_row;
         foreach my $field (@StudentColumns) {
-            $worksheet->write($rows_output,$cols_output++,
+            $worksheet->write($student_row,$cols_output++,
                               $student->{$field});
         }
+        my $last_student_col = $cols_output-1;
+        my $response_count;
         foreach my $prob (@$Problems) {
             foreach my $partid (@{$prob->parts}) {
                 my @Response = $prob->responseIds($partid);
                 my @ResponseType = $prob->responseType($partid);
                 for (my $i=0;$i<=$#Response;$i++) {
+                    my $response_start_col = $last_student_col + 
+                        $response_count * $response_multiplier + 1;
+                    $response_count++;
                     my $respid   = $Response[$i];
                     my $resptype = $ResponseType[$i];
                     my $results = 
                         &Apache::loncoursedata::get_response_data_by_student
                         ($student,$prob->symb(),$respid);
-                    my $final_response = $results->[-1];
-                    my $submission =
-                        $final_response->[
-                                  &Apache::loncoursedata::RDs_submission()
-                                          ];
-                    $submission=&excel_format_response($submission,$resptype);
-                    $worksheet->write($rows_output,$cols_output++,
-                                      $submission);
-                    if ($ENV{'form.correctans'} eq 'true') {
-                        my $correct = 
-                            &Apache::lonstathelpers::analyze_problem_as_student
-                            ($prob,$student->{'username'},$student->{'domain'},
-                             $partid,$respid);
-                        $correct =&excel_format_response($correct,$resptype);
-                        $worksheet->write($rows_output,$cols_output++,
-                                          $correct);
+                    if (! defined($results)) {
+                        $results = [];
+                    }
+                    #
+                    $rows_output = $student_row;
+                    #
+                    for (my $j=scalar(@$results)-1;$j>=0;$j--) {
+                        $cols_output = $response_start_col;
+                        my $response = $results->[$j];
+                        if ($ENV{'form.all_sub'} ne 'true') {
+                            next if ($j ne scalar(@$results)-1);
+                        }
+                        my $cols_output = &write_excel_row
+                            ($worksheet,
+                             $rows_output++,$cols_output,
+                             $response,$student,
+                             $prob,$partid,$respid,
+                             $format,$resptype);
+                        if ($rows_output > $max_row) {
+                            $max_row = $rows_output;
+                        }
                     }
                 }
             }
@@ -303,6 +326,37 @@
     return;
 }
 
+sub write_excel_row {
+    my ($worksheet,$row,$col,$response,$student,$prob,$partid,$respid,
+        $format,$resptype) = @_;
+    # 
+    my $submission =$response->[&Apache::loncoursedata::RDs_submission()];
+    $submission = &excel_format_response($submission,$resptype);
+    $worksheet->write($row,$col++,$submission);
+    if ($ENV{'form.correctans'} eq 'true') {
+        my $correct = &Apache::lonstathelpers::analyze_problem_as_student
+            ($prob,$student->{'username'},$student->{'domain'},
+             $partid,$respid);
+        $correct =&excel_format_response($correct,$resptype);
+        $worksheet->write($row,$col++,$correct);
+    }
+    if ($ENV{'form.prob_status'} eq 'true') {
+        $worksheet->write
+            ($row,$col++,
+             $response->[&Apache::loncoursedata::RDs_awarddetail()]);
+        $worksheet->write
+            ($row,$col++,$response->[&Apache::loncoursedata::RDs_tries()]);
+        $worksheet->write
+            ($row,$col++,
+             &Apache::lonstathelpers::calc_serial
+             ($response->[&Apache::loncoursedata::RDs_timestamp()]),
+             $format->{'date'});
+        $worksheet->write
+            ($row,$col++,$response->[&Apache::loncoursedata::RDs_awarded()]);
+    }
+    return $col;
+}
+
 sub get_title {
     my ($title,$src) = @_;
     if ($title eq '') {
@@ -870,14 +924,6 @@
     $r->rflush();
     
 
-
-
-
-
-
-
-
-
     my @ColumnLabels;
     my @Columns = @DefaultColumns;
     my %seen;
@@ -1101,23 +1147,25 @@
     }
     $all_sub_checkbox.= 'value="true" />';
     #
-    # Concise view checkbox
-    my $concise_view_checkbox = '<input type="checkbox" name="concise" ';
-    if (exists($ENV{'form.concise'}) && $ENV{'form.concise'} eq 'true') {
-        $concise_view_checkbox .= 'checked ';
+    # problem status checkbox
+    my $prob_status_checkbox = '<input type="checkbox" name="prob_status" ';
+    if (exists($ENV{'form.prob_status'}) && 
+        $ENV{'form.prob_status'} eq 'true') {
+        $prob_status_checkbox .= 'checked ';
     }
-    $concise_view_checkbox .= 'value="true" />';
+    $prob_status_checkbox .= 'value="true" />';
     #
     $Str .= '<td align="right" halign="top">'.
-#        '<b>'.&mt('Output Format: [_1]',$output_selector).'</b><br />'.$/.
         '<label><b>'.
-        &mt('show problem [_1]',$prob_checkbox).'</b></label><br />'.
+        &mt('Show problem [_1]',$prob_checkbox).'</b></label><br />'.
+        '<label><b>'.
+        &mt('Show correct answers [_1]',$ans_checkbox).'</b></label><br />'.
+        '<label><b>'.
+        &mt('Show all submissions [_1]',$all_sub_checkbox).
+        '</b></label><br />'.
         '<label><b>'.
-        &mt('compute correct answers [_1]',$ans_checkbox).'</b></label><br />'.
-#        '<label><b>'.
-#        &mt('All submission [_1]',$all_sub_checkbox).'</b></label><br />'.
-#        '<label><b>'.
-#        &mt('concise view [_1]',$concise_view_checkbox).'</b></label><br />'.
+        &mt('Show problem grading [_1]',$prob_status_checkbox).
+        '</b></label><br />'.
         '</td>';
     #
     $Str .= '</tr>'."\n";

--matthew1095708242--