--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 12:21:46 1.20 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 13:57:25 1.21 @@ -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 @@ sub BuildProblemStatisticsPage { $jr = $r; unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - return '
Unable to tie database.'; + $r->print('Unable to tie database.'); + return; } my $Ptr = ''; @@ -78,18 +79,6 @@ sub BuildProblemStatisticsPage { $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 'Unable to tie database.'; - } - 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 @@ sub BuildProblemStatisticsPage { # 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 CreateProblemStatisticsTableHeading } 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 @@ sub BuildStatisticsTable { ##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(''."\n");
$r->print(' |