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

matthew lon-capa-cvs@mail.lon-capa.org
Sun, 07 Mar 2004 20:53:41 -0000


This is a MIME encoded message

--matthew1078692821
Content-Type: text/plain

matthew		Sun Mar  7 15:53:41 2004 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
    /loncom/interface/statistics	loncorrectproblemplot.pm 
  Log:
  loncoursedata.pm: &get_student_scores modified to limit by time.
  loncorrectproblemplot.pm: Added time limits, corrected "bin"ing bug which
      caused the last data set to be missed, plot title is now the sequence
      being analyzed or "Multiple Sequences", added "N", the number of students,
      to the title.  Added the maximum possible number of correct problems to
      the x-axis label.
  
  
--matthew1078692821
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040307155341.txt"

Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.120 loncom/interface/loncoursedata.pm:1.121
--- loncom/interface/loncoursedata.pm:1.120	Wed Feb 18 15:48:21 2004
+++ loncom/interface/loncoursedata.pm	Sun Mar  7 15:53:40 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.120 2004/02/18 20:48:21 matthew Exp $
+# $Id: loncoursedata.pm,v 1.121 2004/03/07 20:53:40 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -182,7 +182,7 @@
             next;
         }
         next if (! ref($curRes));
-        next if (! $curRes->is_problem());# && !$curRes->randomout);
+        next if (! $curRes->is_problem() && $curRes->src() !~ /\.survey$/);
         # Okay, from here on out we only deal with assessments
         $title = $curRes->title();
         $title =~ s/\:/\&\#058;/g;
@@ -2232,7 +2232,7 @@
 ################################################
 ################################################
 sub get_student_scores {
-    my ($Sections,$Symbs,$enrollment,$courseid) = @_;
+    my ($Sections,$Symbs,$enrollment,$courseid,$starttime,$endtime) = @_;
     $courseid = $ENV{'request.course.id'} if (! defined($courseid));
     &setup_table_names($courseid);
     my $dbh = &Apache::lonmysql::get_dbh();
@@ -2243,8 +2243,8 @@
     if (defined($Symbs)  && @$Symbs) {
         $symb_requirements = '('.
             join(' OR ', map{ "(a.symb_id='".&get_symb_id($_->{'symb'}).
-                                  "' AND a.part_id='".&get_part_id($_->{'part'}).
-                                  "')"
+                              "' AND a.part_id='".&get_part_id($_->{'part'}).
+                              "')"
                               } @$Symbs).')';
     }
     #
@@ -2259,6 +2259,16 @@
     if (defined($enrollment) && $enrollment ne 'Any') {
         $enrollment_requirements = "b.status='".$enrollment."'";
     }
+    #
+    my $time_requirements = undef;
+    if (defined($starttime)) {
+        $time_requirements .= "a.timestamp>='".$starttime."'";
+        if (defined($endtime)) {
+            $time_requirements .= " AND a.timestamp<='".$endtime."'";
+        }
+    } elsif (defined($endtime)) {
+        $time_requirements .= "a.timestamp<='".$endtime."'";
+    }
     ##
     ##
     my $request = 'CREATE TEMPORARY TABLE IF NOT EXISTS '.$tmptable.
@@ -2281,7 +2291,10 @@
     if (defined($enrollment_requirements)) {
         $request .= $enrollment_requirements.' AND ';
     }
-    $request =~ s/ AND $//;
+    if (defined($time_requirements)) {
+        $request .= $time_requirements.' AND ';
+    }
+    $request =~ s/ AND $//; # Strip of the trailing ' AND '.
     $request .= ' GROUP BY a.student_id';
 #    &Apache::lonnet::logthis("request = \n".$request);
     my $sth = $dbh->prepare($request);
Index: loncom/interface/statistics/loncorrectproblemplot.pm
diff -u loncom/interface/statistics/loncorrectproblemplot.pm:1.8 loncom/interface/statistics/loncorrectproblemplot.pm:1.9
--- loncom/interface/statistics/loncorrectproblemplot.pm:1.8	Mon Mar  1 11:39:19 2004
+++ loncom/interface/statistics/loncorrectproblemplot.pm	Sun Mar  7 15:53:41 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncorrectproblemplot.pm,v 1.8 2004/03/01 16:39:19 matthew Exp $
+# $Id: loncorrectproblemplot.pm,v 1.9 2004/03/07 20:53:41 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -103,22 +103,32 @@
     # Determine which problem symbs we are to sum over
     if (exists($ENV{'form.CreatePlot'})) {
         my @ProblemSymbs;
+        my $total_parts = 0;
+        my $title = '';
         if ($Apache::lonstatistics::SelectedMaps[0] ne 'all') {
             foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()){
+                if ($title eq '') {
+                    $title = $seq->{'title'};
+                } else {
+                    $title = 'Multiple Sequences';
+                }
                 foreach my $res (@{$seq->{'contents'}}) {
                     next if ($res->{'type'} ne 'assessment');
                     foreach my $part (@{$res->{'parts'}}) {
+                        $total_parts++;
                         push(@ProblemSymbs,{symb=>$res->{'symb'},
                                             part=>$part});
                     }
                 }
             }
         }
+        my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
         my $score_data = &Apache::loncoursedata::get_student_scores
             (\@Apache::lonstatistics::SelectedSections,
              \@ProblemSymbs,
-             $Apache::lonstatistics::enrollment_status);
-        $r->print(&AnalyzeScoreData($score_data));
+             $Apache::lonstatistics::enrollment_status,undef,
+             $starttime,$endtime);
+        $r->print(&AnalyzeScoreData($score_data,$title,$total_parts));
     }
     return;
 }
@@ -138,7 +148,7 @@
 #########################################################
 #########################################################
 sub AnalyzeScoreData {
-    my ($score_data) = @_;
+    my ($score_data,$title,$total_parts) = @_;
     #
     # Basic check first
     if (@$score_data < 1) {
@@ -149,6 +159,7 @@
     my $lowest  = $score_data->[0]->[0];
     $lowest = 0;
     my $highest = $score_data->[-1]->[0];
+    &Apache::lonnet::logthis('highest = '.$highest);
     my $binsize = 1;
     if ($highest > 50) { $binsize = 2; }
     if ($highest > 100) { $binsize = 5; }
@@ -161,9 +172,11 @@
     my @Bins = &bin_data($score_data,$binsize,$lowest,$highest);
     my @Xdata; my @Ydata; my $max;
     my $Str = '<table border="1">'."\n".'<tr><th>Range</th><th>Count</th></tr>'."\n";
+    my $sum = 0;
     while (my $bin = shift(@Bins)) {
         push (@Xdata,$bin->{'start'});
         push (@Ydata,$bin->{'count'});
+        $sum += $bin->{'count'};
         if ($bin->{'count'} > $max) {
             $max = $bin->{'count'};
         }
@@ -172,10 +185,10 @@
     }
     # scale max to an integer.
     $max = 5*(int($max/5)+1);
-    my $title = 'Correct Problems Plot';
     $Str .= "</table><br />\n";
-    $Str = "<br />\n".&Apache::loncommon::DrawBarGraph($title,
-                                                       'Num Correct Problems',
+    $title = &HTML::Entities::decode($title);
+    $Str = "<br />\n".&Apache::loncommon::DrawBarGraph($title.' N = '.$sum,
+                                 'Num Correct Problems (max:'.$total_parts.')',
                                                        'Number of students',
                                                        $max,
                                                        undef, # colors
@@ -218,10 +231,10 @@
     my @Bins;
     my $count=0;
     my $idx=0;
-    while ($idx < scalar(@$data) && ($binend-$endbin)<$binsize) {
+    while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>0) {
         my $dataset = $data->[$idx++];
         my ($x,$y) = @{$dataset};
-        while ($x > $binend) {
+        while ($x > ($binend-.001)) {
             # store the old data
             push (@Bins,{ start => $binstart,
                           count => $count,
@@ -233,6 +246,11 @@
         }
         $count+=$y;
     }
+    if ($count > 0) {
+        push (@Bins,{ start => $binstart,
+                      count => $count,
+                      end   => $binend });
+    }
     return @Bins;
 }
 
@@ -262,6 +280,8 @@
     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
     $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
+    $Str .= '<td rowspan="2">'.
+        &Apache::lonstathelpers::limit_by_time_form().'</td>';
     $Str .= '</tr>'."\n";
     ##
     ## 
@@ -283,7 +303,8 @@
     };
     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
                                               $only_seq_with_assessments);
-    $Str .= '</td><td>'."\n";
+    $Str .= '</td>';
+    #
     ##
     $Str .= '</tr>'."\n";
     $Str .= '</table>'."\n";

--matthew1078692821--