--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 15:05:13 1.23 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 13:13:37 1.24 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonproblemstatistics.pm,v 1.23 2002/08/13 15:05:13 stredwic Exp $ +# $Id: lonproblemstatistics.pm,v 1.24 2002/08/14 13:13:37 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -87,6 +87,19 @@ sub BuildProblemStatisticsPage { # my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID); # my ($upper, $lower) = &Discriminant(\%discriminant,$r); if(!defined($cache{'StatisticsCached'})) { + if(defined($cache{'StatisticsCached'})) { + untie(%cache); + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) { + $r->print('Unable to tie database.'); + return; + } + my @statkeys = split(':::', $cache{'StatisticsKeys'}); + delete $cache{'StatisticsKeys'}; + delete $cache{'StatisticsCached'}; + foreach(@statkeys) { + delete $cache{$_}; + } + } untie(%cache); &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students, 'true', @@ -102,7 +115,7 @@ sub BuildProblemStatisticsPage { return; } my ($problemData) = &ExtractStudentData(\%cache, $students); - &CalculateStatistics($problemData); + &CalculateStatistics($problemData, \%cache); untie(%cache); unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) { @@ -112,6 +125,7 @@ sub BuildProblemStatisticsPage { foreach(keys(%$problemData)) { $cache{$_} = $problemData->{$_}; } + $cache{'StatisticsKeys'} = join(':::', keys(%$problemData)); $cache{'StatisticsCached'} = 'true'; untie(%cache); @@ -130,6 +144,50 @@ sub BuildProblemStatisticsPage { return; } +sub BuildGraphicChart { + my ($graph,$cacheDB,$courseDescription,$r)=@_; + my %cache; + my $max = 0; + + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { + return '
Unable to tie database.'; + } + + my @problems = split(':::', $cache{'problemList'}); + my @values = (); + foreach (@problems) { + my $data = 0; + if($graph eq 'DoDiffGraph') { + $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}), + } else { + $data = sprintf("%.1f", $cache{$_.':percentWrong'}), + } + if($max < $data) { + $max = $data; + } + push(@values, $data); + } + untie(%cache); + + my $sendValues = join(',', @values); +# my $sendCount = $#values; + my $sendCount = scalar(@values); + + my $title = ''; + if($graph eq 'DoDiffGraph') { + $title = 'Degree-of-Difficulty'; + } else { + $title = 'Wrong-Percentage'; + } + my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount, + $sendValues); + + $r->print(''."\n"); + $r->print(''); + $r->print(''."\n"); - $r->print(''); - $r->print('