--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 17:45:19 1.26 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/10/30 18:37:00 1.34 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonproblemstatistics.pm,v 1.26 2002/08/14 17:45:19 stredwic Exp $ +# $Id: lonproblemstatistics.pm,v 1.34 2002/10/30 18:37:00 minaeibi 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,48 +80,58 @@ sub InitializeProblemStatistics { } } -# my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID); + my $isNotCached = 0; my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ? $cache{'StatisticsLastStatus'} : 'Nothing'; my $whichStudents = join(':::',sort(@$students)); - if(!defined($cache{'StatisticsCached'}) || + 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, - 'true', + 'true', '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); - &CalculateStatistics($problemData, \%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_READER(),0640)) { + $r->print('Unable to tie database.3'); + return ('ERROR', undef); + } + my $problemData; + if($isNotCached) { + ($problemData) = &ExtractStudentData(\%cache, $students); + &CalculateStatistics($problemData, \%cache, $courseID); + } + untie(%cache); + + 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->{$_}; } @@ -129,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, + my $orderedProblems = &SortProblems(\%cache, $cache{'ProblemStatisticsSort'}, $cache{'SortProblems'}, $cache{'ProblemStatisticsAscend'}); + untie(%cache); + return ('OK', $orderedProblems); } @@ -149,27 +161,27 @@ sub BuildProblemStatisticsPage { my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod", "Mean","#YES","#yes","%Wrng","DoDiff", - "S.D.","Skew.","D.F.1st","D.F.2nd","Disc."); + "S.D.","Skew.","D.F.1st","D.F.2nd"); my $color=&setbgcolor(0); 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 = ''; - $Ptr .= '
Select Map | '."\n"; $Ptr .= ''; - $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics', + $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'Statistics', 'Statistics'); $Ptr .= ' |
Sorting Type: | '."\n"; $Ptr .= ''."\n"; $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions( - $cache{'ProblemStatisticsAscend'}, - 'ProblemStatistics', - 'Statistics'); + $cache{'ProblemStatisticsAscend'}, + 'ProblemStatistics', + 'Statistics'); $Ptr .= ' |
Select Sections'; $Ptr .= ' | '."\n"; @@ -180,7 +192,7 @@ sub BuildProblemStatisticsPage { \@sectionsSelected, 'Statistics'); $Ptr .= '