--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 20:42:49 1.27 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 21:51:51 1.28 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonproblemstatistics.pm,v 1.27 2002/08/14 20:42:49 stredwic Exp $ +# $Id: lonproblemstatistics.pm,v 1.28 2002/08/14 21:51:51 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,7 +52,7 @@ sub InitializeProblemStatistics { $jr = $r; unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - $r->print('Unable to tie database.'); + $r->print('Unable to tie database1.'); return ('ERROR', undef); } @@ -80,26 +80,32 @@ sub InitializeProblemStatistics { } } + my $isNotCached = 0; 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)) { - $r->print('Unable to tie database.'); - return ('ERROR', undef); - } - my @statkeys = split(':::', $cache{'StatisticsKeys'}); - delete $cache{'StatisticsKeys'}; - delete $cache{'StatisticsCached'}; - foreach(@statkeys) { - delete $cache{$_}; - } + $isNotCached = 1; + } + + untie(%cache); + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) { + $r->print('Unable to tie database.2'); + return ('ERROR', undef); + } + if($isNotCached && defined($cache{'StatisticsCached'})) { + my @statkeys = split(':::', $cache{'StatisticsKeys'}); + delete $cache{'StatisticsKeys'}; + delete $cache{'StatisticsCached'}; + foreach(@statkeys) { + delete $cache{$_}; } - untie(%cache); + } + + untie(%cache); + if($isNotCached) { &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students, 'true', $cacheDB, @@ -107,20 +113,25 @@ sub InitializeProblemStatistics { 'true', $courseID, $r, $c); - if($c->aborted()) { return ('ERROR', undef); } + } + if($c->aborted()) { return ('ERROR', undef); } - unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - $r->print('Unable to tie database.'); - return ('ERROR', undef); - } - my ($problemData) = &ExtractStudentData(\%cache, $students); + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { + $r->print('Unable to tie database.3'); + return ('ERROR', undef); + } + my $problemData; + if($isNotCached) { + ($problemData) = &ExtractStudentData(\%cache, $students); &CalculateStatistics($problemData, \%cache); - untie(%cache); + } + untie(%cache); - unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) { - $r->print('Unable to tie database.'); - return ('ERROR', undef); - } + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) { + $r->print('Unable to tie database.4'); + return ('ERROR', undef); + } + if($isNotCached) { foreach(keys(%$problemData)) { $cache{$_} = $problemData->{$_}; } @@ -128,18 +139,20 @@ sub InitializeProblemStatistics { $cache{'StatisticsCached'} = 'true'; $cache{'StatisticsLastStatus'} = $cache{'Status'}; $cache{'StatisticsWhichStudents'} = $whichStudents; - untie(%cache); + } + untie(%cache); - unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - $r->print('Unable to tie database.'); - return ('ERROR', undef); - } + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { + $r->print('Unable to tie database.5'); + return ('ERROR', undef); } my $orderedProblems = &SortProblems(\%cache, $cache{'ProblemStatisticsSort'}, $cache{'SortProblems'}, $cache{'ProblemStatisticsAscend'}); + untie(%cache); + return ('OK', $orderedProblems); } @@ -153,7 +166,7 @@ sub BuildProblemStatisticsPage { my %cache; unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - $r->print('Unable to tie database.'); + $r->print('Unable to tie database.6'); return; } my $Ptr = ''; @@ -197,7 +210,7 @@ sub BuildProblemStatisticsPage { } unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - $r->print('Unable to tie database.'); + $r->print('Unable to tie database.6'); return; } &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, @@ -220,7 +233,7 @@ sub BuildGraphicChart { } unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - return 'Unable to tie database.'; + return 'Unable to tie database.7'; } my @problems = split(':::', $cache{'problemList'});