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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 22 Mar 2004 17:25:27 -0000


matthew		Mon Mar 22 12:25:27 2004 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
    /loncom/interface/statistics	lonproblemanalysis.pm 
  Log:
  loncoursedata: reworked &get_response_data to take section and enrollment
  as inputs instead of a list of students.
  lonproblemanalysis: Rewrote calls to get_response_data to provide new inputs.
  Modified numerical response analysis to analyzse an entire problem, not just
  one response.  This will probably need to be changed in the future.
  Added &text, which produces <drawimage> text elements.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.125 loncom/interface/loncoursedata.pm:1.126
--- loncom/interface/loncoursedata.pm:1.125	Tue Mar 16 10:54:09 2004
+++ loncom/interface/loncoursedata.pm	Mon Mar 22 12:25:26 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.125 2004/03/16 15:54:09 matthew Exp $
+# $Id: loncoursedata.pm,v 1.126 2004/03/22 17:25:26 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2087,7 +2087,7 @@
 sub RD_sname         { return 6; }
 
 sub get_response_data {
-    my ($students,$symb,$response,$courseid) = @_;
+    my ($Sections,$enrollment,$symb,$response,$courseid) = @_;
     return undef if (! defined($symb) || 
                ! defined($response));
     $courseid = $ENV{'request.course.id'} if (! defined($courseid));
@@ -2098,6 +2098,18 @@
     #
     my $dbh = &Apache::lonmysql::get_dbh();
     return undef if (! defined($dbh));
+    #
+    my $student_requirements;
+    if ( (defined($Sections) && $Sections->[0] ne 'all')) {
+        $student_requirements = '('.
+            join(' OR ', map { "d.section='".$_."'" } @$Sections
+                 ).')';
+    }
+    #
+    my $enrollment_requirements=undef;
+    if (defined($enrollment) && $enrollment ne 'Any') {
+        $enrollment_requirements = "d.status='".$enrollment."'";
+    }
     my $request = 'SELECT '.
         'a.student_id, a.awarddetail, a.response_specific_value, '.
         'a.submission, b.timestamp, c.tries, d.student '.
@@ -2112,13 +2124,15 @@
         'ON a.student_id=d.student_id '.
         'WHERE '.
         'a.symb_id='.$symb_id.' AND a.response_id='.$response_id;
-    if (defined($students)) {
-        $request .= ' AND ('.
-            join(' OR ', map {'a.student_id='.
-                                  &get_student_id($_->{'username'},
-                                                  $_->{'domain'})
-                              } @$students
-                 ).')';
+    if (defined($student_requirements) || defined($enrollment_requirements)) {
+        $request .= ' AND ';
+        if (defined($student_requirements)) {
+            $request .= $student_requirements.' AND ';
+        }
+        if (defined($enrollment_requirements)) {
+            $request .= $enrollment_requirements.' AND ';
+        }
+        $request =~ s/( AND )$//;
     }
     $request .= ' ORDER BY b.timestamp';
 #    &Apache::lonnet::logthis("request =\n".$request);
Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.81 loncom/interface/statistics/lonproblemanalysis.pm:1.82
--- loncom/interface/statistics/lonproblemanalysis.pm:1.81	Tue Mar 16 11:41:26 2004
+++ loncom/interface/statistics/lonproblemanalysis.pm	Mon Mar 22 12:25:27 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemanalysis.pm,v 1.81 2004/03/16 16:41:26 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 @@
                                        $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 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>'.
@@ -232,6 +257,9 @@
     # 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;
@@ -294,6 +322,17 @@
     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" />};
@@ -348,9 +387,10 @@
     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>'.
@@ -533,9 +573,10 @@
     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>'.