--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 00:37:18 1.19 +++ 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.19 2002/08/13 00:37:18 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 = ''; @@ -69,24 +70,15 @@ sub BuildProblemStatisticsPage { 'ProblemStatistics', 'Statistics'); $Ptr .= ''."\n"; - $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}); + $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, + $cache{'DisplayLegend'}); $Ptr .= ''; - $Ptr .= &ProblemStatisticsLegend(); + if($cache{'DisplayLegend'} eq 'Show Legend') { + $Ptr .= &ProblemStatisticsLegend(); + } $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."); @@ -94,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; } @@ -138,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"; @@ -154,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(' | |
'; $Ptr .= '{'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. @@ -508,7 +453,7 @@ sub ExtractStudentData { } } - $problemData{'problemList'} = \@problemList; + $problemData{'problemList'} = join(':::', @problemList); # $Discussed=0; # if($Discuss->{"$name:$problem"}) { # $TotDiscuss++; @@ -521,8 +466,9 @@ sub ExtractStudentData { sub SortProblems { my ($problemData,$sortBy,$ascend)=@_; + my @problems = split(':::', $problemData->{'problemList'}); if($sortBy eq "Homework Sets Order") { - return; + return \@problems; } my $data; @@ -540,26 +486,23 @@ sub SortProblems { 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; |