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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 07 Oct 2003 16:07:40 -0000


matthew		Tue Oct  7 12:07:40 2003 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemanalysis.pm 
  Log:
  Cleanups and added error checking to the entire module.  More is probably
  needed.
  
  
Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.25 loncom/interface/statistics/lonproblemanalysis.pm:1.26
--- loncom/interface/statistics/lonproblemanalysis.pm:1.25	Mon Oct  6 16:51:20 2003
+++ loncom/interface/statistics/lonproblemanalysis.pm	Tue Oct  7 12:07:39 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemanalysis.pm,v 1.25 2003/10/06 20:51:20 matthew Exp $
+# $Id: lonproblemanalysis.pm,v 1.26 2003/10/07 16:07:39 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,39 +46,40 @@
         my ($symb,$part,$resid) = &get_problem_symb(
                      &Apache::lonnet::unescape($ENV{'form.problemchoice'})
                                            );
-        $r->print('<hr />');
         my $resource = &get_resource_from_symb($symb);
         if (defined($resource)) {
             my %Data = &get_problem_data($resource->{'src'});
             my $ORdata = $Data{$part.'.'.$resid};
             ##
-            ## Render the problem for display
+            ## Render the problem
             my $base;
             ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
             $base = "http://".$ENV{'SERVER_NAME'}.$base;
-            $r->print('</form>'.
-                      '<table bgcolor="ffffff"><tr><td>'.
+            my $rendered_problem = 
+                &Apache::lonnet::ssi_body($resource->{'src'});
+            $rendered_problem =~ s/<form /<nop /g;
+            $rendered_problem =~ s/<\s*\/form\s>/<\/nop>/g;
+            $r->print('<table bgcolor="ffffff"><tr><td>'.
                       '<base href="'.$base.'" />'.
-#                      &Apache::loncommon::get_student_view
-#                      ($symb,$ENV{'user.name'},$ENV{'user.domain'},$ENV{'request.course.id'},'web').
-                      &Apache::lonnet::ssi_body($resource->{'src'}).
-                      '</td></tr></table>'.
-           '<form name="Statistics" method="post" action="/adm/statistics">');
+                      $rendered_problem.
+                      '</td></tr></table>');
             ##
             ## Analyze the problem
-            my @Data = &Apache::loncoursedata::get_optionresponse_data
-                (undef,$symb,$resid);
-            my $analysis_html = &DoTriesAnalysis(\@Data,$ORdata);
-            $r->print($analysis_html);
+            my $PerformanceData = 
+                &Apache::loncoursedata::get_optionresponse_data
+                                             (undef,$symb,$resid);
+            if (defined($PerformanceData) && 
+                ref($PerformanceData) eq 'ARRAY') {
+                my $analysis_html = &DoTriesAnalysis($PerformanceData,$ORdata);
+                $r->print($analysis_html);
+            } else {
+                $r->print('<h2>'.
+                          &mt('There is no student data for this problem.').
+                          '</h2>');
+            }
         } else {
             $r->print('resource is undefined');
         }
-        $r->print('<ol>');
-        $r->print("<li /><strike>render problem</strike>\n");
-        $r->print("<li /><strike>Get student response data</strike>\n");
-        $r->print("<li />image tag for plot\n");
-        $r->print("<li />plot key\n");
-        $r->print('</ol>');
         $r->print('<hr />');
     } else {
         $r->print('<h3>No Problem Selected</h3>');
@@ -89,16 +90,16 @@
 
 
 sub DoTriesAnalysis {
-    my ($Data,$ORdata) = @_;
+    my ($PerformanceData,$ORdata) = @_;
     my $mintries = 1;
     my $maxtries = 3;
-    my %ResponseData = &analyze_option_data_by_tries($Data,
+    my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
                                                  $mintries,$maxtries);
     my @Foils = sort(keys(%ResponseData));
     my %Row_Label;
     foreach my $foilid (@Foils) {
         my $value = $ORdata->{'Foiltext'}->{$foilid};
-        &Apache::lonnet::logthis('row label '.$foilid.' = '.$value);
+#        &Apache::lonnet::logthis('row label '.$foilid.' = '.$value);
         $Row_Label{$foilid} = $ORdata->{'Foiltext'}->{$foilid};
     }
     my @Rows;
@@ -164,11 +165,12 @@
 }
 
 sub analyze_option_data_by_tries {
-    my ($data,$mintries,$maxtries) = @_;
+    my ($PerformanceData,$mintries,$maxtries) = @_;
     my %Trydata;
     $mintries = 1         if (! defined($mintries) || $mintries < 1);
     $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
-    foreach my $row (@$data) {
+    foreach my $row (@$PerformanceData) {
+        next if (! defined($row));
         my ($grading,$submission,$time,$tries) = @$row;
         my @Foilgrades = split('&',$grading);
         my @Foilsubs   = split('&',$submission);
@@ -202,6 +204,9 @@
 
 sub DrawGraph {
     my ($title,$xlabel,$ylabel,$MaxY,$values1,$values2)=@_;
+    if (! defined($values1) || ref($values1) ne 'ARRAY') {
+        return '';
+    }
     $title  = '' if (! defined($title));
     $xlabel = '' if (! defined($xlabel));
     $ylabel = '' if (! defined($ylabel));
@@ -280,7 +285,7 @@
         my $seq_str = '';
         foreach my $res (@{$seq->{'contents'}}) {
 #            &Apache::lonnet::logthis('checking '.$res->{'title'});
-#            next if ($res->{'type'} ne 'assessment');
+            next if ($res->{'type'} ne 'assessment');
             foreach my $part (@{$res->{'parts'}}) {
                 my $partdata = $res->{'partdata'}->{$part};
                 if (! exists($partdata->{'option'}) || 
@@ -359,8 +364,8 @@
                         $Partdata{$part}->{$foil}->{'Concept'}=$concept;
                     }
                 }
-                &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
-                                         join(', ',@$value));
+ #               &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
+ #                                        join(', ',@$value));
             } else {
                 $value =~ s/^\s*//g;
                 $value =~ s/\s*$//g;
@@ -371,7 +376,7 @@
                     my $foil = $1;
                     $Partdata{$part}->{'FoilValues'}->{$foil}=$value;
                 }
-                &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
+#                &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
             }
         }
     }