--- loncom/interface/statistics/lonproblemstatistics.pm 2002/10/30 18:37:00 1.34 +++ loncom/interface/statistics/lonproblemstatistics.pm 2003/02/25 20:47:47 1.40 @@ -1,7 +1,6 @@ # The LearningOnline Network with CAPA -# (Publication Handler # -# $Id: lonproblemstatistics.pm,v 1.34 2002/10/30 18:37:00 minaeibi Exp $ +# $Id: lonproblemstatistics.pm,v 1.40 2003/02/25 20:47:47 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,12 +29,12 @@ # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei # YEAR=2002 -# 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei -# 5/12,5/14,5/15,5/19,5/26,7/16,7/25,7/29,8/5 Behrouz Minaei +# 1/22,2/1,2/6,2/25,3/2,3/26,4/7,5/6 Behrouz Minaei +# 5/12,5/26,7/16,7/29,8/5,10/31 Behrouz Minaei # ### -package Apache::lonproblemstatistics; +package Apache::lonproblemstatistics; use strict; use Apache::lonnet(); @@ -43,14 +42,11 @@ use Apache::lonhtmlcommon; use Apache::loncoursedata; use GDBM_File; -my $jr; sub InitializeProblemStatistics { my ($cacheDB, $students, $courseID, $c, $r)=@_; my %cache; - $jr = $r; - unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { $r->print('Unable to tie database1.'); return ('ERROR', undef); @@ -188,9 +184,7 @@ sub BuildProblemStatisticsPage { $Ptr .= ''."\n"; my @sections = split(':',$cache{'sectionList'}); my @sectionsSelected = split(':',$cache{'sectionsSelected'}); - $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections, - \@sectionsSelected, - 'Statistics'); + $Ptr .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); $Ptr .= ''."\n"; $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, $cache{'DisplayLegend'}, @@ -224,12 +218,7 @@ sub BuildProblemStatisticsPage { 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 $max; my $title = ''; if($graph eq 'DoDiffGraph') { @@ -238,22 +227,6 @@ sub BuildGraphicChart { $title = 'Wrong-Percentage'; } - - # 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'; @@ -265,35 +238,30 @@ sub BuildGraphicChart { my @values = (); + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { + return 'Unable to tie database.7'; + } + foreach(@$orderedProblems) { my ($sequence,$problem,$part)=split(':', $_); if($cache{'StatisticsMaps'} ne 'All Maps' && $cache{'StatisticsMaps'} ne $cache{$sequence.':title'}) { - next; + next; } - if($currentSequence == -1 || - ($sortProblems eq 'Sort Within Sequence' && + if( $currentSequence == -1 || + ($sortProblems eq 'Sort Within Sequence' && $currentSequence != $sequence)) { - if($currentSequence ne -1) { - #$r->print('
finish a graph
'); - } + if($currentSequence != -1) { + &DrawGraph(\@values,$courseDescription,$title,$max,$r); + } if($sortProblems eq 'Sort Within Sequence') { - $r->print(''.$cache{$sequence.':title'}.''); + $r->print('
'.$cache{$sequence.':title'}.''."\n"); } - 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 = (); - + $max=0; } my $data = 0; if($graph eq 'DoDiffGraph') { @@ -305,17 +273,40 @@ sub BuildGraphicChart { $max = $data; } push(@values, $data); - } - -#$r->print('
'); - untie(%cache); + &DrawGraph(\@values,$courseDescription,$title,$max,$r); + return; } +sub DrawGraph { + my ($values,$courseDescription,$title,$Max,$r)=@_; + my $sendValues = join(',', @$values); + my $sendCount = scalar(@$values); + $r->print("
The Maximum Value is: $Max"); + if ( $Max > 1 ) { + if ($Max % 10) { + if ( int($Max) < $Max ) { + $Max++; + $Max = int($Max); + } + } + #(10 - $Max % 10); + } else { $Max = 1; } + + my @GData = ('','Problem_number',$title,$Max,$sendCount,$sendValues); + +# $r->print('
'."\n"); + $r->print('
'."\n"); + $r->print(''); +# $r->print('
'."\n"); + $r->print('
'."\n"); +} + #---- Problem Statistics Web Page --------------------------------------- sub CreateProblemStatisticsTableHeading { @@ -664,7 +655,7 @@ sub ExtractStudentData { sub SortDivideByTries { my ($toSort, $data, $sortOn)=@_; - my @orderedData = sort { ($data->{$a.':totalTries'}) ? + my @orderedData = sort { ($data->{$a.':totalTries'}) ? ($data->{$a.$sortOn}/$data->{$a.':totalTries'}):0 <=> ($data->{$b.':totalTries'}) ?