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

stredwic lon-capa-cvs@mail.lon-capa.org
Wed, 14 Aug 2002 16:18:55 -0000


This is a MIME encoded message

--stredwic1029341935
Content-Type: text/plain

stredwic		Wed Aug 14 12:18:55 2002 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm lonstatistics.pm 
    /loncom/interface/statistics	lonproblemanalysis.pm 
                                	lonproblemstatistics.pm 
  Log:
  Added section selection to problem statistics and problem analysis.
  Fixed some divide by zeros in lonproblemstatistics.
  Broke up the table of option response problems and gave them the
  heading of the sequence in which they lie.
  
  
--stredwic1029341935
Content-Type: text/plain
Content-Disposition: attachment; filename="stredwic-20020814121855.txt"

Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.15 loncom/interface/loncoursedata.pm:1.16
--- loncom/interface/loncoursedata.pm:1.15	Wed Aug 14 09:16:31 2002
+++ loncom/interface/loncoursedata.pm	Wed Aug 14 12:18:55 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: loncoursedata.pm,v 1.15 2002/08/14 13:16:31 stredwic Exp $
+# $Id: loncoursedata.pm,v 1.16 2002/08/14 16:18:55 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -396,11 +396,12 @@
                         $beenHere{'o:'.$partId.$currentResourceID}++;
                         if(defined($cache->{'OptionResponses'})) {
                             $cache->{'OptionResponses'}.= ':::'.
-                                $currentResourceID.':'.
+                                $currentSequence.':'.$currentResourceID.':'.
                                 $partId.':'.$responseId;
                         } else {
-                            $cache->{'OptionResponses'}= $currentResourceID.
-                                ':'.$partId.':'.$responseId;
+                            $cache->{'OptionResponses'}= $currentSequence.':'.
+                                $currentResourceID.':'.
+                                $partId.':'.$responseId;
                         }
                     }
                 }
Index: loncom/interface/lonstatistics.pm
diff -u loncom/interface/lonstatistics.pm:1.43 loncom/interface/lonstatistics.pm:1.44
--- loncom/interface/lonstatistics.pm:1.43	Tue Aug 13 11:01:07 2002
+++ loncom/interface/lonstatistics.pm	Wed Aug 14 12:18:55 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonstatistics.pm,v 1.43 2002/08/13 15:01:07 stredwic Exp $
+# $Id: lonstatistics.pm,v 1.44 2002/08/14 16:18:55 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -82,6 +82,16 @@
     &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
     &CheckFormElement($cache, 'sort', 'sort', 'fullname');
     &CheckFormElement($cache, 'download', 'download', 'false');
+    &CheckFormElement($cache, 'StatisticsMaps', 
+                      'StatisticsMaps', 'All Maps');
+    if(defined($ENV{'form.Section'})) {
+        my @sectionsSelected = (ref($ENV{'form.Section'}) ?
+                               @{$ENV{'form.Section'}} :
+                                ($ENV{'form.Section'}));
+        $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
+    } elsif(!defined($cache->{'sectionsSelected'})) {
+        $cache->{'sectionsSelected'} = $cache->{'sectionList'};
+    }
 
     # student assessment
     if(defined($ENV{'form.CreateStudentAssessment'}) ||
@@ -102,15 +112,6 @@
         &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
     &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
 
-    if(defined($ENV{'form.Section'})) {
-        my @sectionsSelected = (ref($ENV{'form.Section'}) ?
-                               @{$ENV{'form.Section'}} :
-                                ($ENV{'form.Section'}));
-        $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
-    } elsif(!defined($cache->{'sectionsSelected'})) {
-        $cache->{'sectionsSelected'} = $cache->{'sectionList'};
-    }
-
     # Problem analysis
     &CheckFormElement($cache, 'Interval', 'Interval', '1');
 
@@ -119,8 +120,6 @@
                       'DisplayFormat', 'Display Table Format');
     &CheckFormElement($cache, 'ProblemStatisticsAscend',
                       'ProblemStatisticsAscend', 'Ascending');
-    &CheckFormElement($cache, 'ProblemStatisticsMaps', 
-                      'ProblemStatisticsMaps', 'All Maps');
     &CheckFormElement($cache, 'ProblemStatisticsSort',
                       'ProblemStatisticsSort', 'Homework Sets Order');
     &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend', 'Hide Legend');
Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.6 loncom/interface/statistics/lonproblemanalysis.pm:1.7
--- loncom/interface/statistics/lonproblemanalysis.pm:1.6	Tue Aug 13 10:44:33 2002
+++ loncom/interface/statistics/lonproblemanalysis.pm	Wed Aug 14 12:18:55 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonproblemanalysis.pm,v 1.6 2002/08/13 14:44:33 stredwic Exp $
+# $Id: lonproblemanalysis.pm,v 1.7 2002/08/14 16:18:55 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,6 +39,7 @@
 
 use strict;
 use Apache::lonnet();
+use Apache::lonhtmlcommon();
 use GDBM_File;
 
 my $jr;
@@ -48,11 +49,26 @@
 
     my %cache;
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
-        $r->print('<html><body>Unable to tie database.</body></html>');
+        $r->print('Unable to tie database.');
         return;
     }
 
-    $r->print(&IntervalOptions($cache{'Interval'}));
+    my $Ptr = '';
+    $Ptr .= '<table border="0"><tbody>';
+    $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
+    $Ptr .= '</td>'."\n";
+    $Ptr .= '<td align="left">'."\n";
+    my @sectionsSelected = split(':',$cache{'sectionsSelected'});
+    my @sections = split(':',$cache{'sectionList'});
+    $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
+                                                          \@sectionsSelected,
+                                                          'Statistics');
+    $Ptr .= '</td></tr>'."\n";
+    $Ptr .= '<tr><td align="right"><b>Intervals</b></td>'."\n";
+    $Ptr .= '<td align="left">';
+    $Ptr .= &IntervalOptions($cache{'Interval'});
+    $Ptr .= '</td></tr></table><br>';
+    $r->print($Ptr);
     $r->rflush();
     $r->print(&OptionResponseTable($cache{'OptionResponses'}, \%cache));
 
@@ -69,17 +85,53 @@
 
     my $Str = '</form>';
     my %cache;
-    if(&Apache::loncoursedata::DownloadStudentCourseDataSeparate($students, 'true', 
-                                                                 $cacheDB, 'true', 
-                                                                 'true', $courseID, 
-                                                                 $r, $c) ne 'OK') {
+
+    unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+        $Str .= 'Unable to tie database.';
+        $r->print($Str);
+        return;
+    }
+
+    # Remove students who don't have the proper section.
+    my @sectionsSelected = split(':',$cache{'sectionsSelected'});
+    for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
+        $studentIndex--) {
+        my $value = $cache{$students->[$studentIndex].':section'};
+        my $found = 0;
+        foreach (@sectionsSelected) {
+            if($_ eq 'none') {
+                if($value eq '' || !defined($value) || $value eq ' ') {
+                    $found = 1;
+                    last;
+                }
+            } else {
+                if($value eq $_) {
+                    $found = 1;
+                    last;
+                }
+            }
+        }
+        if($found == 0) {
+            splice(@$students, $studentIndex, 1);
+        }
+    }
+    untie(%cache);
+
+    if(&Apache::loncoursedata::DownloadStudentCourseDataSeparate($students, 
+                                                                 'true', 
+                                                                 $cacheDB, 
+                                                                 'true', 
+                                                                 'true', 
+                                                                 $courseID, 
+                                                                 $r, 
+                                                                 $c) ne 'OK') {
         $r->print($Str);
         return;
     }
 
 
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
-        $Str .= '<html><body>Unable to tie database.</body></html>';
+        $Str .= 'Unable to tie database.';
         $r->print($Str);
         return;
     }
@@ -160,8 +212,7 @@
         }
     }
 
-    my $Ptr = '<br><b>Select number of intervals</b>'."\n".
-       	      '<select name="Interval">'."\n";
+    my $Ptr = '<select name="Interval">'."\n";
     for(my $n=1; $n<=7;$ n++) {
 	$Ptr .= '<option';
         if($interval == $n) {
@@ -176,43 +227,57 @@
 
 sub OptionResponseTable {
     my ($optionResponses,$cache)=@_;
-    my $Str = '';
-    $Str .= '<br><b> Option Response Problems in this course:</b>'."\n";
-    $Str .= '<br><br>'."\n";
-    $Str .= "<table border=2><tr><th> \# </th><th> Problem Title </th>";
-    $Str .= '<th> Resource </th><th> Analysis  </th></tr>'."\n";
 
-    my $number=1;
     my @optionResponses=split(':::', $optionResponses);
     my %partCount;
-    foreach (@optionResponses) {
-        my ($problemId, $part, undef)=split(':',$_);
+    my %sequences;
+    foreach(@optionResponses) {
+        my ($sequence, $problemId, $part, undef)=split(':',$_);
         $partCount{$problemId.':'.$part}++;
+        if(!defined($sequences{$sequence})) {
+            $sequences{$sequence} = $_;
+        } else {
+            $sequences{$sequence} .= ':::'.$_;
+        }
     }
 
-    foreach (@optionResponses) {
-        my ($problemId, $part, $response)=split(':',$_);
-        my $uri = $cache->{$problemId.':source'};
-        my $title = $cache->{$problemId.':title'};
-
-        my $Temp = '<a href="'.$uri.'" target="_blank">'.$title.'</a>';
-        $Str .= '<tr>';
-        $Str .= '<td> '.$number.' </td>';
-        $Str .= '<td bgcolor="#DDFFDD">'.$Temp.'</td>';
-        $Str .= '<td bgcolor="#EEFFCC">'.$uri.'</td>';
-        if($partCount{$problemId.':'.$part} < 2) {
-            $Str .= '<td><input type="submit" name="Analyze:::';
-            $Str .= $problemId.':'.$part.'" value="';
-            $Str .= 'Part '.$part;
-            $Str .= '" /></td></tr>'."\n";
-        } else {
-            $Str .= '<td><input type="submit" name="Analyze:::'.$_.'" value="';
-            $Str .= 'Part '.$part.' Response '.$response;
-            $Str .= '" /></td></tr>'."\n";
+    my $Str = '';
+
+    foreach my $sequence (sort(keys(%sequences))) {
+        my @optionProblems = split(':::', $sequences{$sequence});
+
+        $Str .= '<b>'.$cache->{$sequence.':title'}.'</b>'."\n";
+        $Str .= "<table border=2><tr><th> \# </th><th> Problem Title </th>";
+        $Str .= '<th> Resource </th><th> Analysis  </th></tr>'."\n";
+
+        my $count = 1;
+        foreach(@optionProblems) {
+            my (undef, $problemId, $part, $response)=
+                split(':',$sequences{$sequence});
+            my $uri = $cache->{$problemId.':source'};
+            my $title = $cache->{$problemId.':title'};
+
+            my $Temp = '<a href="'.$uri.'" target="_blank">'.$title.'</a>';
+            $Str .= '<tr>';
+            $Str .= '<td> '.$count.' </td>';
+            $Str .= '<td bgcolor="#DDFFDD">'.$Temp.'</td>';
+            $Str .= '<td bgcolor="#EEFFCC">'.$uri.'</td>';
+            if($partCount{$problemId.':'.$part} < 2) {
+                $Str .= '<td><input type="submit" name="Analyze:::';
+                $Str .= $problemId.':'.$part.'" value="';
+                $Str .= 'Part '.$part;
+                $Str .= '" /></td></tr>'."\n";
+            } else {
+                my $value = $problemId.':'.$part.':'.$response;
+                $Str .= '<td><input type="submit" name="Analyze:::'.$value;
+                $Str .= '" value="';
+                $Str .= 'Part '.$part.' Response '.$response;
+                $Str .= '" /></td></tr>'."\n";
+            }
+            $count++;
         }
-        $number++;
+        $Str .= '</table><br>'."\n";
     }
-    $Str .= '</table>'."\n";
 
     return $Str;
 }
Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.24 loncom/interface/statistics/lonproblemstatistics.pm:1.25
--- loncom/interface/statistics/lonproblemstatistics.pm:1.24	Wed Aug 14 09:13:37 2002
+++ loncom/interface/statistics/lonproblemstatistics.pm	Wed Aug 14 12:18:55 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonproblemstatistics.pm,v 1.24 2002/08/14 13:13:37 stredwic Exp $
+# $Id: lonproblemstatistics.pm,v 1.25 2002/08/14 16:18:55 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -56,6 +56,30 @@
         return;
     }
 
+    # Remove students who don't have the proper section.
+    my @sectionsSelected = split(':',$cache{'sectionsSelected'});
+    for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
+        $studentIndex--) {
+        my $value = $cache{$students->[$studentIndex].':section'};
+        my $found = 0;
+        foreach (@sectionsSelected) {
+            if($_ eq 'none') {
+                if($value eq '' || !defined($value) || $value eq ' ') {
+                    $found = 1;
+                    last;
+                }
+            } else {
+                if($value eq $_) {
+                    $found = 1;
+                    last;
+                }
+            }
+        }
+        if($found == 0) {
+            splice(@$students, $studentIndex, 1);
+        }
+    }
+
     my $Ptr = '';
     $Ptr .= '<table border="0"><tbody>';
     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
@@ -70,6 +94,14 @@
                                             'ProblemStatistics',
                                             'Statistics');
     $Ptr .= '</td></tr>'."\n";
+    $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
+    $Ptr .= '</td>'."\n";
+    $Ptr .= '<td align="left">'."\n";
+    my @sections = split(':',$cache{'sectionList'});
+    $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
+                                                          \@sectionsSelected,
+                                                          'Statistics');
+    $Ptr .= '</td></tr>'."\n";
     $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, 
                                       $cache{'DisplayLegend'});
     $Ptr .= '</table>';
@@ -85,8 +117,12 @@
     my $color=&setbgcolor(0);
 
 #    my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
-#    my ($upper, $lower) = &Discriminant(\%discriminant,$r);
-    if(!defined($cache{'StatisticsCached'})) {
+    my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
+                     $cache{'StatisticsLastStatus'} : 'Nothing';
+    my $whichStudents = join(':::',sort(@$students));
+    if(!defined($cache{'StatisticsCached'}) || 
+       $lastStatus ne $cache{'Status'} ||
+       $whichStudents ne $cache{'StatisticsWhichStudents'}) {
         if(defined($cache{'StatisticsCached'})) {
             untie(%cache);
             unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
@@ -127,6 +163,8 @@
         }
         $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
         $cache{'StatisticsCached'} = 'true';
+        $cache{'StatisticsLastStatus'} = $cache{'Status'};
+        $cache{'StatisticsWhichStudents'} = $whichStudents;
         untie(%cache);
 
         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
@@ -134,6 +172,7 @@
             return;
         }
     }
+
     my $orderedProblems = &SortProblems(\%cache, 
                                         $cache{'ProblemStatisticsSort'},
                                         $cache{'ProblemStatisticsAscend'});
@@ -170,7 +209,6 @@
     untie(%cache);
 
     my $sendValues = join(',', @values);
-#    my $sendCount = $#values;
     my $sendCount = scalar(@values);
 
     my $title = '';
@@ -236,8 +274,8 @@
     my $count = 1;
     foreach(@$orderedProblems) {
         my ($sequence,$problem,$part)=split(':', $_);
-        if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
-           $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
+        if($cache->{'StatisticsMaps'} ne 'All Maps'  &&
+           $cache->{'StatisticsMaps'} ne $cache->{$sequence.':title'}) {
             next;
         }
 
@@ -261,18 +299,6 @@
                        sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),
                        0); # 0 is for discussion, need to figure out
 
-#6666666
-#	    $r->print('<br>'.$out.'&'.$DoD);
-#            print (OUT $out.'@'.$DoD.'&');
-#6666666
-
-#check with Gerd
-#        $urlres=~/^(\w+)\/(\w+)/;
-#        if ($StdNo) {
-#            &Apache::lonnet::put('nohist_resevaldata',\%storestats,
-#                                 $1,$2);
-#        }
-#-------------------------------- Row of statistical table
         &TableRow($displayFormat,$tableData,$count,$r,$color);
         $count++;
     }
@@ -281,6 +307,11 @@
     }
     $r->print('</td></tr></table>');
 #6666666
+#	    $r->print('<br>'.$out.'&'.$DoD);
+#            print (OUT $out.'@'.$DoD.'&');
+#6666666
+
+#6666666
 #    close( OUT );
 #666666
     return;
@@ -647,13 +678,13 @@
         foreach my $name (@upper1) {
             $upper1Sum += $cache->{"$name:$problem:$part:awarded"};
         }
-        $upper1Sum /= (scalar(@upper1)) ? (scalar(@upper1)) : 0;
+        $upper1Sum = (scalar(@upper1)) ? ($upper1Sum/(scalar(@upper1))) : 0;
 
         my $lower1Sum=0;
         foreach my $name (@lower1) {
             $lower1Sum += $cache->{"$name:$problem:$part:awarded"};
         }
-        $lower1Sum /= (scalar(@lower1)) ? (scalar(@lower1)) : 0;
+        $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0;
 
         $data->{$_.':discriminationFactor1'} = $upper1Sum - $lower1Sum;
 
@@ -665,13 +696,13 @@
         foreach my $name (@upper2) {
             $upper2Sum += $cache->{"$name:$problem:$part:awarded"};
         }
-        $upper2Sum /= (scalar(@upper2)) ? (scalar(@upper2)) : 0;
+        $upper2Sum = (scalar(@upper2)) ? ($upper2Sum/(scalar(@upper2))) : 0;
 
         my $lower2Sum=0;
         foreach my $name (@lower2) {
             $lower2Sum += $cache->{"$name:$problem:$part:awarded"};
         }
-        $lower2Sum /= (scalar(@lower2)) ? (scalar(@lower2)) : 0;
+        $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0;
 
         $data->{$_.':discriminationFactor2'} = $upper2Sum - $lower2Sum;
     }

--stredwic1029341935--