--- loncom/interface/statistics/lonproblemstatistics.pm 2002/07/27 20:48:36 1.4
+++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 17:45:19 1.26
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# (Publication Handler
#
-# $Id: lonproblemstatistics.pm,v 1.4 2002/07/27 20:48:36 minaeibi Exp $
+# $Id: lonproblemstatistics.pm,v 1.26 2002/08/14 17:45:19 stredwic Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,7 +31,7 @@
# 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 Behrouz Minaei
+# 5/12,5/14,5/15,5/19,5/26,7/16,7/25,7/29,8/5 Behrouz Minaei
#
###
@@ -43,315 +43,245 @@ use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use GDBM_File;
+my $jr;
-sub BuildProblemStatisticsPage {
- my ($cacheDB, $students, $courseID, $c, $r,%color)=@_;
+sub InitializeProblemStatistics {
+ my ($cacheDB, $students, $courseID, $c, $r)=@_;
my %cache;
- #my %DoDiff;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
- return '
Unable to tie database.';
- }
-
- my $Ptr = '';
- $Ptr .= '';
- $Ptr .= 'Select Map | '."\n";
- $Ptr .= '';
- $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics');
- $Ptr .= ' |
'."\n";
- $Ptr .= &AscendOrderOptions($cache{'Ascend'});
- $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'});
- $Ptr .= '
';
- $Ptr .= &ProblemStatisticsLegend();
+ $jr = $r;
- untie(%cache);
- foreach (@$students) {
- my $courseData =
- &Apache::loncoursedata::DownloadCourseInformation($_, $courseID);
- last if ($c->aborted());
- if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
- &Apache::loncoursedata::ProcessStudentData(\%cache,
- $courseData, $_);
- untie(%cache);
+ unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+ $r->print('Unable to tie database.');
+ return ('ERROR', undef);
+ }
+
+ # Remove students who don't have the proper section.
+ my @sectionsSelected = split(':',$cache{'sectionsSelected'});
+ for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
+ $studentIndex--) {
+ my $value = $cache{$students->[$studentIndex].':section'};
+ my $found = 0;
+ foreach (@sectionsSelected) {
+ if($_ eq 'none') {
+ if($value eq '' || !defined($value) || $value eq ' ') {
+ $found = 1;
+ last;
+ }
+ } else {
+ if($value eq $_) {
+ $found = 1;
+ last;
+ }
+ }
+ }
+ if($found == 0) {
+ splice(@$students, $studentIndex, 1);
}
}
- if($c->aborted()) { return $Ptr; }
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
- return 'Unable to tie database.';
+# my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
+ my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
+ $cache{'StatisticsLastStatus'} : 'Nothing';
+ my $whichStudents = join(':::',sort(@$students));
+ if(!defined($cache{'StatisticsCached'}) ||
+ $lastStatus ne $cache{'Status'} ||
+ $whichStudents ne $cache{'StatisticsWhichStudents'}) {
+ if(defined($cache{'StatisticsCached'})) {
+ untie(%cache);
+ unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
+ $r->print('Unable to tie database.');
+ return ('ERROR', undef);
+ }
+ 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 ('ERROR', undef); }
+
+ unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+ $r->print('Unable to tie database.');
+ return ('ERROR', undef);
+ }
+ 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 ('ERROR', undef);
+ }
+ foreach(keys(%$problemData)) {
+ $cache{$_} = $problemData->{$_};
+ }
+ $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
+ $cache{'StatisticsCached'} = 'true';
+ $cache{'StatisticsLastStatus'} = $cache{'Status'};
+ $cache{'StatisticsWhichStudents'} = $whichStudents;
+ untie(%cache);
+
+ unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+ $r->print('Unable to tie database.');
+ return ('ERROR', undef);
+ }
}
- my $discriminantFactor;
- my @list=();
- my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
- my $index=0;
- foreach (@$students) {
- $index++;
- #&Apache::lonstatistics::Update_PrgWin(++$index,$r);
- $discriminantFactor = &ExtractStudentData(\%cache, $_, \@list,
- \%Discuss, $r);
- }
- #&Apache::lonstatistics::Close_PrgWin($r);
-
- my ($upper, $lower) = &Discriminant($discriminantFactor);
- my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
- 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
- 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd", 13, "Disc.");
-
- my %GraphDat= &BuildStatisticsTable(\%cache, $discriminantFactor, \@list,
- \%Header, $students, $r, \%color);
- untie(%cache);
-
- return $Ptr;
+ my $orderedProblems = &SortProblems(\%cache,
+ $cache{'ProblemStatisticsSort'},
+ $cache{'SortProblems'},
+ $cache{'ProblemStatisticsAscend'});
+ return ('OK', $orderedProblems);
}
+sub BuildProblemStatisticsPage {
+ my ($cacheDB, $students, $courseID, $c, $r)=@_;
-#---- Problem Statistics Web Page ---------------------------------------
-
-
-sub NumericSort {
- $a <=> $b;
-}
-
+ 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 %cache;
-sub CreateProblemStatisticsTableHeading {
- my ($displayFormat,$sequenceSource,$sequenceTitle,$headings,$r)=@_;
- if($displayFormat eq 'Display CSV Format') {
- $r->print('
"'.$sequenceTitle.'","');
- $r->print($sequenceSource.'"');
- return;
- }
-
- $r->print('
'.$sequenceTitle.'');
-
- my $Result = "\n".''."\n");
+ 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 .= 'Select Sections';
+ $Ptr .= ' | '."\n";
+ $Ptr .= ''."\n";
+ my @sections = split(':',$cache{'sectionList'});
+ my @sectionsSelected = split(':',$cache{'sectionsSelected'});
+ $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
+ \@sectionsSelected,
+ 'Statistics');
+ $Ptr .= ' |
'."\n";
+ $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
+ $cache{'DisplayLegend'},
+ $cache{'SortProblems'});
+ $Ptr .= '
';
+ if($cache{'DisplayLegend'} eq 'Show Legend') {
+ $Ptr .= &ProblemStatisticsLegend();
+ }
+ $r->print($Ptr);
$r->rflush();
-}
-
-
-
-# ------ Dump the Student's DB file and handling the data for statistics table
-sub ExtractStudentData {
- my ($cache,$name,$list,$Discuss,$r)=@_;
- my %discriminantFactor;
-
- my $totalTries = 0;
- my $totalAwarded = 0;
- my $tempProblemOrder=0;
- my $spent=0;
- my $spent_yes=0;
- my $TotDiscuss=0;
- my $TotalOpend = 0;
- my $ProbSolved = 0;
- my $ProbTot = 0;
- my $TotFirst = 0;
- my $TimeTot = 0;
- my $Discussed=0;
-
-$Apache::lonxml::debug=1;
-#&Apache::lonhomework::showhash(%$cache);
-$Apache::lonxml::debug=0;
+ untie(%cache);
- foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
-# if($cache->{'ProblemStatisticsMap'} ne 'All Maps' &&
-# $cache->{'ProblemStatisticsMap'} ne $cache->{$sequence.':title'}) {
-# $r->print("
$name --- $sequence");
-# $r->print("
".$cache->{$sequence.':title'});
-# next;
-# }
+ my ($result, $orderedProblems) =
+ &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
+ if($result ne 'OK') {
+ return;
+ }
- my $Dis = '';
- foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
- my $problem = $cache->{$problemID.':problem'};
- $r->print("
$problemID === $problem");
- my $LatestVersion = $cache->{$name.':version:'.$problem};
- # Output dashes for all the parts of this problem if there
- # is no version information about the current problem.
- #if(!$LatestVersion) {
- # foreach my $part (split(/\:/,$cache->{$sequence.':'.
- # $problemID.
- # ':parts'})) {
- # $codes .= "-,";
- # $attempts .= "0,";
- # }
- # next;
- #}
-
- my %partData=undef;
- # Initialize part data, display skips correctly
- # Skip refers to when a student made no submissions on that
- # part/problem.
- foreach my $part (split(/\:/,$cache->{$sequence.':'.
- $problemID.
- ':parts'})) {
- $partData{$part.':tries'}=0;
- $partData{$part.':code'}='-';
- }
+ unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+ $r->print('Unable to tie database.');
+ return;
+ }
+ &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
+ $cache{'SortProblems'}, $orderedProblems,
+ \@Header, $r, $color);
+ untie(%cache);
- # Looping through all the versions of each part, starting with the
- # oldest version. Basically, it gets the most recent
- # set of grade data for each part.
- for(my $Version=1; $Version<=$LatestVersion; $Version++) {
- foreach my $part (split(/\:/,$cache->{$sequence.':'.
- $problemID.
- ':parts'})) {
-
- if(!defined($cache->{$name.":$Version:$problem".
- ":resource.$part.solved"})) {
- # No grade for this submission, so skip
- next;
- }
+ return;
+}
- my $tries=0;
- my $time=0;
- my $awarded=0;
- $Discussed=0;
- my $code='U';
-
- $awarded = $cache->{$name.
- "$Version:$problem:resource.".
- "$part.awarded"};
- $partData{$part.':awarded'} = ($awarded) ? $awarded : 0;
- $totalAwarded += $awarded;
+sub BuildGraphicChart {
+ my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
+ my %cache;
+ my $max = 0;
- $tries = $cache->{$name.":$Version:$problem".
- ":resource.$part.tries"};
- $partData{$part.':tries'} = ($tries) ? $tries : 0;
- $partData{$part.':wrong'} = $partData{$part.':tries'};
- $totalTries += $tries;
+ my ($result, undef) =
+ &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
+ if($result ne 'OK') {
+ return;
+ }
- my $val = $cache->{$name.":$Version:$problem".
- ":resource.$part.solved"};
- if ($val eq 'correct_by_student') {$code = 'C';}
- elsif ($val eq 'correct_by_override') {$code = 'O';}
- elsif ($val eq 'incorrect_attempted') {$code = 'I';}
- elsif ($val eq 'incorrect_by_override'){$code = 'I';}
- elsif ($val eq 'excused') {$code = 'x';}
- $partData{$part.':code'}=$code;
- if($partData{$part.':wrong'} ne 0 &&
- ($code eq 'C' || $code eq 'O')) {
- $partData{$part.':wrong'}--;
- }
- }
- }
+ 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);
- # Loop through all the parts for the current problem in the
- # correct order and prepare the output
- foreach (split(/\:/,$cache->{$sequence.':'.$problemID.
- ':parts'})) {
- #$r->print("
".$cache->{$sequence.':title'});
-
- my $Yes = 0;
- if($partData{$_.':code'} eq 'C' ||
- $partData{$_.':code'} eq 'O') {
- $Yes=1;
- }
- my $ptr = $tempProblemOrder.'&'.$problemID;
+ my $sendValues = join(',', @values);
+ my $sendCount = scalar(@values);
- if($_ > 1) {
- $ptr .= "*(part $_)";
- $Dis .= '&';
- }
+ my $title = '';
+ if($graph eq 'DoDiffGraph') {
+ $title = 'Degree-of-Difficulty';
+ } else {
+ $title = 'Wrong-Percentage';
+ }
+ my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount,
+ $sendValues);
- my ($pr_no,$dod)=split('&',$ptr);
-# my $DoDiff=$DoDiff->{$dod};
-# $r->print('
'.$name.'---'.$ptr.'==='.$DoDiff);
-
- my $Fac = ($partData{$_.':Tries'}) ?
- ($partData{$_.':awarded'}/$partData{$_.':tries'}) : 0;
- my $DisF;
- if($Fac > 0 && $Fac < 1) {
- $DisF = sprintf( "%.4f", $Fac );
- } else {
- $DisF = $Fac;
- }
+ $r->print(''."\n");
+ $r->print('');
+ $r->print('