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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 16 Sep 2004 21:54:23 -0000


This is a MIME encoded message

--matthew1095371663
Content-Type: text/plain

matthew		Thu Sep 16 17:54:23 2004 EDT

  Modified files:              
    /loncom/interface/statistics	lonstathelpers.pm 
                                	lonstudentsubmissions.pm 
  Log:
  lonstathelpers: removed $ResponseTypes input from MultipleProblemSelector
  Added parameter $update_message to manage_caches.
  lonstudentsubmissions:Removed useless calls to get_problem_data, added
  warning about the amount of time it takes to compute correct answers,
  new_excel_output: determine number of columns we will use in the excel
    spreadsheet and abort if it's too many, added support for correct answer
    printing
  added &get_problem_data which is not currently used and probably won't be
  Excel output is the only working output still.
  
  
--matthew1095371663
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040916175423.txt"

Index: loncom/interface/statistics/lonstathelpers.pm
diff -u loncom/interface/statistics/lonstathelpers.pm:1.22 loncom/interface/statistics/lonstathelpers.pm:1.23
--- loncom/interface/statistics/lonstathelpers.pm:1.22	Thu Sep 16 10:28:19 2004
+++ loncom/interface/statistics/lonstathelpers.pm	Thu Sep 16 17:54:22 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstathelpers.pm,v 1.22 2004/09/16 14:28:19 matthew Exp $
+# $Id: lonstathelpers.pm,v 1.23 2004/09/16 21:54:22 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -169,7 +169,7 @@
 
 =pod
 
-=item &MultpleProblemSelector($navmap,$ResponseTypes,$selected,$inputname)
+=item &MultpleProblemSelector($navmap,$selected,$inputname)
 
 Generate HTML with checkboxes for problem selection.
 
@@ -178,10 +178,6 @@
 $navmap: a navmap object.  If undef, navmaps will be called to create a
 new object.
 
-$ResponseTypes: scalar containing regular expression which matches response 
-types.  Only those problems which contain the given response type will be 
-shown.
-
 $selected: Scalar, Array, or hash reference of currently selected items.
 
 $inputname: The name of the form elements to use for the checkboxs.
@@ -194,7 +190,7 @@
 ####################################################
 ####################################################
 sub MultipleProblemSelector {
-    my ($navmap,$ReponseTypes,$inputname,$formname)=@_;
+    my ($navmap,$inputname,$formname)=@_;
     my $cid = $ENV{'request.course.id'};
     my $Str;
     # Massage the input as needed.
@@ -284,14 +280,15 @@
         sub {
             if (@_) { 
                 my ($res,$checked) = @_;
-                $target.='<tr><td>'.
+                $target.='<tr><td><label>'.
                     '<input type="checkbox" name="'.$inputname.'" ';
                 if ($checked) {
                     $target .= 'checked ';
                 }
                 $target.= 
                     'value="'.&Apache::lonnet::escape($res->symb).'" />'.
-                    '</td><td>'.&get_title($res->title,$res->symb).'</td>'.
+                    '&nbsp;'.
+                    &get_title($res->title,$res->symb).'</label></td>'.
                     '</tr>'.$/;
             } else { 
                 if (defined($target)) {
@@ -1244,7 +1241,7 @@
 ####################################################
 ####################################################
 sub manage_caches {
-    my ($r,$formname,$inputname) = @_;
+    my ($r,$formname,$inputname,$update_message) = @_;
     &Apache::loncoursedata::clear_internal_caches();
     my $sectionkey = 
         join(',',
@@ -1261,8 +1258,12 @@
         (exists($ENV{'form.prevenrollstatus'}) &&
             $ENV{'form.prevenrollstatus'} ne $statuskey)
         ) {
+        if (defined($update_message)) {
+            $r->print($update_message);
+        }
         &Apache::lonstatistics::Gather_Full_Student_Data($r,$formname,
                                                          $inputname);
+            
     }
     #
     my @Buttons = 
Index: loncom/interface/statistics/lonstudentsubmissions.pm
diff -u loncom/interface/statistics/lonstudentsubmissions.pm:1.18 loncom/interface/statistics/lonstudentsubmissions.pm:1.19
--- loncom/interface/statistics/lonstudentsubmissions.pm:1.18	Wed Sep 15 17:08:50 2004
+++ loncom/interface/statistics/lonstudentsubmissions.pm	Thu Sep 16 17:54:22 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentsubmissions.pm,v 1.18 2004/09/15 21:08:50 matthew Exp $
+# $Id: lonstudentsubmissions.pm,v 1.19 2004/09/16 21:54:22 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -67,7 +67,8 @@
     }
     #
     my @CacheButtonHTML = 
-        &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
+        &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status',
+                                   '<h3>'.&mt('Loading student data').'</h3>');
     $r->rflush();
     #
     if (exists($ENV{'form.problemchoice'}) && 
@@ -123,40 +124,21 @@
                     $r->rflush();
                 }
             }
-            my %Data;
-            if (scalar(@Problems) > 5) {
-                # progress window
-                my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
-                    ($r,'Problem Analysis Status',
-                     'Problem Analysis Progress', 
-                     scalar(@Problems),
-                     'inline',undef,'Statistics','stats_status');
-                foreach my $problem (@Problems) {
-                    $Data{$problem->symb} = 
-                    {&Apache::lonstathelpers::get_problem_data
-                         ($problem->src)};
-                    &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
-                                                             'last problem');
-
-                }
-                &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
-            } else {
-                foreach my $problem (@Problems) {
-                    $Data{$problem->symb} = 
-                    {&Apache::lonstathelpers::get_problem_data
-                         ($problem->src)};
-                }
-            }
-            &new_excel_output($r,\@Problems,\@Students,\%Data);
+            &new_excel_output($r,\@Problems,\@Students);
         }
         $r->print('<hr />');
     } else {
         $r->print('<input type="submit" name="Generate" value="'.
                   &mt('Prepare Report').'" />');
         $r->print('&nbsp;'x5);
-        $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
+        $r->print('<p>'.
+                  &mt('Computing correct answers greatly increasese the amount of time required to prepare a report.').
+                  '</p>');
+        $r->print('<p>'.
+                  &mt('please select problems and use the <b>Prepare Report</b> button to continue.').
+                  '</p>');
         $r->print(&Apache::lonstathelpers::MultipleProblemSelector
-                  (undef,'.','problemchoice','Statistics'));
+                  (undef,'problemchoice','Statistics'));
     }
 }
 
@@ -164,9 +146,27 @@
 #########################################################
 
 sub new_excel_output {
-    my ($r,$Problems,$Students,$ProblemData) = @_;
+    my ($r,$Problems,$Students) = @_;
     my $c = $r->connection();
     #
+    #
+    # Determine the number of columns in the spreadsheet
+    my $columncount = 3; # username, domain, id
+    my $multiplier = 1;
+    $multiplier ++ if ($ENV{'form.correctans'} eq 'true');
+    foreach my $prob (@$Problems) {
+        $columncount += ($multiplier * $prob->countResponses);
+        last if ($columncount > 255);
+    }
+    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>'.$/);
+        $r->rflush();
+        return;
+    }
+    #
+    # Print out a message telling them what we are doing
     if (scalar(@$Problems) > 1) {
         $r->print('<h2>'.
                   &mt('Preparing Excel spreadsheet of student responses to [_1] problems',
@@ -215,7 +215,8 @@
     # Student headers
     my @StudentColumns = ('username','domain','id');
     foreach (@StudentColumns) {
-        $worksheet->write($header_row,$cols_output++,$_,$format->{'bold'});
+        $worksheet->write($header_row,$cols_output++,ucfirst($_),
+                          $format->{'bold'});
     }
     # Problem headers
     foreach my $prob (@$Problems) {
@@ -231,6 +232,10 @@
                                   $resptypes->[$i].', '.$responses->[$i]);
                 $worksheet->write($header_row,$cols_output,'Submission');
                 $cols_output++;
+                if ($ENV{'form.correctans'} eq 'true') {
+                    $worksheet->write($header_row,$cols_output,'Correct');
+                    $cols_output++;
+                }
             }
         }
     }
@@ -265,6 +270,15 @@
                     $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);
+                    }
                 }
             }
         }
@@ -303,7 +317,7 @@
     my ($answer,$responsetype) = @_;
     if ($responsetype eq 'radiobutton') {
         $answer =~ s/=([^=])$//;
-    } elsif ($responsetype eq 'option') {
+    } elsif ($responsetype =~ /^(option|match)$/) {
         $answer = join("\n",
                        map { 
                            &Apache::lonnet::unescape($_) ;
@@ -316,25 +330,40 @@
     return $answer;
 }
 
-
-=pod
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+##
+## Currently not used
+sub get_problem_data {
+    my ($r,$Problems) = @_;
+    #
+    # Analyze 
+    my %Data;
+    if (scalar(@$Problems) > 5) {
+        # progress window
+        my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
+            ($r,'Problem Analysis Status',
+             'Problem Analysis Progress', 
+             scalar(@$Problems),
+             'inline',undef,'Statistics','stats_status');
+        foreach my $problem (@$Problems) {
+            $Data{$problem->symb} = 
+            {&Apache::lonstathelpers::get_problem_data
+                 ($problem->src)};
+            &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
+                                                     'last problem');
+        }
+        &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+    } else {
+        foreach my $problem (@$Problems) {
+            $Data{$problem->symb} = 
+            {&Apache::lonstathelpers::get_problem_data
+                 ($problem->src)};
+        }
+    }
+    return \%Data;
+}
 
 
+=pod
 
 #########################################################
 #########################################################
@@ -1020,15 +1049,15 @@
 sub CreateInterface {
     ##
     ## Output Selection
-    my $OutputSelector = $/.'<select name="output">'.$/;
+    my $output_selector = $/.'<select name="output">'.$/;
     foreach ('HTML','Excel','CSV') {
-        $OutputSelector .= '    <option value="'.lc($_).'"';
+        $output_selector .= '    <option value="'.lc($_).'"';
         if ($ENV{'form.output'} eq lc($_)) {
-            $OutputSelector .= ' selected ';
+            $output_selector .= ' selected ';
         }
-        $OutputSelector .='>'.&mt($_).'</option>'.$/;
+        $output_selector .='>'.&mt($_).'</option>'.$/;
     } 
-    $OutputSelector .= '</select>'.$/;
+    $output_selector .= '</select>'.$/;
     ##
     ## Environment variable initialization
     my $Str = '';
@@ -1064,13 +1093,13 @@
     }
     $ans_checkbox .= 'value="true" />';
     #
-    # Only show last submission checkbox
-    my $last_sub_checkbox = '<input type="checkbox" name="last_sub_only" ';
-    if (exists($ENV{'form.last_sub_only'}) && 
-        $ENV{'form.last_sub_only'} eq 'true') {
-        $last_sub_checkbox .= 'checked ';
+    # Show all submissions checkbox
+    my $all_sub_checkbox = '<input type="checkbox" name="all_sub" ';
+    if (exists($ENV{'form.all_sub'}) && 
+        $ENV{'form.all_sub'} eq 'true') {
+        $all_sub_checkbox .= 'checked ';
     }
-    $last_sub_checkbox.= 'value="true" />';
+    $all_sub_checkbox.= 'value="true" />';
     #
     # Concise view checkbox
     my $concise_view_checkbox = '<input type="checkbox" name="concise" ';
@@ -1080,13 +1109,13 @@
     $concise_view_checkbox .= 'value="true" />';
     #
     $Str .= '<td align="right" halign="top">'.
-#        '<b>'.&mt('Output Format: [_1]',$OutputSelector).'</b><br />'.$/.
+#        '<b>'.&mt('Output Format: [_1]',$output_selector).'</b><br />'.$/.
         '<label><b>'.
         &mt('show problem [_1]',$prob_checkbox).'</b></label><br />'.
         '<label><b>'.
         &mt('compute correct answers [_1]',$ans_checkbox).'</b></label><br />'.
 #        '<label><b>'.
-#        &mt('final answer only [_1]',$last_sub_checkbox).'</b></label><br />'.
+#        &mt('All submission [_1]',$all_sub_checkbox).'</b></label><br />'.
 #        '<label><b>'.
 #        &mt('concise view [_1]',$concise_view_checkbox).'</b></label><br />'.
         '</td>';

--matthew1095371663--