--- loncom/interface/statistics/lonpercentage.pm 2002/08/30 15:35:08 1.1
+++ loncom/interface/statistics/lonpercentage.pm 2008/12/12 10:01:30 1.11
@@ -1,7 +1,6 @@
# 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.11 2008/12/12 10:01:30 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,8 +32,10 @@ use strict;
use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use GDBM_File;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
-#my $jr;
sub BuildPercentageGraph {
my ($cacheDB, $students, $courseID, $c, $r)=@_;
@@ -60,8 +61,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));
@@ -111,9 +112,7 @@ sub CreateInterface {
$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 .= '';
@@ -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 .= 'Percent Correct | Students | ';
+ $Ptr .= '% Correct | '.
+ 'Frequency | '.
+ 'Students | ';
$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,15 +325,16 @@ sub TableData {
}
$alternate = ($alternate + 1) % 2;
- $Ptr .= ''.$_.' | ';
+ $Ptr .= ' | '.$_.' | ';
+ $Ptr .= ''.$count.' | ';
foreach my $name (sort(split(':::', $percentage->{$_}))) {
$Ptr .= '';
+ $Ptr .= &escape($cache->{$name.':fullname'}).'">';
$Ptr .= $cache->{$name.':fullname'};
- $Ptr .= ',  ';
+ $Ptr .= ', ';
}
$Ptr .= ' | '."\n";
|
|