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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 21 Dec 2006 19:52:29 -0000


albertel		Thu Dec 21 14:52:29 2006 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemanalysis.pm 
                                	lonsubmissiontimeanalysis.pm 
  Log:
  - bug5095 - handle case of no students and no spread in provided answers
              more correctly (rather than infinite loop)
  
  
Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.128 loncom/interface/statistics/lonproblemanalysis.pm:1.129
--- loncom/interface/statistics/lonproblemanalysis.pm:1.128	Fri Aug 18 11:15:38 2006
+++ loncom/interface/statistics/lonproblemanalysis.pm	Thu Dec 21 14:52:28 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemanalysis.pm,v 1.128 2006/08/18 15:15:38 raeburn Exp $
+# $Id: lonproblemanalysis.pm,v 1.129 2006/12/21 19:52:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -144,25 +144,27 @@
                 $r->print(&Apache::lonstathelpers::render_resource($resource));
             }
             $r->rflush();
-            my %Data = &Apache::lonstathelpers::get_problem_data
-                ($resource->src);
-            my $problem_data = $Data{$current_problem->{'part'}.
-                                    '.'.
-                                    $current_problem->{'respid'}};
-            if ($current_problem->{'resptype'} eq 'option') {
-                &OptionResponseAnalysis($r,$current_problem,
-                                        $problem_data,
-                                        \@Students);
-            } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
-                &radio_response_analysis($r,$current_problem,
-                                         $problem_data,
-                                         \@Students);
-            } elsif ($current_problem->{'resptype'} eq 'numerical') {
-                &numerical_response_analysis($r,$current_problem,
-                                             $problem_data,\@Students);
-            } else {
-                $r->print('<h2>Analysis of '.$current_problem->{'resptype'}.' is not supported</h2>');
-            }
+	    if (@Students) {
+		my %Data = &Apache::lonstathelpers::get_problem_data
+		    ($resource->src);
+		my $problem_data = $Data{$current_problem->{'part'}.
+					     '.'.
+					     $current_problem->{'respid'}};
+		if ($current_problem->{'resptype'} eq 'option') {
+		    &OptionResponseAnalysis($r,$current_problem,
+					    $problem_data,
+					    \@Students);
+		} elsif ($current_problem->{'resptype'} eq 'radiobutton') {
+		    &radio_response_analysis($r,$current_problem,
+					     $problem_data,
+					     \@Students);
+		} elsif ($current_problem->{'resptype'} eq 'numerical') {
+		    &numerical_response_analysis($r,$current_problem,
+						 $problem_data,\@Students);
+		} else {
+		    $r->print('<h2>Analysis of '.$current_problem->{'resptype'}.' is not supported</h2>');
+		}
+	    }
         }
         $r->print('<hr />');
     } else {
@@ -327,11 +329,14 @@
             last;
         }
     }
+    $percent_spread = $highest_percent - $lowest_percent;
     my $bin_size = 1;
     foreach (qw/0.01 0.05 0.1 0.5 1 2 5 10 20 25 50 100/) {
         if ($lowest_percent/2 < $_){
             $bin_size = $_;
-            last;
+	    if ( ($percent_spread/$bin_size) < $max_bins ) {
+		last;
+	    }
         }
     }
     my @bins;
@@ -406,6 +411,10 @@
     } elsif ($low_bin < 0 && $high_bin < -$low_bin) {
         $high_bin = -$low_bin;
     }
+    if ($high_bin == $low_bin) {
+	$high_bin+=1;
+	$low_bin-=1;
+    }
     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;
Index: loncom/interface/statistics/lonsubmissiontimeanalysis.pm
diff -u loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.27 loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.28
--- loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.27	Fri Aug 18 11:15:38 2006
+++ loncom/interface/statistics/lonsubmissiontimeanalysis.pm	Thu Dec 21 14:52:28 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonsubmissiontimeanalysis.pm,v 1.27 2006/08/18 15:15:38 raeburn Exp $
+# $Id: lonsubmissiontimeanalysis.pm,v 1.28 2006/12/21 19:52:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -135,8 +135,10 @@
             $r->print(&Apache::lonstathelpers::render_resource($resource));
             $r->print('<br />');
             $r->rflush();
-            $r->print(&analyze_times($r,$resource->symb,\@Students,
-                                     $current_problem->{'part'}));
+	    if (@Students) {	    
+		$r->print(&analyze_times($r,$resource->symb,\@Students,
+					 $current_problem->{'part'}));
+	    }
         }
         $r->print('<hr />');
     }