--- loncom/interface/statistics/lonproblemanalysis.pm	2004/03/16 16:30:31	1.80
+++ loncom/interface/statistics/lonproblemanalysis.pm	2004/03/22 17:25:27	1.82
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemanalysis.pm,v 1.80 2004/03/16 16:30:31 matthew Exp $
+# $Id: lonproblemanalysis.pm,v 1.82 2004/03/22 17:25:27 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -160,8 +160,17 @@ sub BuildProblemAnalysisPage {
                                        $ProblemData,
                                        \@Students);
             } elsif ($current_problem->{'resptype'} eq 'numerical') {
-                    &NumericalResponseAnalysis($r,$current_problem,
-                                               $ProblemData,\@Students);
+                ## 
+                ## analyze all responses of a problem at once
+                my $res = $current_problem->{'resource'};
+                foreach my $partid (@{$res->{'parts'}}) {
+                    $current_problem->{'part'} = $partid;
+                    foreach my $respid (@{$res->{'partdata'}->{$partid}->{'ResponseIds'}}) {
+                        $current_problem->{'respid'}=$respid;
+                        &NumericalResponseAnalysis($r,$current_problem,
+                                                   $ProblemData,\@Students);
+                    }
+                }
             } else {
                 $r->print('<h2>This analysis is not supported</h2>');
             }
@@ -188,13 +197,29 @@ sub BuildProblemAnalysisPage {
 sub NumericalResponseAnalysis {
     my ($r,$problem,$ProblemData,$Students) = @_;
     my $c = $r->connection();
-    my ($resource,$respid) = ($problem->{'resource'},
-                              $problem->{'respid'});
-    $r->print('Response '.$respid.'</br />');
+    my ($resource,$partid,$respid) = ($problem->{'resource'},
+                                      $problem->{'part'},
+                                      $problem->{'respid'});
+    #
+    if (scalar(@{$resource->{'parts'}})>1) {
+        if (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) {
+            $r->print('<h3>'.
+                      &mt('Part [_1], response [_2].',$partid,$respid).
+                      '</h3>');
+        } else { 
+            $r->print('<h3>'.
+                      &mt('Part [_1]',$partid,$respid).
+                      '</h3>');
+        }
+    } elsif (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) {
+        $r->print('<h3>'.&mt('Response [_1]',$respid).'</h3>');
+    }
+    #
     my $analysis_html;
-    my $PerformanceData = 
-        &Apache::loncoursedata::get_response_data
-        ($Students,$resource->{'symb'},$respid);
+    my $PerformanceData = &Apache::loncoursedata::get_response_data
+        (\@Apache::lonstatistics::SelectedSections,
+         $Apache::lonstatistics::enrollment_status,
+         $resource->{'symb'},$respid);
     if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {
         $analysis_html = '<h2>'.
@@ -205,7 +230,8 @@ sub NumericalResponseAnalysis {
     }
     #
     # This next call causes all the waiting around that people complain about
-    my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);
+    my ($max,$min) = &Apache::lonstathelpers::GetStudentAnswers($r,$problem,
+                                                                $Students);
     return if ($c->aborted());
     #
     # Collate the data
@@ -231,6 +257,9 @@ sub one_dimensional_plot {
     # Compute data -> image scaling factors
     my $min = $Labels->[0];
     my $max = $Labels->[-1];
+    if ($max == $min) {
+        $max =$min+1;
+    }
     my $h_scale = ($width-10)/($max-$min);
     #
     my $max_y = 0;
@@ -293,6 +322,17 @@ sub line {
     return qq{<line x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" />$/};
 }
 
+sub text {
+    my ($x,$y,$color,$text,$font,$direction) = @_;
+    if (! defined($font) || $font !~ /^(tiny|small|medium|large|giant)$/) {
+        $font = 'medium';
+    }
+    if (! defined($direction) || $direction ne 'vertical') {
+        $direction = '';
+    }
+    return qq{<text x="$x" y="$y" color="$color" font="$font" direction="$direction" >$text</text>};
+}
+
 sub rectangle {
     my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
     return qq{<rectangle x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" filled="$filled" />};
@@ -308,38 +348,6 @@ sub circle {
     return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
 }
 
-sub GetStudentAnswers {
-    my ($r,$problem,$Students) = @_;
-    my $c = $r->connection();
-    my %Answers;
-    my ($resource,$partid,$respid) = ($problem->{'resource'},
-                                      $problem->{'part'},
-                                      $problem->{'respid'});
-    # Read in the cache (if it exists) before we start timing things.
-    &Apache::lonstathelpers::ensure_proper_cache($resource->{'symb'});
-    # Open progress window
-    my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
-        ($r,'Student Answer Compilation Status',
-         'Student Answer Compilation Progress', scalar(@$Students));
-    $r->rflush();
-    foreach my $student (@$Students) {
-        last if ($c->aborted());
-        my $sname = $student->{'username'};
-        my $sdom = $student->{'domain'};
-        my $answer = &Apache::lonstathelpers::analyze_problem_as_student
-            ($resource,$sname,$sdom,$partid,$respid);
-        &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
-                                                 &mt('last student'));
-        $student->{'answer'} = $answer;
-    }
-    &Apache::lonstathelpers::write_answer_cache();
-    return if ($c->aborted());
-    $r->rflush();
-    # close progress window
-    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
-    return;
-}
-
 sub build_student_data_worksheet {
     my ($workbook,$format) = @_;
     my $rows_output = 3;
@@ -379,9 +387,10 @@ sub RadioResponseAnalysis {
     my ($resource,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});
     my $analysis_html;
-    my $PerformanceData = 
-        &Apache::loncoursedata::get_response_data
-        ($Students,$resource->{'symb'},$respid);
+    my $PerformanceData = &Apache::loncoursedata::get_response_data
+        (\@Apache::lonstatistics::SelectedSections,
+         $Apache::lonstatistics::enrollment_status,
+         $resource->{'symb'},$respid);
     if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {
         $analysis_html = '<h2>'.
@@ -564,9 +573,10 @@ sub OptionResponseAnalysis {
     my ($resource,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});
     # Note: part data is not needed.
-    my $PerformanceData = 
-        &Apache::loncoursedata::get_response_data
-        ($Students,$resource->{'symb'},$respid);
+    my $PerformanceData = &Apache::loncoursedata::get_response_data
+        (\@Apache::lonstatistics::SelectedSections,
+         $Apache::lonstatistics::enrollment_status,
+         $resource->{'symb'},$respid);
     if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {
         $r->print('<h2>'.