![]() ![]() | ![]() |
Sorting the statistics table works properly
1: # The LearningOnline Network with CAPA 2: # (Publication Handler 3: # 4: # $Id: lonproblemstatistics.pm,v 1.14 2002/08/06 02:01:05 minaeibi Exp $ 5: # 6: # Copyright Michigan State University Board of Trustees 7: # 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA). 9: # 10: # LON-CAPA is free software; you can redistribute it and/or modify 11: # it under the terms of the GNU General Public License as published by 12: # the Free Software Foundation; either version 2 of the License, or 13: # (at your option) any later version. 14: # 15: # LON-CAPA is distributed in the hope that it will be useful, 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18: # GNU General Public License for more details. 19: # 20: # You should have received a copy of the GNU General Public License 21: # along with LON-CAPA; if not, write to the Free Software 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23: # 24: # /home/httpd/html/adm/gpl.txt 25: # 26: # http://www.lon-capa.org/ 27: # 28: # (Navigate problems for statistical reports 29: # YEAR=2001 30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei 31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei 32: # YEAR=2002 33: # 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 34: # 5/12,5/14,5/15,5/19,5/26,7/16,7/25,7/29,8/5 Behrouz Minaei 35: # 36: ### 37: 38: package Apache::lonproblemstatistics; 39: 40: use strict; 41: use Apache::lonnet(); 42: use Apache::lonhtmlcommon; 43: use Apache::loncoursedata; 44: use GDBM_File; 45: 46: 47: sub BuildProblemStatisticsPage { 48: my ($cacheDB, $students, $courseID, $c, $r)=@_; 49: my %cache; 50: #my %DoDiff; 51: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) { 52: return '<html><body>Unable to tie database.</body></html>'; 53: } 54: 55: my $Ptr = ''; 56: $Ptr .= '<table border="0"><tbody>'; 57: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n"; 58: $Ptr .= '<td align="left">'; 59: $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics', 60: 'Statistics'); 61: $Ptr .= '</td></tr>'."\n"; 62: $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n"; 63: $Ptr .= '<td align="left">'."\n"; 64: $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions( 65: $cache{'ProblemStatisticsAscend'}, 66: 'ProblemStatistics', 67: 'Statistics'); 68: $Ptr .= '</td></tr>'."\n"; 69: $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}); 70: $Ptr .= '</table>'; 71: $Ptr .= &ProblemStatisticsLegend(); 72: $r->print($Ptr); 73: $r->rflush(); 74: 75: untie(%cache); 76: &Create_PrgWin($r); 77: my $count=0; 78: foreach (@$students) { 79: &Update_PrgWin(scalar(@$students),$count,$_,$r); 80: my $courseData = 81: &Apache::loncoursedata::DownloadCourseInformation($_, $courseID); 82: last if ($c->aborted()); 83: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) { 84: &Apache::loncoursedata::ProcessStudentData(\%cache, 85: $courseData, $_); 86: untie(%cache); 87: } 88: $count++; 89: } 90: &Close_PrgWin($r); 91: if($c->aborted()) { return; } 92: 93: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) { 94: return '<html><body>Unable to tie database.</body></html>'; 95: } 96: 97: my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod", 98: 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff", 99: 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd", 13, "Disc."); 100: my $color=&setbgcolor(0); 101: 102: my $state=$ENV{'form.ProblemStatisticsHeading'}; 103: 104: # my $state=&Apache::lonstatistics::CheckFormElement(\%cache, 105: # 'ProblemStatisticsHeading', 106: # 'ProblemStatisticsHeading', 107: # 'Homework Sets Order'); 108: # $r->print("<br>state=".$state); 109: 110: my $TempCache; 111: 112: if ($state) { 113: $TempCache=&CacheStatisticsTable($state,\%cache,\%Header, 114: $r,$color); 115: } else { 116: my %discriminant=(); 117: my @list=(); 118: my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID); 119: my $index=0; 120: foreach (@$students) { 121: $index++; 122: #&Apache::lonstatistics::Update_PrgWin(++$index,$r); 123: &ExtractStudentData(\%cache, $_, \@list,\%Discuss, $r, 124: \%discriminant); 125: } 126: #&Apache::lonstatistics::Close_PrgWin($r); 127: my ($upper, $lower) = &Discriminant(\%discriminant,$r); 128: $TempCache= &BuildStatisticsTable(\%cache, $upper, $lower, 129: \@list, \%Header, $students, 130: $r, $color); 131: } 132: untie(%cache); 133: 134: foreach (keys %$TempCache) { 135: last if ($c->aborted()); 136: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) { 137: $cache{$_}=$TempCache->{$_}; 138: 139: untie(%cache); 140: } 141: } 142: if($c->aborted()) { return; } 143: untie(%cache); 144: } 145: 146: 147: #---- Problem Statistics Web Page --------------------------------------- 148: 149: sub CreateProblemStatisticsTableHeading { 150: my ($displayFormat,$sequenceSource,$sequenceTitle,$headings,$r)=@_; 151: if($displayFormat eq 'Display CSV Format') { 152: $r->print('<br>"'.$sequenceTitle.'","'); 153: $r->print($sequenceSource.'"'); 154: return; 155: } 156: if ($sequenceSource eq 'Sorted by: ') { 157: $r->print('<br><b>'.$sequenceSource.$sequenceTitle.'</b>'); 158: } else { 159: $r->print('<br><a href="'.$sequenceSource. 160: '" target="_blank">'.$sequenceTitle.'</a>'); 161: } 162: my $Result = "\n".'<table border=2><tr><th>P#</th>'."\n"; 163: for(my $nIndex=0; $nIndex < (scalar (keys %$headings)); $nIndex++) { 164: $Result .= '<th>'.'<input type="submit" name="'; 165: $Result .= 'ProblemStatisticsHeading" value="'; 166: $Result .= $headings->{$nIndex}.'" />'.'</th>'."\n"; 167: } 168: $Result .= "\n".'</tr>'."\n"; 169: $r->print($Result); 170: $r->rflush(); 171: } 172: 173: sub CloseTable { 174: my ($cache,$r)=@_; 175: if($cache->{'DisplayFormat'} eq 'Display CSV Format') { 176: return; 177: } 178: $r->print("\n".'</table>'."\n"); 179: $r->rflush(); 180: } 181: 182: 183: # Create progress 184: sub Create_PrgWin { 185: my ($r)=@_; 186: $r->print(<<ENDPOP); 187: <script> 188: popwin=open('','popwin','width=400,height=100'); 189: popwin.document.writeln('<html><body bgcolor="#88DDFF">'+ 190: '<title>LON-CAPA Statistics</title>'+ 191: '<h4>Computation Progress</h4>'+ 192: '<form name=popremain>'+ 193: '<input type=text size=35 name=remaining value=Starting></form>'+ 194: '</body></html>'); 195: popwin.document.close(); 196: </script> 197: ENDPOP 198: 199: $r->rflush(); 200: } 201: 202: # update progress 203: sub Update_PrgWin { 204: my ($totalStudents,$index,$name,$r)=@_; 205: $r->print('<script>popwin.document.popremain.remaining.value="'. 206: 'Computing '.$index.'/'.$totalStudents.': '. 207: $name.'";</script>'); 208: $r->rflush(); 209: } 210: 211: # close Progress Line 212: sub Close_PrgWin { 213: my ($r)=@_; 214: $r->print('<script>popwin.close()</script>'); 215: $r->rflush(); 216: } 217: 218: 219: # ------ Dump the Student's DB file and handling the data for statistics table 220: sub ExtractStudentData { 221: my ($cache,$name,$list,$Discuss,$r,$discriminant)=@_; 222: my $totalTries = 0; 223: my $totalAwarded = 0; 224: my $spent=0; 225: my $spent_yes=0; 226: my $TotDiscuss=0; 227: my $TotalOpend = 0; 228: my $ProbSolved = 0; 229: my $ProbTot = 0; 230: my $TotFirst = 0; 231: my $TimeTot = 0; 232: my $Discussed=0; 233: my $discrim=''; 234: my $tempSequenceOrder=100; 235: 236: #$Apache::lonxml::debug=1; 237: #&Apache::lonhomework::showhash(%$cache); 238: #$Apache::lonxml::debug=0; 239: 240: foreach my $sequence (split(':', $cache->{'orderedSequences'})) { 241: my $tempProblemOrder=100; 242: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' && 243: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) { 244: # $r->print("<br>sequences=$cache->{'orderedSequences'}"); 245: # $r->print("<br>".$cache->{$sequence.':title'}); 246: next; 247: } 248: $tempSequenceOrder++; 249: 250: #$discrim .= '&'; 251: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) { 252: # $r->print("<br>problems=$cache->{$sequence.':problems'}"); 253: my $problem = $cache->{$problemID.':problem'}; 254: # $r->print("<br>$problemID === $problem"); 255: my $LatestVersion = $cache->{$name.':version:'.$problem}; 256: # Output dashes for all the parts of this problem if there 257: # is no version information about the current problem. 258: #if(!$LatestVersion) { 259: # foreach my $part (split(/\:/,$cache->{$sequence.':'. 260: # $problemID. 261: # ':parts'})) { 262: # $codes .= "-,"; 263: # $attempts .= "0,"; 264: # } 265: # next; 266: #} 267: 268: my %partData=undef; 269: $partData{'count'}=0; 270: # Initialize part data, display skips correctly 271: # Skip refers to when a student made no submissions on that 272: # part/problem. 273: foreach my $part (split(/\:/,$cache->{$sequence.':'. 274: $problemID. 275: ':parts'})) { 276: $tempProblemOrder++; 277: $partData{'count'}++; 278: # $r->print("<br>parts=$cache->{$sequence.':'.$problemID.':parts'}"); 279: $partData{$part.':order'}=$tempProblemOrder; 280: $partData{$part.':tries'}=0; 281: $partData{$part.':code'}='-'; 282: } 283: 284: # Looping through all the versions of each part, starting with the 285: # oldest version. Basically, it gets the most recent 286: # set of grade data for each part. 287: for(my $Version=1; $Version<=$LatestVersion; $Version++) { 288: foreach my $part (split(/\:/,$cache->{$sequence.':'. 289: $problemID. 290: ':parts'})) { 291: 292: if(!defined($cache->{$name.":$Version:$problem". 293: ":resource.$part.solved"})) { 294: # No grade for this submission, so skip 295: next; 296: } 297: 298: my $tries=0; 299: my $time=0; 300: my $awarded=0; 301: $Discussed=0; 302: my $code='-'; 303: 304: $awarded = $cache->{"$name:$Version:$problem:resource.". 305: "$part.awarded"}; 306: $partData{$part.':awarded'} = ($awarded) ? $awarded : 0; 307: $totalAwarded += $awarded; 308: 309: $tries = $cache->{"$name:$Version:$problem". 310: ":resource.$part.tries"}; 311: $partData{$part.':tries'} = ($tries) ? $tries : 0; 312: $partData{$part.':wrong'} = $partData{$part.':tries'}; 313: $totalTries += $tries; 314: 315: my $val = $cache->{$name.":$Version:$problem". 316: ":resource.$part.solved"}; 317: if ($val eq 'correct_by_student') {$code = 'C';} 318: elsif ($val eq 'correct_by_override') {$code = 'O';} 319: elsif ($val eq 'incorrect_attempted') {$code = 'I';} 320: elsif ($val eq 'incorrect_by_override'){$code = 'I';} 321: elsif ($val eq 'excused') {$code = 'x';} 322: $partData{$part.':code'}=$code; 323: if($partData{$part.':wrong'} ne 0 && 324: ($code eq 'C' || $code eq 'O')) { 325: $partData{$part.':wrong'}--; 326: } 327: } 328: } 329: 330: #$Apache::lonxml::debug=1; 331: #&Apache::lonhomework::showhash(%partData); 332: #$Apache::lonxml::debug=0; 333: 334: # Loop through all the parts for the current problem in the 335: # correct order and prepare the output 336: my $partCounter=0; 337: foreach (split(/\:/,$cache->{$sequence.':'.$problemID. 338: ':parts'})) { 339: $partCounter++; 340: my $Yes = 0; 341: if($partData{$_.':code'} eq 'C' || 342: $partData{$_.':code'} eq 'O') { 343: $Yes=1; 344: } 345: my $pOrder=$partData{$_.':order'}; 346: my $ptr = $tempSequenceOrder.':'.$pOrder.':'.$problemID; 347: 348: if($partData{'count'} > 1) { 349: $ptr .= "*(part $_)"; 350: } 351: #if($partCounter > 1) { 352: $discrim .= '&'; 353: #} 354: 355: my ($pr_no,$dod)=split('&',$ptr); 356: # my $DoDiff=$DoDiff->{$dod}; 357: # $r->print('<br>'.$name.'---'.$ptr.'==='.$DoDiff); 358: 359: my $Fac = ($partData{$_.':tries'}) ? 360: ($partData{$_.':awarded'}/$partData{$_.':tries'}) : 0; 361: my $DisF; 362: if($Fac > 0 && $Fac < 1) { 363: $DisF = sprintf( "%.4f", $Fac ); 364: } else { 365: $DisF = $Fac; 366: } 367: 368: if ($Discuss->{"$name:$problem"}) { 369: $TotDiscuss++; 370: $Discussed=1; 371: } 372: my $time = $cache->{"$name:$LatestVersion:$problem:timestamp"}; 373: $discrim .= $tempSequenceOrder.'@'.$pOrder.'='.$DisF.'+'.$Yes; 374: $ptr .= '&'.$partData{$_.':tries'}. 375: '&'.$partData{$_.':wrong'}. 376: '&'.$partData{$_.':code'}; 377: push (@$list, $ptr."&$Discussed"); 378: # $r->print('<br>'.$_.$name.'---'.$ptr); 379: 380: #### if ($DoDiff>0.85) { 381: 382: $TimeTot += $time; 383: 384: if ($Yes==1 && $partData{$_.':tries'}==1) { 385: $TotFirst++; 386: } 387: # my $Acts= $Activity->{$name.':'.$problem}; 388: # if ($Acts) { 389: # my $Pt=&ProcAct( $Acts, $time ); 390: #my ($spe,$beg) = split(/\+/,$Pt); 391: # my $spe= $Pt; 392: # if ($Yes==1) {$spent_yes += $spe;} 393: # $spent += $spe; 394: #$Beg += $beg; 395: # $r->print('<br>'.$name.'---'.$problem.'---'.$spe); 396: # } 397: $TotalOpend++; 398: $ProbTot++; 399: 400: $tempProblemOrder++; 401: } 402: } 403: } 404: my $pstr; 405: if($totalTries) { 406: my $DisFac = ($totalAwarded/$totalTries); 407: my $DisFactor = sprintf( "%.4f", $DisFac ); 408: my $TS = sprintf( "%.2f", $spent ); 409: my $TS_yes = sprintf( "%.2f", $spent_yes ); 410: $pstr=$DisFactor.':'.$name.':'.$ProbTot.':'.$TotalOpend.':'. 411: $totalTries.':'.$ProbSolved.':'.$TotFirst.':'. 412: $TS_yes.':'.$TS.':'.$TotDiscuss; 413: (%$discriminant)->{$pstr}=$discrim; 414: } 415: } 416: 417: sub NumericSort { 418: $a <=> $b; 419: } 420: 421: sub OrderedSort { 422: if ($ENV{'form.order'} eq 'Descending') { 423: $b <=> $a; 424: } else { 425: $a <=> $b; 426: } 427: } 428: 429: 430: 431: sub BuildStatisticsTable { 432: my ($cache,$upper,$lower,$list,$headings,$students,$r,$color)=@_; 433: my $NoElements = scalar @$list; 434: my @list=sort(@$list); 435: 436: #6666666 437: # my $file="/home/httpd/perl/tmp/183d.txt"; 438: # open(OUT, ">$file"); 439: #6666666 440: ## &Apache::lonstatistics::Create_PrgWin($r); 441: ##777777 442: ## my (%Activity) = &LoadActivityLog(); 443: ## $r->print('<script>popwin.document.popremain.remaining.value="'. 444: ## 'Loading Discussion...";</script>'); 445: ## my ($doDiffFile) = &LoadDoDiffFile(); 446: 447: ##777777 448: ## $Str .= &Classify($discriminantFactor, $students); 449: 450: my $p_count = 0; 451: my $dummy; 452: my $p_val; 453: my $ResId; 454: my %TempCache; 455: my $cIdx=0; 456: 457: foreach my $sequence (split(':', $cache->{'orderedSequences'})) { 458: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' && 459: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) { 460: next; 461: } 462: &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 463: $cache->{$sequence.':source'}, 464: $cache->{$sequence.':title'}, 465: $headings,$r); 466: my ($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/, 467: $list[$cIdx]); 468: my ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar); 469: $sequence+=100; 470: while ($SqOrd==$sequence && $cIdx<$NoElements) { 471: my %storestats=(); 472: my $pOrd=$PrOrd; 473: my $Temp = $Prob; 474: my $MxTries = 0; 475: my $TotalTries = 0; 476: my $YES = 0; 477: my $Incorrect = 0; 478: my $Override = 0; 479: my $StdNo = 0; 480: my $DiscNo=0; 481: my @StdLst; 482: while ($pOrd==$PrOrd && $cIdx<$NoElements) 483: { 484: $cIdx++; 485: $StdNo++; 486: $StdLst[ $StdNo ] = $Tries; 487: $TotalTries += $Tries; 488: if ( $MxTries < $Tries ) { $MxTries = $Tries; } 489: if ( $Code eq 'C' ){ $YES++; } 490: elsif( $Code eq 'I' ) { $Incorrect++; } 491: elsif( $Code eq 'O' ) { $Override++; } 492: elsif( $Code eq '-' ) { $StdNo--; } 493: ($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/, 494: $list[$cIdx]); 495: ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar); 496: } 497: 498: $p_count++; 499: my $Dummy; 500: ($ResId,$Dummy)=split(/\*/,$Temp); 501: 502: ###################### 503: $Temp = '<a href="'.$cache->{$ResId.':source'}. 504: '" target="_blank">'.$cache->{$ResId.':title'}.$Dummy.'</a>'; 505: 506: #$r->print('<br>rid='.$ResId); 507: #$r->print('<br>src='.$cache->{$ResId.':source'}); 508: #$r->print('<br>tit='.$cache->{$ResId.':title'}); 509: 510: my $res = &Apache::lonnet::declutter($cache->{$ResId.':source'}); 511: my $urlres=$res; 512: 513: $ResId=~/(\d+)\.(\d+)/; 514: my $Map = &Apache::lonnet::declutter( $cache->{'map_id_'.$1} ); 515: $urlres=$Map; 516: ####################### 517: 518: # $res = '<a href="'.$cache->{$ResId.':source'}.'">'.$res.'</a>'; 519: #$Map = '<a href="'.$Map.'">'.$res.'</a>'; 520: 521: #------------------------ Compute the Average of Tries about one problem 522: my $Average = ($StdNo) ? $TotalTries/$StdNo : 0; 523: 524: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time; 525: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo; 526: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average; 527: 528: #-------------------------------- Compute percentage of Wrong tries 529: my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0; 530: 531: #-------------------------------- Compute Standard Deviation 532: my $StdDev = 0; 533: if ( $StdNo > 1 ) { 534: for ( my $n = 0; $n < $StdNo; $n++ ) { 535: my $Dif = $StdLst[ $n ]-$Average; 536: $StdDev += $Dif*$Dif; 537: } 538: $StdDev /= ( $StdNo - 1 ); 539: $StdDev = sqrt( $StdDev ); 540: } 541: 542: #-------------------------------- Compute Degree of Difficulty 543: my $DoDiff = 0; 544: if( $TotalTries > 0 ) { 545: $DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries ); 546: # $DoDiff = ($TotalTries)/($YES + $Override+ 0.1); 547: } 548: 549: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff; 550: 551: #-------------------------------- Compute the Skewness 552: my $Skewness = 0; 553: my $Sum = 0; 554: if ( $StdNo > 0 && $StdDev > 0 ) { 555: for ( my $n = 0; $n < $StdNo; $n++ ) { 556: my $Dif = $StdLst[ $n ]-$Average; 557: $Skewness += $Dif*$Dif*$Dif; 558: } 559: $Skewness /= $StdNo; 560: $Skewness /= $StdDev*$StdDev*$StdDev; 561: } 562: 563: #--------------------- Compute the Discrimination Factors 564: my ($Up1,$Up2)=split(/\:/,$upper->{$sequence.'@'.$pOrd}); 565: my ($Lw1,$Lw2)=split(/\:/,$lower->{$sequence.'@'.$pOrd}); 566: 567: my $Dis1 = $Up1 - $Lw1; 568: my $Dis2 = $Up2 - $Lw2; 569: my $_D1 = sprintf("%.2f", $Dis1); 570: my $_D2 = sprintf("%.2f", $Dis2); 571: 572: #----------------- Some restition in presenting the float numbers 573: my $Avg = sprintf( "%.2f", $Average ); 574: my $Wrng = sprintf( "%.1f", $Wrong ); 575: my $SD = sprintf( "%.1f", $StdDev ); 576: my $DoD = sprintf( "%.2f", $DoDiff ); 577: my $Sk = sprintf( "%.1f", $Skewness ); 578: my $join = $sequence.'@'.$pOrd.'&'.$Temp.'&'.$StdNo.'&'. 579: $TotalTries.'&'.$MxTries.'&'.$Avg.'&'. 580: $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'. 581: $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'. 582: $DiscNo.'&'.$Prob; 583: 584: #####{$sequence.'@'.$pOrd} 585: $TempCache{'CacheTable:'.($p_count-1)}=$join; 586: 587: #6666666 588: # $r->print('<br>'.$out.'&'.$DoD); 589: # print (OUT $out.'@'.$DoD.'&'); 590: #6666666 591: 592: $urlres=~/^(\w+)\/(\w+)/; 593: if ($StdNo) { 594: &Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 595: } 596: #-------------------------------- Row of statistical table 597: &TableRow($cache,$join,$cIdx,($p_count-1),$r,$color, 598: \%TempCache); 599: } 600: $TempCache{'ProblemCount'}=$p_count; 601: &CloseTable($cache,$r); 602: } 603: ### &Close_PrgWin(); 604: #6666666 605: # close( OUT ); 606: #666666 607: return \%TempCache; 608: } 609: 610: 611: sub CacheStatisticsTable { 612: my ($state,$cache,$headings,$r,$color)=@_; 613: my @list = (); 614: my %TempCache; 615: my %myHeader = reverse( %$headings ); 616: my $pos = $myHeader{$state}; 617: if ($pos > 0) {$pos++;} 618: my $p_count = $cache->{'ProblemCount'}; 619: 620: for ( my $k=0; $k<$p_count;$k++) { 621: my $key=$cache->{'CacheTable:'.$k}; 622: my @Temp=split(/\&/,$key); 623: $list[$k]=$Temp[$pos].'+'.$key; 624: } 625: 626: if ($pos>0) { 627: # $r->print('<br>pos1='.$pos); 628: # @list = sort OrderedSort (@list); 629: @list = sort NumericSort (@list); 630: } else { 631: @list = sort (@list); 632: } 633: my $cIdx=0; 634: 635: if ( $pos == 0 ) { 636: foreach my $sequence (split(':', $cache->{'orderedSequences'})) { 637: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' && 638: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) { 639: next; 640: } 641: if ($cIdx==$p_count) { 642: return \%TempCache; 643: } 644: &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 645: $cache->{$sequence.':source'}, 646: $cache->{$sequence.':title'}, 647: $headings,$r); 648: 649: my ($tar)=split(/\&/,$list[$cIdx]); 650: $tar=~s/\+//eg; 651: my ($SqOrd)=split(/\@/,$tar); 652: $sequence+=100; 653: while ($SqOrd==$sequence && $cIdx<$p_count) { 654: my($Pre, $Post) = split(/\+/,$list[$cIdx]); 655: &TableRow($cache,$Post,$cIdx,$cIdx,$r,$color,\%TempCache); 656: $cIdx++; 657: my ($tar)=split(/\&/,$list[$cIdx]); 658: $tar=~s/\+//eg; 659: ($SqOrd)=split(/\@/,$tar); 660: } 661: &CloseTable($cache,$r); 662: } 663: } 664: else { 665: &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 666: 'Sorted by: ', 667: $headings->{$pos-1}, 668: $headings,$r); 669: for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) { 670: my($Pre, $Post) = split(/\+/,$list[$nIndex]); 671: &TableRow($cache,$Post,$nIndex,$nIndex,$r,$color,\%TempCache); 672: } 673: &CloseTable($cache,$r); 674: } 675: 676: return \%TempCache; 677: } 678: 679: 680: sub TableRow { 681: my ($cache,$Str,$Idx,$RealIdx,$r,$color,$GraphDat)=@_; 682: my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override, 683: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str); 684: my $Ptr; 685: if($cache->{'DisplayFormat'} eq 'Display CSV Format') { 686: my ($ResId,$Dummy)=split(/\*/,$Prob); 687: $Ptr="\n".'<br>'. 688: "\n".'"'.($RealIdx+1).'",'. 689: "\n".'"'.$cache->{$ResId.':title'}.$Dummy.'",'. 690: "\n".'"'.$cache->{$ResId.':source'}.'",'. 691: "\n".'"'.$StdNo.'",'. 692: "\n".'"'.$TotalTries.'",'. 693: "\n".'"'.$MxTries.'",'. 694: "\n".'"'.$Avg.'",'. 695: "\n".'"'.$YES.'",'. 696: "\n".'"'.$Override.'",'. 697: "\n".'"'.$Wrng.'",'. 698: "\n".'"'.$DoD.'",'. 699: "\n".'"'.$SD.'",'. 700: "\n".'"'.$Sk.'",'. 701: "\n".'"'.$_D1.'",'. 702: "\n".'"'.$_D2.'"'. 703: "\n".'"'.$DiscNo.'"'; 704: 705: $r->print("\n".$Ptr); 706: } else { 707: $Ptr="\n".'<tr>'. 708: "\n".'<td>'.($RealIdx+1).'</td>'. 709: "\n".'<td>'.$Temp.'</td>'. 710: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'. 711: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'. 712: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'. 713: "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'. 714: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'. 715: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'. 716: "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'. 717: "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'. 718: "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'. 719: "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'. 720: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'. 721: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'. 722: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>'; 723: $r->print("\n".$Ptr.'</tr>' ); 724: } 725: $GraphDat->{'GraphGif:'.$RealIdx}=$DoD.':'.$Wrng; 726: } 727: 728: 729: # For loading the colored table for display or un-colored for print 730: sub setbgcolor { 731: my $PrintTable=shift; 732: my %color; 733: if ($PrintTable){ 734: $color{"gb"}="#FFFFFF"; 735: $color{"red"}="#FFFFFF"; 736: $color{"yellow"}="#FFFFFF"; 737: $color{"green"}="#FFFFFF"; 738: $color{"purple"}="#FFFFFF"; 739: } else { 740: $color{"gb"}="#DDFFFF"; 741: $color{"red"}="#FFDDDD"; 742: $color{"yellow"}="#EEFFCC"; 743: $color{"green"}="#DDFFDD"; 744: $color{"purple"}="#FFDDFF"; 745: } 746: 747: return \%color; 748: } 749: 750: sub ProblemStatisticsButtons { 751: my ($displayFormat)=@_; 752: 753: my $Ptr = '<tr><td></td><td align="left">'; 754: $Ptr .= '<input type="submit" name="DoDiffGraph" '; 755: $Ptr .= 'value="DoDiff Graph" />'."\n"; 756: $Ptr .= ' '; 757: $Ptr .= '<input type="submit" name="PercentWrongGraph" '; 758: $Ptr .= 'value="%Wrong Graph" />'."\n"; 759: $Ptr .= ' '; 760: $Ptr .= '<input type="submit" name="DisplayCSVFormat" '; 761: if($displayFormat eq 'Display CSV Format') { 762: $Ptr .= 'value="Display Table Format" />'."\n"; 763: } else { 764: $Ptr .= 'value="Display CSV Format" />'."\n"; 765: } 766: $Ptr .= '</td></tr>'; 767: 768: return $Ptr; 769: } 770: 771: sub ProblemStatisticsLegend { 772: my $Ptr = ''; 773: $Ptr = '<table border="0">'; 774: $Ptr .= '<tr><td>'; 775: $Ptr .= '<b>#Stdnts</b></td>'; 776: $Ptr .= '<td>Total Number of Students opened the problem.'; 777: $Ptr .= '</td></tr><tr><td>'; 778: $Ptr .= '<b>Tries</b></td>'; 779: $Ptr .= '<td>Total Number of Tries for solving the problem.'; 780: $Ptr .= '</td></tr><tr><td>'; 781: $Ptr .= '<b>Mod</b></td>'; 782: $Ptr .= '<td>Maximunm Number of Tries for solving the problem.'; 783: $Ptr .= '</td></tr><tr><td>'; 784: $Ptr .= '<b>Mean</b></td>'; 785: $Ptr .= '<td>Average Number of the tries. [ Tries / #Stdnts ]'; 786: $Ptr .= '</td></tr><tr><td>'; 787: $Ptr .= '<b>#YES</b></td>'; 788: $Ptr .= '<td>Number of students solved the problem correctly.'; 789: $Ptr .= '</td></tr><tr><td>'; 790: $Ptr .= '<b>#yes</b></td>'; 791: $Ptr .= '<td>Number of students solved the problem by override.'; 792: $Ptr .= '</td></tr><tr><td>'; 793: $Ptr .= '<b>%Wrng</b></td>'; 794: $Ptr .= '<td>Percentage of students tried to solve the problem '; 795: $Ptr .= 'but still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]'; 796: $Ptr .= '</td></tr><tr><td>'; 797: $Ptr .= '<b>DoDiff</b></td>'; 798: $Ptr .= '<td>Degree of Difficulty of the problem. '; 799: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]'; 800: $Ptr .= '</td></tr><tr><td>'; 801: $Ptr .= '<b>S.D.</b></td>'; 802: $Ptr .= '<td>Standard Deviation of the tries. '; 803: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) '; 804: $Ptr .= 'where Xi denotes every student\'s tries ]'; 805: $Ptr .= '</td></tr><tr><td>'; 806: $Ptr .= '<b>Skew.</b></td>'; 807: $Ptr .= '<td>Skewness of the students tries.'; 808: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]'; 809: $Ptr .= '</td></tr><tr><td>'; 810: $Ptr .= '<b>Dis.F.</b></td>'; 811: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the '; 812: $Ptr .= 'problem according to a Criterion<br>'; 813: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - '; 814: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>'; 815: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: '; 816: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>'; 817: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: '; 818: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>'; 819: $Ptr .= '</td></tr>'; 820: $Ptr .= '<tr><td><b>Disc.</b></td>'; 821: $Ptr .= '<td>Number of Students had at least one discussion.'; 822: $Ptr .= '</td></tr></table>'; 823: 824: return $Ptr; 825: } 826: 827: #------- Processing upperlist and lowerlist according to each problem 828: sub ProcessDiscriminant { 829: my ($List,$r) = @_; 830: my @sortedList = sort (@$List); 831: my $Count = scalar @sortedList; 832: my $Problem; 833: my @Dis; 834: my $Slvd=0; 835: my $tmp; 836: my $Sum1=0; 837: my $Sum2=0; 838: my $nIndex=0; 839: my $nStudent=0; 840: my %Proc=undef; 841: while ($nIndex<$Count) { 842: # $r->print("<br> $nIndex) $sortedList[$nIndex]"); 843: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]); 844: @Dis=split(/\+/,$tmp); 845: my $Temp = $Problem; 846: do { 847: $nIndex++; 848: $nStudent++; 849: $Sum1 += $Dis[0]; 850: $Sum2 += $Dis[1]; 851: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]); 852: @Dis=split(/\+/,$tmp); 853: } while ( $Problem eq $Temp && $nIndex < $Count ); 854: $Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent); 855: # $r->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}"); 856: $Sum1=0; 857: $Sum2=0; 858: $nStudent=0; 859: } 860: 861: return %Proc; 862: } 863: 864: #------- Creating Discimination factor 865: sub Discriminant { 866: my ($discriminant,$r)=@_; 867: #$Apache::lonxml::debug=1; 868: #&Apache::lonhomework::showhash(%$discriminant); 869: #$Apache::lonxml::debug=0; 870: my @discriminantKeys=keys(%$discriminant); 871: my $Count = scalar @discriminantKeys; 872: 873: my $UpCnt = int(0.27*$Count); 874: my $low=0; 875: my $up=$Count-$UpCnt; 876: my @UpList=(); 877: my @LowList=(); 878: 879: $Count=0; 880: foreach my $key (sort(@discriminantKeys)) { 881: $Count++; 882: if($low < $UpCnt || $Count > $up) { 883: $low++; 884: my $str=$discriminant->{$key}; 885: foreach(split(/\&/,$str)){ 886: if($_) { 887: if($low<$UpCnt) { push(@LowList,$_); } 888: else { push(@UpList,$_); } 889: } 890: } 891: } 892: } 893: my %DisUp = &ProcessDiscriminant(\@UpList,$r); 894: my %DisLow = &ProcessDiscriminant(\@LowList,$r); 895: 896: return (\%DisUp, \%DisLow); 897: } 898: 899: #---- END Problem Statistics Web Page ---------------------------------------- 900: 901: #---- Problem Statistics Graph Web Page -------------------------------------- 902: 903: # ------------------------------------------- Prepare data for Graphical chart 904: 905: sub BuildDiffGraph { 906: my ($r)=@_; 907: 908: my $graphData = &GetGraphData('DiffGraph', $r); 909: $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />'); 910: 911: return; 912: } 913: 914: sub BuildWrongGraph { 915: my ($r)=@_; 916: 917: my $graphData = &GetGraphData('WrongGraph', $r); 918: $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />'); 919: 920: return; 921: } 922: 923: 924: sub GetGraphData { 925: my ($ylab,$r,$cache)=@_; 926: my $Col; 927: my $data=''; 928: my $count = 0; 929: my $Max = 0; 930: my $cid=$ENV{'request.course.id'}; 931: 932: if ( $ylab eq 'DoDiff Graph' ) { 933: $ylab = 'Degree-of-Difficulty'; 934: $Col = 0; 935: } 936: else { 937: $ylab = 'Wrong-Percentage'; 938: $Col = 1; 939: } 940: 941: my $p_count = $cache->{'ProblemCount'}; 942: 943: for ( my $k=0; $k<$p_count;$k++) { 944: my $key=$cache->{'CacheTable:'.$k}; 945: my @Temp=split(/\&/,$key); 946: # $list[$k]=$key; 947: } 948: 949: # foreach (sort NumericSort keys %GraphDat) { 950: # my @Temp=split(/\:/,$GraphDat{$_}); 951: # my $inf = $Temp[$Col]; 952: # if ( $Max < $inf ) {$Max = $inf;} 953: # $data .= $inf.','; 954: # $count++; 955: # } 956: if ( $Max > 1 ) { 957: $Max += (10 - $Max % 10); 958: $Max = int($Max); 959: } else { $Max = 1; } 960: 961: #untie(%GraphDat); 962: 963: my $Course = $ENV{'course.'.$cid.'.description'}; 964: $Course =~ s/\ /"_"/eg; 965: my $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'. 966: $Max.'&'.$count.'&'.$data; 967: } 968: 969: 970: 1; 971: __END__