--- loncom/interface/statistics/lonpercentage.pm 2002/08/30 15:35:08 1.1 +++ loncom/interface/statistics/lonpercentage.pm 2003/01/14 22:10:08 1.8 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonpercentage.pm,v 1.1 2002/08/30 15:35:08 stredwic Exp $ +# $Id: lonpercentage.pm,v 1.8 2003/01/14 22:10:08 minaeibi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,7 +34,6 @@ use Apache::lonhtmlcommon; use Apache::loncoursedata; use GDBM_File; -#my $jr; sub BuildPercentageGraph { my ($cacheDB, $students, $courseID, $c, $r)=@_; @@ -60,8 +59,8 @@ sub BuildPercentageGraph { return; } - my ($Ptr, $percentage) = &GraphData(\%cache, $students); - $r->print($Ptr.'

'); + my ($Ptr, $percentage) = &GraphData(\%cache, $students,$r); + $r->print($Ptr.'
'); $r->print(&TableData(\%cache, $percentage)); @@ -186,7 +185,7 @@ sub InitializeSelectedStudents { } sub GraphData { - my ($cache,$students)=@_; + my ($cache,$students,$r)=@_; my $sequenceSelected = $cache->{'StatisticsMaps'}; my $problemSelected = $cache->{'StatisticsProblemSelect'}; @@ -194,10 +193,11 @@ sub GraphData { my %percentages; my $Ptr = ''; + my $totalProblems = 0; foreach(@$students) { my $totalCorrect = 0; - my $totalProblems = 0; + $totalProblems = 0; foreach my $sequence (split(':',$cache->{'orderedSequences'})) { next if($cache->{$sequence.':title'} ne $sequenceSelected && @@ -222,9 +222,13 @@ sub GraphData { } } } - - my $percent = sprintf("%d", ($totalProblems) ? - (($totalCorrect/$totalProblems)*100) : 0); + my $percent; + if ( $totalProblems >= 100 ) { + $percent = sprintf("%d", ($totalProblems) ? + (($totalCorrect/$totalProblems)*100) : 0); + } else { + $percent = sprintf("%d", ($totalProblems) ? $totalCorrect : 0); + } if(defined($percentages{$percent})) { $percentages{$percent} .= ':::'.$_; } else { @@ -235,40 +239,85 @@ sub GraphData { my @percent = (); my @percentCount = (); my $max = 0; - foreach my $key (sort(keys(%percentages))) { + my $pno = 0; + + foreach my $key (sort NumericSort keys(%percentages)) { push(@percent, $key); - my $count = scalar(split(':::', $percentages{$key})); + my @temp = split(':::', $percentages{$key}); + my $count = scalar(@temp); if($count > $max) { $max = $count; } push(@percentCount, $count); + $pno++; } - my @GData = ('', 'Percentage', 'Number_of_Students', - $max, scalar(@percent), - join(',',@percent), join(',', @percentCount)); + my $cId=0; + my @data1=(); + my @data2=(); + for (my $nIdx=0; $nIdx<$pno; $nIdx++ ) { + $data1[$cId]=$percent[$nIdx]; + $data2[$cId]=$percentCount[$nIdx]; + my $cr=$percent[$nIdx+1]; + while ($data1[$cId]<$cr) { + $cId++; + $data1[$cId]=$cId; + $data2[$cId]=0; + } + } + + my $xlabel; + my $Freq; + if ($totalProblems >= 100 ) { + $xlabel = 'Percentage_of_Problems_Correct'; + $Freq=101; + } else { + $xlabel = 'Number_of_Problems_Correct'; + $Freq = $cId; + } + +# $r->print('
Freq='.$Freq); +# $r->print('
max='.$max); +# $r->print('
percentcount='.join(',', @percentCount)); +# $r->print('
percent='.join(',', @percent)); +# $r->print('
percentcount='.join(',', @data1)); +# $r->print('
percent='.join(',', @data2)); + + my @GData = ("Percentage",$xlabel, + 'Number_of_Students',$max,$Freq, + join(',',@data1), join(',', @data2)); $Ptr .= ''."\n"; - $Ptr .= ' $b; +} + sub TableData { my($cache,$percentage)=@_; my $Ptr; - $Ptr .= '
'."\n"; + $Ptr .= '
'."\n"; $Ptr .= ''."\n"; $Ptr .= ''."\n"; - $Ptr .= ''; + $Ptr .= ''. + ''. + ''; $Ptr .= ''."\n"; my $alternate=0; - foreach (sort(keys(%$percentage))) { + foreach (sort NumericSort keys(%$percentage)) { + + my @temp = split(':::', $percentage->{$_}); + my $count = scalar(@temp); + if($alternate) { $Ptr .= ''; } else { @@ -276,7 +325,8 @@ sub TableData { } $alternate = ($alternate + 1) % 2; - $Ptr .= ''; + $Ptr .= '
Percent CorrectStudents% CorrectFrequencyStudents
'.$_.''; + $Ptr .= ''.$_.''.$count.''; foreach my $name (sort(split(':::', $percentage->{$_}))) { $Ptr .= '