--- loncom/interface/statistics/lonproblemstatistics.pm 2002/09/22 17:08:32 1.33 +++ 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.33 2002/09/22 17:08:32 minaeibi Exp $ +# $Id: lonproblemstatistics.pm,v 1.34 2002/10/30 18:37:00 minaeibi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -84,7 +84,7 @@ sub InitializeProblemStatistics { 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'}) { $isNotCached = 1; @@ -109,7 +109,7 @@ sub InitializeProblemStatistics { &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students, 'true', $cacheDB, - 'true', + 'true', 'true', $courseID, $r, $c); @@ -147,7 +147,7 @@ sub InitializeProblemStatistics { return ('ERROR', undef); } - my $orderedProblems = &SortProblems(\%cache, + my $orderedProblems = &SortProblems(\%cache, $cache{'ProblemStatisticsSort'}, $cache{'SortProblems'}, $cache{'ProblemStatisticsAscend'}); @@ -179,7 +179,7 @@ sub BuildProblemStatisticsPage { $Ptr .= 'Sorting Type:'."\n"; $Ptr .= ''."\n"; $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions( - $cache{'ProblemStatisticsAscend'}, + $cache{'ProblemStatisticsAscend'}, 'ProblemStatistics', 'Statistics'); $Ptr .= ''."\n"; @@ -192,7 +192,7 @@ sub BuildProblemStatisticsPage { \@sectionsSelected, 'Statistics'); $Ptr .= ''."\n"; - $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, + $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, $cache{'DisplayLegend'}, $cache{'SortProblems'}); $Ptr .= ''; @@ -213,8 +213,8 @@ sub BuildProblemStatisticsPage { $r->print('Unable to tie database.6'); return; } - &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, - $cache{'SortProblems'}, $orderedProblems, + &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, + $cache{'SortProblems'}, $orderedProblems, \@Header, $r, $color); untie(%cache); @@ -225,20 +225,76 @@ sub BuildGraphicChart { my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_; my %cache; my $max = 0; + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { + return 'Unable to tie database.7'; + } + +# my @problems = split(':::', $cache{'problemList'}); + + my $title = ''; + if($graph eq 'DoDiffGraph') { + $title = 'Degree-of-Difficulty'; + } else { + $title = 'Wrong-Percentage'; + } - my ($result, undef) = + + # 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); + # } + + + my $count = 1; + my $currentSequence = -1; + my $sortProblems = 'Sort Within Sequence'; + + my ($result, $orderedProblems) = &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r); if($result ne 'OK') { return; } - unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { - return 'Unable to tie database.7'; - } - - my @problems = split(':::', $cache{'problemList'}); my @values = (); - foreach (@problems) { + + foreach(@$orderedProblems) { + my ($sequence,$problem,$part)=split(':', $_); + if($cache{'StatisticsMaps'} ne 'All Maps' && + $cache{'StatisticsMaps'} ne $cache{$sequence.':title'}) { + next; + } + + if($currentSequence == -1 || + ($sortProblems eq 'Sort Within Sequence' && + $currentSequence != $sequence)) { + if($currentSequence ne -1) { + #$r->print('
finish a graph
'); + } + if($sortProblems eq 'Sort Within Sequence') { + $r->print(''.$cache{$sequence.':title'}.''); + } + + my $sendValues = join(',', @values); + my $sendCount = scalar(@values); + + my @GData = ($courseDescription, 'Problems', + $title, $max, $sendCount, $sendValues); + $r->print(''."\n"); + $r->print(''); + $r->print('
'."\n"); + $currentSequence = $sequence; + @values = (); + + } my $data = 0; if($graph eq 'DoDiffGraph') { $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}), @@ -249,29 +305,17 @@ sub BuildGraphicChart { $max = $data; } push(@values, $data); - } - untie(%cache); - - my $sendValues = join(',', @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('
'); + + untie(%cache); return; } + #---- Problem Statistics Web Page --------------------------------------- sub CreateProblemStatisticsTableHeading { @@ -287,7 +331,7 @@ sub CreateProblemStatisticsTableHeading $Str .= '&ProblemStatisticsSort='; $Str .= &Apache::lonnet::escape($_).'">'.$_.' '."\n"; } - $Str .= "\n".''."\n"; + $Str .= "\n".''."\n"; return $Str; } @@ -305,8 +349,8 @@ sub BuildStatisticsTable { next; } - if($currentSequence == -1 || - ($sortProblems eq 'Sort Within Sequence' && + if($currentSequence == -1 || + ($sortProblems eq 'Sort Within Sequence' && $currentSequence != $sequence)) { if($displayFormat ne 'Display CSV Format') { if($currentSequence ne -1) { @@ -571,7 +615,7 @@ sub ExtractStudentData { } my $studentTriesJoined = join(':::', @studentTries); - $problemData{$id.':sequenceTitle'} = + $problemData{$id.':sequenceTitle'} = $cache->{$sequence.':title'}; $problemData{$id.':studentCount'} = $studentCount; $problemData{$id.':totalTries'} = $totalTries; @@ -623,7 +667,7 @@ sub SortDivideByTries { my @orderedData = sort { ($data->{$a.':totalTries'}) ? ($data->{$a.$sortOn}/$data->{$a.':totalTries'}):0 <=> - ($data->{$b.':totalTries'}) ? + ($data->{$b.':totalTries'}) ? ($data->{$b.$sortOn}/$data->{$b.':totalTries'}):0 } @$toSort;