--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 00:37:18 1.19 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/13 15:05:13 1.23 @@ -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.23 2002/08/13 15:05:13 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(' | |
';
$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 +452,7 @@ sub ExtractStudentData {
}
}
- $problemData{'problemList'} = \@problemList;
+ $problemData{'problemList'} = join(':::', @problemList);
# $Discussed=0;
# if($Discuss->{"$name:$problem"}) {
# $TotDiscuss++;
@@ -521,8 +465,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 +485,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 +626,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(' |