--- loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 17:45:19 1.26 +++ loncom/interface/statistics/lonproblemstatistics.pm 2002/08/14 20:42:49 1.27 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonproblemstatistics.pm,v 1.26 2002/08/14 17:45:19 stredwic Exp $ +# $Id: lonproblemstatistics.pm,v 1.27 2002/08/14 20:42:49 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,7 +80,6 @@ sub InitializeProblemStatistics { } } -# my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID); my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ? $cache{'StatisticsLastStatus'} : 'Nothing'; my $whichStudents = join(':::',sort(@$students)); @@ -149,7 +148,7 @@ sub BuildProblemStatisticsPage { my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod", "Mean","#YES","#yes","%Wrng","DoDiff", - "S.D.","Skew.","D.F.1st","D.F.2nd","Disc."); + "S.D.","Skew.","D.F.1st","D.F.2nd"); my $color=&setbgcolor(0); my %cache; @@ -158,7 +157,7 @@ sub BuildProblemStatisticsPage { return; } my $Ptr = ''; - $Ptr .= ''; + $Ptr .= '
'; $Ptr .= ''."\n"; $Ptr .= ''."\n"; $Str .= ''."\n"; foreach(@$headings) { - $Str .= ''."\n"; @@ -283,20 +283,6 @@ sub BuildStatisticsTable { my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings, $r,$color)=@_; -#6666666 -# my $file="/home/httpd/perl/tmp/183d.txt"; -# open(OUT, ">$file"); -#6666666 -## &Apache::lonstatistics::Create_PrgWin($r); -##777777 -## my (%Activity) = &LoadActivityLog(); -## $r->print(''); -## my ($doDiffFile) = &LoadDoDiffFile(); - -##777777 -## $Str .= &Classify($discriminantFactor, $students); - my $count = 1; my $currentSequence = -1; foreach(@$orderedProblems) { @@ -332,21 +318,23 @@ sub BuildStatisticsTable { my $ref = ''.$cache->{$problem.':title'}.''; my $title = $cache->{$problem.':title'}; + if($part != 0) { + $title .= ' Part '.$part; + } my $source = $cache->{$problem.':source'}; my $tableData = join('&', $ref, $title, $source, $cache->{$_.':studentCount'}, $cache->{$_.':totalTries'}, $cache->{$_.':maxTries'}, - sprintf("%.2f", $cache->{$_.':mean'}), + $cache->{$_.':mean'}, $cache->{$_.':correct'}, $cache->{$_.':correctByOverride'}, - sprintf("%.1f", $cache->{$_.':percentWrong'}), - sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}), - sprintf("%.1f", $cache->{$_.':standardDeviation'}), - sprintf("%.1f", $cache->{$_.':skewness'}), - sprintf("%.2f", $cache->{$_.':discriminationFactor1'}), - sprintf("%.2f", $cache->{$_.':discriminationFactor2'}), - 0); # 0 is for discussion, need to figure out + $cache->{$_.':percentWrong'}, + $cache->{$_.':degreeOfDifficulty'}, + $cache->{$_.':standardDeviation'}, + $cache->{$_.':skewness'}, + $cache->{$_.':discriminationFactor1'}, + $cache->{$_.':discriminationFactor2'}); &TableRow($displayFormat,$tableData,$count,$r,$color); @@ -358,21 +346,14 @@ sub BuildStatisticsTable { } else { $r->print('
'); } -#6666666 -# $r->print('
'.$out.'&'.$DoD); -# print (OUT $out.'@'.$DoD.'&'); -#6666666 - -#6666666 -# close( OUT ); -#666666 + return; } sub TableRow { my ($displayFormat,$Str,$RealIdx,$r,$color)=@_; my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override, - $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str); + $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str); my $Ptr; if($displayFormat eq 'Display CSV Format') { $Ptr='"'.$RealIdx.'",'."\n". @@ -390,7 +371,6 @@ sub TableRow { '"'.$Sk.'",'."\n". '"'.$_D1.'",'."\n". '"'.$_D2.'"'."\n". - '"'.$DiscNo.'"'."\n". "
\n"; $r->print("\n".$Ptr); @@ -409,8 +389,7 @@ sub TableRow { ''."\n". ''."\n". ''."\n". - ''."\n". - ''."\n"; + ''."\n"; $r->print($Ptr.''."\n"); } @@ -443,10 +422,10 @@ sub ProblemStatisticsButtons { my $Ptr = '
Select Map'; $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics', @@ -269,7 +268,8 @@ sub CreateProblemStatisticsTableHeading $Str .= '
P#'.''; + $Str .= ''.$_.'  '.$SD.' '.$Sk.' '.$_D1.' '.$_D2.' '.$DiscNo.' '.$_D2.'
'; $Ptr .= '{'orderedSequences'})) { @@ -584,11 +557,12 @@ sub ExtractStudentData { } } + my $studentTriesJoined = join(':::', @studentTries); $problemData{$id.':sequenceTitle'} = $cache->{$sequence.':title'}; $problemData{$id.':studentCount'} = $studentCount; $problemData{$id.':totalTries'} = $totalTries; - $problemData{$id.':studentTries'} = \@studentTries; + $problemData{$id.':studentTries'} = $studentTriesJoined; $problemData{$id.':totalAwarded'} = $totalAwarded; $problemData{$id.':correct'} = $correct; $problemData{$id.':correctByOverride'} = $correctByOverride; @@ -627,11 +601,6 @@ sub ExtractStudentData { $problemData{'studentsLowerListCriterion2'}=join(':::', @lowerStudents2); $problemData{'problemList'} = join(':::', @problemList); -# $Discussed=0; -# if($Discuss->{"$name:$problem"}) { -# $TotDiscuss++; -# $Discussed=1; -# } return \%problemData; } @@ -668,23 +637,41 @@ sub SortProblems { elsif($sortBy eq "DoDiff") { $data = ':degreeOfDifficulty'; } elsif($sortBy eq "S.D.") { $data = ':standardDeviation'; } elsif($sortBy eq "Skew.") { $data = ':skewness'; } - elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; } - elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; } - elsif($sortBy eq "Disc.") { $data = ''; } + elsif($sortBy eq "D.F.1st") { $data = ':discriminationFactor1'; } + elsif($sortBy eq "D.F.2nd") { $data = ':discriminationFactor2'; } else { return \@problems; } my %temp; + my @sequenceList=(); foreach(@problems) { my ($sequence) = split(':', $_); - $temp{$_} = $sequence; + + my @array=(); + my $tempArray; + if(defined($temp{$sequence})) { + $tempArray = $temp{$sequence}; + } else { + push(@sequenceList, $sequence); + $tempArray = \@array; + $temp{$sequence} = $tempArray; + } + + push(@$tempArray, $_); } my @orderedProblems; if($sortProblems eq "Sort Within Sequence") { - @orderedProblems = - sort { $temp{$a} cmp $temp{$b} || - $problemData->{$a.$data} <=> $problemData->{$b.$data} } - @problems; + foreach(keys(%temp)) { + my $tempArray = $temp{$_}; + my @tempOrder = + sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} } + @$tempArray; + $temp{$_} = \@tempOrder; + } + foreach(@sequenceList) { + my $tempArray = $temp{$_}; + @orderedProblems = (@orderedProblems, @$tempArray); + } } else { @orderedProblems = sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} } @@ -704,27 +691,31 @@ sub CalculateStatistics { my @problems = split(':::', $data->{'problemList'}); foreach(@problems) { # Mean - $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ? + my $mean = ($data->{$_.':studentCount'}) ? ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0; + $data->{$_.':mean'} = sprintf("%.2f", $mean); # %Wrong - $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ? + my $pw = ($data->{$_.':studentCount'}) ? (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) : 100.0; + $data->{$_.':percentWrong'} = sprintf("%.1f", $pw); # Degree of Difficulty - $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ? + my $dod = ($data->{$_.':totalTries'}) ? (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) / $data->{$_.':totalTries'})) : 0; + $data->{$_.':degreeOfDifficulty'} = sprintf("%.2f", $dod); + # Factor in mean - my $studentTries = $data->{$_.':studentTries'}; - foreach(my $index=0; $index < scalar(@$studentTries); $index++) { - $studentTries->[$index] -= $data->{$_.':mean'}; + my @studentTries = split(':::', $data->{$_.':studentTries'}); + foreach(my $index=0; $index < scalar(@studentTries); $index++) { + $studentTries[$index] -= $mean; } my $sumSquared = 0; my $sumCubed = 0; - foreach(@$studentTries) { + foreach(@studentTries) { my $squared = ($_ * $_); my $cubed = ($squared * $_); $sumSquared += $squared; @@ -732,15 +723,27 @@ sub CalculateStatistics { } # Standard deviation - $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ? - ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0; + my $standardDeviation; + if($data->{$_.':studentCount'} - 1 > 0) { + $standardDeviation = (sqrt($sumSquared)) / + ($data->{$_.':studentCount'} - 1); + } else { + $standardDeviation = 0.0; + } + $data->{$_.':standardDeviation'} = sprintf("%.1f", $standardDeviation); # Skewness - my $standardDeviation = $data->{$_.':standardDeviation'}; - $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ? - (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) / - ($standardDeviation * $standardDeviation * $standardDeviation)) : - 0; + my $skew; + if($standardDeviation > 0.0999 && $data->{$_.':studentCount'} > 0) { + $skew = (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) / + ($standardDeviation * + $standardDeviation * + $standardDeviation)); + } else { + $skew = 0.0; + } + + $data->{$_.':skewness'} = sprintf("%.1f", $skew); # Discrimination Factor 1 my ($sequence, $problem, $part) = split(':', $_); @@ -760,7 +763,8 @@ sub CalculateStatistics { } $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0; - $data->{$_.':discriminationFactor1'} = $upper1Sum - $lower1Sum; + my $df1 = $upper1Sum - $lower1Sum; + $data->{$_.':discriminationFactor1'} = sprintf("%.2f", $df1); # Discrimination Factor 2 my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'}); @@ -778,7 +782,8 @@ sub CalculateStatistics { } $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0; - $data->{$_.':discriminationFactor2'} = $upper2Sum - $lower2Sum; + my $df2 = $upper2Sum - $lower2Sum; + $data->{$_.':discriminationFactor2'} = sprintf("%.2f", $df2); } return;