--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 00:37:18 1.19 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 15:01:07 1.22 @@ -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.22 2002/08/13 15:01:07 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(''."\n"); $r->print(&CreateProblemStatisticsTableHeading($headings, $r)); @@ -165,29 +176,33 @@ sub BuildStatisticsTable { } my $count = 1; - foreach(@$problems) { + foreach(@$orderedProblems) { my ($sequence,$problem,$part)=split(':', $_); -# my $problemRef = ''.$cache->{$problem.':title'}.''; +# if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' && +# $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) { +# next; +# } - my $ref = $cache->{$problem.':title'}; + + my $ref = ''.$cache->{$problem.':title'}.''; +# my $ref = $cache->{$problem.':title'}; my $title = $cache->{$problem.':title'}; my $source = 'source'; my $tableData = join('&', $ref, $title, $source, - $data->{$_.':studentCount'}, - $data->{$_.':totalTries'}, - $data->{$_.':maxTries'}, - sprintf("%.2f", $data->{$_.':mean'}), - $data->{$_.':correct'}, - $data->{$_.':correctByOverride'}, - sprintf("%.1f", $data->{$_.':percentWrong'}), - sprintf("%.2f", $data->{$_.':degreeOfDifficulty'}), - sprintf("%.1f", $data->{$_.':standardDeviation'}), - sprintf("%.1f", $data->{$_.':skewness'}), - sprintf("%.2f", $data->{$_.':discriminationFactor1'}), - sprintf("%.2f", $data->{$_.':discriminationFactor2'}), - 0); # 0 is for discussion, need to figure out -# $TempCache{'CacheTable:'.$_}=$join; + $cache->{$_.':studentCount'}, + $cache->{$_.':totalTries'}, + $cache->{$_.':maxTries'}, + sprintf("%.2f", $cache->{$_.':mean'}), + $cache->{$_.':correct'}, + $cache->{$_.':correctByOverride'}, + sprintf("%.1f", $cache->{$_.':percentWrong'}), + sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}), + sprintf("%.1f", $cache->{$_.':standardDeviation'}), + sprintf("%.1f", $cache->{$_.':skewness'}), + sprintf("%.2f", $cache->{$_.':discriminationFactor1'}), + sprintf("%.2f", $cache->{$_.':discriminationFactor2'}), + 0); # 0 is for discussion, need to figure out #6666666 # $r->print('
'.$out.'&'.$DoD); @@ -202,10 +217,8 @@ sub BuildStatisticsTable { # } #-------------------------------- Row of statistical table &TableRow($displayFormat,$tableData,$count,$r,$color); -# $GraphDat->{'GraphGif:'.($count-1)}=$DoD.':'.$Wrng; $count++; } -# $TempCache{'ProblemCount'}=$count; if($cache->{'DisplayFormat'} ne 'Display CSV Format') { $r->print('
'."\n"); } @@ -213,78 +226,8 @@ sub BuildStatisticsTable { #6666666 # close( OUT ); #666666 - return \%TempCache; -} - -=pod -sub CacheStatisticsTable { - my ($state,$cache,$headings,$r,$color)=@_; - my @list = (); - my %TempCache; - my %myHeader = reverse( %$headings ); - my $pos = $myHeader{$state}; - if ($pos > 0) {$pos++;} - my $p_count = $cache->{'ProblemCount'}; - - for ( my $k=0; $k<$p_count;$k++) { - my $key=$cache->{'CacheTable:'.$k}; - my @Temp=split(/\&/,$key); - $list[$k]=$Temp[$pos].'+'.$key; - } - - if ($pos>0) { - @list = sort OrderedSort (@list); - } else { - @list = sort (@list); - } - my $cIdx=0; - - if ( $pos == 0 ) { - foreach my $sequence (split(':', $cache->{'orderedSequences'})) { - if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' && - $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) { - next; - } - if ($cIdx==$p_count) { - return \%TempCache; - } - $r->print(&CreateProblemStatisticsTableHeading( - $cache->{'DisplayFormat'}, - $cache->{$sequence.':source'}, - $cache->{$sequence.':title'}, - $headings,$r)); - - my ($tar)=split(/\&/,$list[$cIdx]); - $tar=~s/\+//eg; - my ($SqOrd)=split(/\@/,$tar); - $sequence+=100; - while ($SqOrd==$sequence && $cIdx<$p_count) { - my($Pre, $Post) = split(/\+/,$list[$cIdx]); - &TableRow($cache,$Post,$cIdx,$cIdx,$r,$color,\%TempCache); - $cIdx++; - my ($tar)=split(/\&/,$list[$cIdx]); - $tar=~s/\+//eg; - ($SqOrd)=split(/\@/,$tar); - } - &CloseTable($cache,$r); - } - } - else { - $r->print(&CreateProblemStatisticsTableHeading( - $cache->{'DisplayFormat'}, - 'Sorted by: ', - $headings->{$pos-1}, - $headings,$r)); - for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) { - my($Pre, $Post) = split(/\+/,$list[$nIndex]); - &TableRow($cache,$Post,$nIndex,$nIndex,$r,$color,\%TempCache); - } - &CloseTable($cache,$r); - } - - return \%TempCache; + return; } -=cut sub TableRow { my ($displayFormat,$Str,$RealIdx,$r,$color)=@_; @@ -356,7 +299,7 @@ sub setbgcolor { } sub ProblemStatisticsButtons { - my ($displayFormat)=@_; + my ($displayFormat, $displayLegend)=@_; my $Ptr = '
'; $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; @@ -684,49 +627,46 @@ sub Discriminant { # ------------------------------------------- Prepare data for Graphical chart sub BuildGraphicChart { - my ($ylab,$r,$cacheDB)=@_; + my ($graph,$cacheDB,$courseDescription,$r)=@_; my %cache; - my $Col; - my $data=''; - my $count = 0; - my $Max = 0; + my $max = 0; unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { return 'Unable to tie database.'; } - my $p_count = $cache{'ProblemCount'}; - - for ( my $k=0; $k<$p_count;$k++) { - my @Temp=split(/\:/,$cache{'GraphGif:'.$k}); - my $inf = $Temp[$Col]; - if ( $Max < $inf ) {$Max = $inf;} - $data .= $inf.','; - $count++; + 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); -# $r->print("
count=$p_count >>data= $data"); - if ( $Max > 1 ) { - $Max += (10 - $Max % 10); - $Max = int($Max); - } else { $Max = 1; } - - my $cid=$ENV{'request.course.id'}; - - if ( $ylab eq 'DoDiff Graph' ) { - $ylab = 'Degree-of-Difficulty'; - $Col = 0; + my $sendValues = join(',', @values); +# my $sendCount = $#values; + my $sendCount = scalar(@values); + + my $title = ''; + if($graph eq 'DoDiffGraph') { + $title = 'Degree-of-Difficulty'; } else { - $ylab = 'Wrong-Percentage'; - $Col = 1; + $title = 'Wrong-Percentage'; } - my $Course = $ENV{'course.'.$cid.'.description'}; - $Course =~ s/\ /"_"/eg; - my $GData=$Course.'&'.'Problems#'.'&'.$ylab.'&'. - $Max.'&'.$count.'&'.$data; + my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount, + $sendValues); - $r->print(''); + $r->print(''."\n"); + $r->print(''); + $r->print('
'."\n"); return; }