--- loncom/interface/statistics/lonproblemanalysis.pm	2005/11/07 22:09:00	1.122
+++ loncom/interface/statistics/lonproblemanalysis.pm	2006/08/17 21:19:47	1.127
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemanalysis.pm,v 1.122 2005/11/07 22:09:00 albertel Exp $
+# $Id: lonproblemanalysis.pm,v 1.127 2006/08/17 21:19:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,6 +38,9 @@ use Apache::lonstudentsubmissions();
 use HTML::Entities();
 use Time::Local();
 use capa;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+  
 
 my $plotcolors = ['#33ff00', 
                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
@@ -59,6 +62,7 @@ sub BuildProblemAnalysisPage {
     #
     my %Saveable_Parameters = ('Status' => 'scalar',
                                'Section' => 'array',
+                               'Groups' => 'array',
                                'NumPlots' => 'scalar',
                                'AnalyzeOver' => 'scalar',
                                );
@@ -74,7 +78,7 @@ sub BuildProblemAnalysisPage {
     my @Students = @Apache::lonstatistics::Students;
     #
     if (@Students < 1 && exists($env{'form.firstrun'})) {
-        $r->print('<h2>There are no students in the sections selected</h2>');
+        $r->print('<h2>There are no students in the sections/groups selected</h2>');
     }
     #
     my @CacheButtonHTML = 
@@ -97,8 +101,11 @@ sub BuildProblemAnalysisPage {
             $r->print($html.('&nbsp;'x5));
         }
         #
-        $r->print(&Apache::lonstathelpers::submission_report_form
-                                                      ('problem_analysis'));
+
+        # This is commented out pending actual implementation of 
+        # CSV and Excel output.
+        #$r->print(&Apache::lonstathelpers::submission_report_form
+        #                                              ('problem_analysis'));
         #
         $r->print('<hr />');
         $r->rflush();
@@ -191,6 +198,7 @@ sub numerical_response_analysis {
     # Gather student data
     my $response_data = &Apache::loncoursedata::get_response_data
         ([&Apache::lonstatistics::get_selected_sections()],
+         [&Apache::lonstatistics::get_selected_groups()],
          $Apache::lonstatistics::enrollment_status,
          $resource->symb,$respid);
     #
@@ -398,7 +406,8 @@ sub numerical_plot_differences {
     } elsif ($low_bin < 0 && $high_bin < -$low_bin) {
         $high_bin = -$low_bin;
     }
-    if (($high_bin -$low_bin)/$min_bin_size * 2 > $max_bins) {
+    if (!$min_bin_size ||
+        ($high_bin -$low_bin)/$min_bin_size * 2 > $max_bins) {
         $min_bin_size = abs($high_bin - $low_bin) / $max_bins * 2;
     }
     my @bins;
@@ -778,6 +787,7 @@ sub radio_response_analysis {
     # Gather student data
     my $response_data = &Apache::loncoursedata::get_response_data
         ([&Apache::lonstatistics::get_selected_sections()],
+         [&Apache::lonstatistics::get_selected_groups()],
          $Apache::lonstatistics::enrollment_status,
          $resource->symb,$respid);
     my $correct;   # either a hash reference or a scalar
@@ -790,7 +800,7 @@ sub radio_response_analysis {
             my ($idx,@remainder) = split('&',$student->{'answer'});
             my ($answer) = ($remainder[$idx]=~/^(.*)=([^=]*)$/);
             $correct->{$student->{'username'}.':'.$student->{'domain'}}=
-                &Apache::lonnet::unescape($answer);
+                &unescape($answer);
         }
     } else {
         foreach my $foil (keys(%$foildata)) {
@@ -1183,6 +1193,7 @@ sub OptionResponseAnalysis {
     # Note: part data is not needed.
     my $PerformanceData = &Apache::loncoursedata::get_response_data
         ([&Apache::lonstatistics::get_selected_sections()],
+         [&Apache::lonstatistics::get_selected_groups()],
          $Apache::lonstatistics::enrollment_status,
          $resource->symb,$respid);
     if (! defined($PerformanceData) || 
@@ -1819,11 +1830,11 @@ sub CreateInterface {
     ##
     ## Build the menu
     my $Str = '';
-    $Str .= &Apache::lonhtmlcommon::breadcrumbs
-        (undef,'Detailed Problem Analysis');
+    $Str .= &Apache::lonhtmlcommon::breadcrumbs('Detailed Problem Analysis');
     $Str .= '<table cellspacing="5">'."\n";
     $Str .= '<tr>';
     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
+    $Str .= '<td align="center"><b>'.&mt('Groups').'</b></td>';
     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
     $Str .= '<td align="center">&nbsp;</td>';
     $Str .= '</tr>'."\n";
@@ -1833,6 +1844,10 @@ sub CreateInterface {
     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
     $Str .= '</td>';
     #
+    $Str .= '<td align="center">'."\n";
+    $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
+    $Str .= '</td>';
+    #
     $Str .= '<td align="center">';
     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
     $Str .= '</td>';
@@ -1925,7 +1940,7 @@ sub hashify_attempt {
     my %attempt;
     $attempt{'student'}    = $row->[&Apache::loncoursedata::RD_sname()];
     $attempt{'tries'}      = $row->[&Apache::loncoursedata::RD_tries()];
-    $attempt{'submission'} = &Apache::lonnet::unescape($row->[&Apache::loncoursedata::RD_submission()]);
+    $attempt{'submission'} = &unescape($row->[&Apache::loncoursedata::RD_submission()]);
     $attempt{'award'}      = $row->[&Apache::loncoursedata::RD_awarddetail()];
     $attempt{'timestamp'}  = $row->[&Apache::loncoursedata::RD_timestamp()];
     return %attempt;
@@ -1949,12 +1964,12 @@ sub Process_OR_Row {
     my @Foilsubs   = split('&',$submission);
     for (my $j=0;$j<=$#Foilgrades;$j++) {
         my ($foilid,$correct)  = split('=',$Foilgrades[$j]);
-        $foilid = &Apache::lonnet::unescape($foilid);
+        $foilid = &unescape($foilid);
         my (undef,$submission) = split('=',$Foilsubs[$j]);
         if ($correct) {
             $RowData{$foilid}->{'_correct'}++;
         } else {
-            $submission = &Apache::lonnet::unescape($submission);
+            $submission = &unescape($submission);
             $RowData{$foilid}->{$submission}++;
         }
         $RowData{$foilid}->{'_total'}++;