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

stredwic lon-capa-cvs@mail.lon-capa.org
Tue, 13 Aug 2002 13:57:26 -0000


This is a MIME encoded message

--stredwic1029247046
Content-Type: text/plain

stredwic		Tue Aug 13 09:57:26 2002 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemstatistics.pm 
  Log:
  Added cached data for problem statistics.  Now it will store the data
  it calculates for the statistics formulas and other constant data.  
  Currently, it doesn't know if a student's course data has been updated.
  
  
--stredwic1029247046
Content-Type: text/plain
Content-Disposition: attachment; filename="stredwic-20020813095726.txt"

Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.20 loncom/interface/statistics/lonproblemstatistics.pm:1.21
--- loncom/interface/statistics/lonproblemstatistics.pm:1.20	Tue Aug 13 08:21:46 2002
+++ loncom/interface/statistics/lonproblemstatistics.pm	Tue Aug 13 09:57:25 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonproblemstatistics.pm,v 1.20 2002/08/13 12:21:46 stredwic Exp $
+# $Id: lonproblemstatistics.pm,v 1.21 2002/08/13 13:57:25 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,7 +52,8 @@
     $jr = $r;
 
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
-        return '<html><body>Unable to tie database.</body></html>';
+        $r->print('Unable to tie database.');
+        return;
     }
 
     my $Ptr = '';
@@ -78,18 +79,6 @@
     $r->print($Ptr);
     $r->rflush();
 
-    untie(%cache);
-
-    &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,'true',
-                                                              $cacheDB,'true', 
-                                                              'true',$courseID,
-                                                              $r, $c);
-    if($c->aborted()) { return; }
-
-    unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
-        return '<html><body>Unable to tie database.</body></html>';
-    }
-
     my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
                   "Mean","#YES","#yes","%Wrng","DoDiff",
                   "S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");
@@ -97,25 +86,46 @@
 
 #    my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
 #    my ($upper, $lower) = &Discriminant(\%discriminant,$r);
-    my ($problemData) = &ExtractStudentData(\%cache, $students);
-    &CalculateStatistics($problemData);
-    &SortProblems($problemData, $cache{'ProblemStatisticsSort'},
-                  $cache{'ProblemStatisticsAscend'});
-    #$TempCache=
-    &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
-                          $problemData, \@Header, $r, $color);
-    untie(%cache);
-
-#    foreach (keys %$TempCache) {
-#        last if ($c->aborted());
-#        if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
-#	    $cache{$_}=$TempCache->{$_};
-#            untie(%cache);
-#        }
-#    }
+    if(!defined($cache{'StatisticsCached'})) {
+        untie(%cache);
+        &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
+                                                                  'true',
+                                                                  $cacheDB,
+                                                                  'true', 
+                                                                  'true',
+                                                                  $courseID,
+                                                                  $r, $c);
+        if($c->aborted()) { return; }
+
+        unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+            $r->print('Unable to tie database.');
+            return;
+        }
+        my ($problemData) = &ExtractStudentData(\%cache, $students);
+        &CalculateStatistics($problemData);
+        untie(%cache);
+
+        unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
+            $r->print('Unable to tie database.');
+            return;
+        }
+        foreach(keys(%$problemData)) {
+            $cache{$_} = $problemData->{$_};
+        }
+        $cache{'StatisticsCached'} = 'true';
+        untie(%cache);
 
-#    if($c->aborted()) { return; }
-#    untie(%cache);
+        unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+            $r->print('Unable to tie database.');
+            return;
+        }
+    }
+    my $orderedProblems = &SortProblems(\%cache, 
+                                        $cache{'ProblemStatisticsSort'},
+                                        $cache{'ProblemStatisticsAscend'});
+    &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, $orderedProblems, 
+                          \@Header, $r, $color);
+    untie(%cache);
 
     return;
 }
@@ -141,7 +151,7 @@
 }
 
 sub BuildStatisticsTable {
-    my ($cache,$displayFormat,$data,$headings,$r,$color)=@_;
+    my ($cache,$displayFormat,$orderedProblems,$headings,$r,$color)=@_;
 
 #6666666
 #    my $file="/home/httpd/perl/tmp/183d.txt";
@@ -157,9 +167,7 @@
 ##777777
 ##    $Str .= &Classify($discriminantFactor, $students);
 
-    my %TempCache;
-    my $problems = $data->{'problemList'};
-    if($displayFormat ne 'Display CSV Format') {
+     if($displayFormat ne 'Display CSV Format') {
         $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
         $r->print('<table border="0" cellpadding="3">'."\n");
         $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
@@ -168,29 +176,33 @@
     }
 
     my $count = 1;
-    foreach(@$problems) {
+    foreach(@$orderedProblems) {
         my ($sequence,$problem,$part)=split(':', $_);
-#        my $problemRef = '<a href="'.$cache->{$problem.':source'}.
-#                '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
+#        if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
+#           $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
+#            next;
+#        }
+
 
-        my $ref = $cache->{$problem.':title'};
+        my $ref = '<a href="'.$cache->{$problem.':source'}.
+                  '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
+#        my $ref = $cache->{$problem.':title'};
         my $title = $cache->{$problem.':title'};
         my $source = 'source';
         my $tableData = join('&', $ref, $title, $source,
-                         $data->{$_.':studentCount'},
-                         $data->{$_.':totalTries'},
-                         $data->{$_.':maxTries'},
-                         sprintf("%.2f", $data->{$_.':mean'}),
-                         $data->{$_.':correct'},
-                         $data->{$_.':correctByOverride'},
-                         sprintf("%.1f", $data->{$_.':percentWrong'}),
-                         sprintf("%.2f", $data->{$_.':degreeOfDifficulty'}),
-                         sprintf("%.1f", $data->{$_.':standardDeviation'}),
-                         sprintf("%.1f", $data->{$_.':skewness'}),
-                         sprintf("%.2f", $data->{$_.':discriminationFactor1'}),
-                         sprintf("%.2f", $data->{$_.':discriminationFactor2'}),
-                         0); # 0 is for discussion, need to figure out
-#        $TempCache{'CacheTable:'.$_}=$join;
+                       $cache->{$_.':studentCount'},
+                       $cache->{$_.':totalTries'},
+                       $cache->{$_.':maxTries'},
+                       sprintf("%.2f", $cache->{$_.':mean'}),
+                       $cache->{$_.':correct'},
+                       $cache->{$_.':correctByOverride'},
+                       sprintf("%.1f", $cache->{$_.':percentWrong'}),
+                       sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}),
+                       sprintf("%.1f", $cache->{$_.':standardDeviation'}),
+                       sprintf("%.1f", $cache->{$_.':skewness'}),
+                       sprintf("%.2f", $cache->{$_.':discriminationFactor1'}),
+                       sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),
+                       0); # 0 is for discussion, need to figure out
 
 #6666666
 #	    $r->print('<br>'.$out.'&'.$DoD);
@@ -205,10 +217,8 @@
 #        }
 #-------------------------------- Row of statistical table
         &TableRow($displayFormat,$tableData,$count,$r,$color);
-#        $GraphDat->{'GraphGif:'.($count-1)}=$DoD.':'.$Wrng;
         $count++;
     }
-#    $TempCache{'ProblemCount'}=$count;
     if($cache->{'DisplayFormat'} ne 'Display CSV Format') {
         $r->print('</table>'."\n");
     }
@@ -216,78 +226,8 @@
 #6666666
 #    close( OUT );
 #666666
-    return \%TempCache;
-}
-
-=pod
-sub CacheStatisticsTable {
-    my ($state,$cache,$headings,$r,$color)=@_;
-    my @list = (); 
-    my %TempCache;
-    my %myHeader = reverse( %$headings );
-    my $pos = $myHeader{$state};
-    if ($pos > 0) {$pos++;}
-    my $p_count = $cache->{'ProblemCount'};
-
-    for ( my $k=0; $k<$p_count;$k++) {
-	my $key=$cache->{'CacheTable:'.$k};
-	my @Temp=split(/\&/,$key);
-	$list[$k]=$Temp[$pos].'+'.$key;
-    }
-    
-    if ($pos>0) {
-        @list = sort OrderedSort (@list);
-    } else {
-        @list = sort (@list);
-    }
-    my $cIdx=0;
-
-    if ( $pos == 0 ) {
-	foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
-	    if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
-	       $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
-		next;
-	    }
-	    if ($cIdx==$p_count) {
-		return \%TempCache;
-	    }
-	    $r->print(&CreateProblemStatisticsTableHeading(
-                                             $cache->{'DisplayFormat'}, 
-                                             $cache->{$sequence.':source'},
-                                             $cache->{$sequence.':title'}, 
-                                             $headings,$r));
-
-	    my ($tar)=split(/\&/,$list[$cIdx]);
-	    $tar=~s/\+//eg;
-	    my ($SqOrd)=split(/\@/,$tar);
-	    $sequence+=100;
-	    while ($SqOrd==$sequence && $cIdx<$p_count) {
-		my($Pre, $Post) = split(/\+/,$list[$cIdx]); 
-		&TableRow($cache,$Post,$cIdx,$cIdx,$r,$color,\%TempCache);
-		$cIdx++;
-		my ($tar)=split(/\&/,$list[$cIdx]);
-		$tar=~s/\+//eg;
-		($SqOrd)=split(/\@/,$tar);
-	    }
-	    &CloseTable($cache,$r);
-	}
-    }
-    else {
-        $r->print(&CreateProblemStatisticsTableHeading(
-                                             $cache->{'DisplayFormat'}, 
-                                             'Sorted by: ',
-					     $headings->{$pos-1},
-                                             $headings,$r));
-	for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
-	    my($Pre, $Post) = split(/\+/,$list[$nIndex]);
-	    &TableRow($cache,$Post,$nIndex,$nIndex,$r,$color,\%TempCache);
-	} 
-	&CloseTable($cache,$r);
-    }
-
-    return \%TempCache;
+    return;
 }
-=cut
 
 sub TableRow {
     my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
@@ -454,11 +394,6 @@
     my @problemList=();
     my %problemData;
     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
-        if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
-           $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
-            next;
-        }
-
         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
             foreach my $part (split(/\:/,$cache->{$sequence.':'.
                                                   $problemID.
@@ -518,7 +453,7 @@
         }
     }
 
-    $problemData{'problemList'} = \@problemList;
+    $problemData{'problemList'} = join(':::', @problemList);
 #                $Discussed=0;
 #                if($Discuss->{"$name:$problem"}) {
 #		    $TotDiscuss++;
@@ -531,8 +466,9 @@
 sub SortProblems {
     my ($problemData,$sortBy,$ascend)=@_;
 
+    my @problems = split(':::', $problemData->{'problemList'});
     if($sortBy eq "Homework Sets Order") {
-        return;
+        return \@problems;
     }
 
     my $data;
@@ -550,26 +486,23 @@
     elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }
     elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }
     elsif($sortBy eq "Disc.")   { $data = ''; }
-    else                        { return; }
+    else                        { return \@problems; }
 
-    my $problems = $problemData->{'problemList'};
     my @orderedProblems = 
         sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
-             @$problems;
+             @problems;
     if($ascend eq 'Descending') {
         @orderedProblems = reverse(@orderedProblems);
     }
 
-    $problemData->{'problemList'} = \@orderedProblems;
-
-    return;
+    return \@orderedProblems;
 }
 
 sub CalculateStatistics {
     my ($data)=@_;
 
-    my $problems = $data->{'problemList'};
-    foreach(@$problems) {
+    my @problems = split(':::', $data->{'problemList'});
+    foreach(@problems) {
         # Mean
         $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ? 
             ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;

--stredwic1029247046--