# The LearningOnline Network with CAPA
# (Publication Handler
#
# $Id: lonproblemstatistics.pm,v 1.24 2002/08/14 13:13:37 stredwic Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# (Navigate problems for statistical reports
# YEAR=2001
# 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
#
###
package Apache::lonproblemstatistics;
use strict;
use Apache::lonnet();
use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use GDBM_File;
my $jr;
sub BuildProblemStatisticsPage {
my ($cacheDB, $students, $courseID, $c, $r)=@_;
my %cache;
$jr = $r;
unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
$r->print('Unable to tie database.');
return;
}
my $Ptr = '';
$Ptr .= '
';
$Ptr .= 'Select Map | '."\n";
$Ptr .= '';
$Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
'Statistics');
$Ptr .= ' |
'."\n";
$Ptr .= 'Sorting Type: | '."\n";
$Ptr .= ''."\n";
$Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
$cache{'ProblemStatisticsAscend'},
'ProblemStatistics',
'Statistics');
$Ptr .= ' |
'."\n";
$Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
$cache{'DisplayLegend'});
$Ptr .= '
';
if($cache{'DisplayLegend'} eq 'Show Legend') {
$Ptr .= &ProblemStatisticsLegend();
}
$r->print($Ptr);
$r->rflush();
my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
"Mean","#YES","#yes","%Wrng","DoDiff",
"S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");
my $color=&setbgcolor(0);
# my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
# my ($upper, $lower) = &Discriminant(\%discriminant,$r);
if(!defined($cache{'StatisticsCached'})) {
if(defined($cache{'StatisticsCached'})) {
untie(%cache);
unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
$r->print('Unable to tie database.');
return;
}
my @statkeys = split(':::', $cache{'StatisticsKeys'});
delete $cache{'StatisticsKeys'};
delete $cache{'StatisticsCached'};
foreach(@statkeys) {
delete $cache{$_};
}
}
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, \%cache);
untie(%cache);
unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
$r->print('Unable to tie database.');
return;
}
foreach(keys(%$problemData)) {
$cache{$_} = $problemData->{$_};
}
$cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
$cache{'StatisticsCached'} = 'true';
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;
}
sub BuildGraphicChart {
my ($graph,$cacheDB,$courseDescription,$r)=@_;
my %cache;
my $max = 0;
unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
return 'Unable to tie database.';
}
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);
my $sendValues = join(',', @values);
# my $sendCount = $#values;
my $sendCount = scalar(@values);
my $title = '';
if($graph eq 'DoDiffGraph') {
$title = 'Degree-of-Difficulty';
} else {
$title = 'Wrong-Percentage';
}
my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount,
$sendValues);
$r->print(''."\n");
$r->print('');
$r->print('