Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.15

1.1       stredwic    1: # The LearningOnline Network with CAPA
                      2: # (Publication Handler
                      3: #
1.15    ! minaeibi    4: # $Id: lonproblemstatistics.pm,v 1.14 2002/08/06 02:01:05 minaeibi Exp $
1.1       stredwic    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
1.12      minaeibi   34: # 5/12,5/14,5/15,5/19,5/26,7/16,7/25,7/29,8/5  Behrouz Minaei
1.1       stredwic   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 {
1.5       minaeibi   48:     my ($cacheDB, $students, $courseID, $c, $r)=@_;
1.1       stredwic   49:     my %cache;
1.2       minaeibi   50:     #my %DoDiff;
1.1       stredwic   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">';
1.9       stredwic   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');
1.1       stredwic   68:     $Ptr .= '</td></tr>'."\n";
                     69:     $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'});
1.2       minaeibi   70:     $Ptr .= '</table>';
1.1       stredwic   71:     $Ptr .= &ProblemStatisticsLegend();
1.5       minaeibi   72:     $r->print($Ptr);
1.13      stredwic   73:     $r->rflush();
1.1       stredwic   74: 
                     75:     untie(%cache);
1.13      stredwic   76:     &Create_PrgWin($r);
                     77:     my $count=0;
1.1       stredwic   78:     foreach (@$students) {
1.13      stredwic   79:         &Update_PrgWin(scalar(@$students),$count,$_,$r);
1.1       stredwic   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:         }
1.13      stredwic   88:         $count++;
1.1       stredwic   89:     }
1.13      stredwic   90:     &Close_PrgWin($r);
1.5       minaeibi   91:     if($c->aborted()) { return; }
1.1       stredwic   92: 
                     93:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
                     94:         return '<html><body>Unable to tie database.</body></html>';
                     95:     }
1.12      minaeibi   96: 
1.1       stredwic   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.");
1.5       minaeibi  100:     my $color=&setbgcolor(0);
1.12      minaeibi  101: 
                    102:     my $state=$ENV{'form.ProblemStatisticsHeading'}; 
                    103: 
                    104: #    my $state=&Apache::lonstatistics::CheckFormElement(\%cache,
                    105: #                                                  'ProblemStatisticsHeading',
                    106: #                                                  'ProblemStatisticsHeading',
                    107: #                                                  'Homework Sets Order'); 
1.14      minaeibi  108: #    $r->print("<br>state=".$state);
1.12      minaeibi  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; }
1.1       stredwic  143:     untie(%cache);
                    144: }
                    145: 
                    146: 
                    147: #---- Problem Statistics Web Page ---------------------------------------
                    148: 
                    149: sub CreateProblemStatisticsTableHeading {
1.2       minaeibi  150:     my ($displayFormat,$sequenceSource,$sequenceTitle,$headings,$r)=@_;
1.1       stredwic  151:     if($displayFormat eq 'Display CSV Format') {
                    152:         $r->print('<br>"'.$sequenceTitle.'","');
                    153:         $r->print($sequenceSource.'"');
                    154: 	return;
                    155:     }
1.14      minaeibi  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:     }
1.1       stredwic  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 {
1.2       minaeibi  174:     my ($cache,$r)=@_;
1.1       stredwic  175:     if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
                    176: 	return;
                    177:     }    
                    178:     $r->print("\n".'</table>'."\n");
                    179:     $r->rflush();
                    180: }
                    181: 
                    182: 
1.13      stredwic  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: }
1.14      minaeibi  217: 
1.1       stredwic  218:  
                    219: # ------ Dump the Student's DB file and handling the data for statistics table 
                    220: sub ExtractStudentData {
1.6       minaeibi  221:     my ($cache,$name,$list,$Discuss,$r,$discriminant)=@_;
1.1       stredwic  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;
1.7       minaeibi  233:     my $discrim='';
1.5       minaeibi  234:     my $tempSequenceOrder=100;
1.1       stredwic  235: 
1.5       minaeibi  236: #$Apache::lonxml::debug=1;
1.3       minaeibi  237: #&Apache::lonhomework::showhash(%$cache);
1.5       minaeibi  238: #$Apache::lonxml::debug=0;
1.3       minaeibi  239: 
1.1       stredwic  240:     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
1.5       minaeibi  241: 	my $tempProblemOrder=100;
1.9       stredwic  242:         if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
                    243:            $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
1.5       minaeibi  244: #	    $r->print("<br>sequences=$cache->{'orderedSequences'}");
1.4       minaeibi  245: #	    $r->print("<br>".$cache->{$sequence.':title'});
1.9       stredwic  246:             next;
                    247:         }
                    248: 	$tempSequenceOrder++;
1.1       stredwic  249: 
1.7       minaeibi  250:         #$discrim .= '&';
1.1       stredwic  251:         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
1.5       minaeibi  252: #	    $r->print("<br>problems=$cache->{$sequence.':problems'}");
1.1       stredwic  253:             my $problem = $cache->{$problemID.':problem'};
1.5       minaeibi  254: #	    $r->print("<br>$problemID === $problem");
1.1       stredwic  255:             my $LatestVersion = $cache->{$name.':version:'.$problem};
1.3       minaeibi  256: 	    # Output dashes for all the parts of this problem if there
1.1       stredwic  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;
1.7       minaeibi  269: 	    $partData{'count'}=0;
1.1       stredwic  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'})) {
1.5       minaeibi  276: 		$tempProblemOrder++;
1.7       minaeibi  277: 		$partData{'count'}++;
1.5       minaeibi  278: #		$r->print("<br>parts=$cache->{$sequence.':'.$problemID.':parts'}");
                    279:                 $partData{$part.':order'}=$tempProblemOrder;
1.1       stredwic  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++) {
1.3       minaeibi  288: 		foreach my $part (split(/\:/,$cache->{$sequence.':'.
1.1       stredwic  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;
1.5       minaeibi  302:                     my $code='-';
1.1       stredwic  303: 
1.7       minaeibi  304:                     $awarded = $cache->{"$name:$Version:$problem:resource.".
1.1       stredwic  305:                                         "$part.awarded"};
                    306:                     $partData{$part.':awarded'} = ($awarded) ? $awarded : 0;
                    307:                     $totalAwarded += $awarded;
                    308: 
1.7       minaeibi  309:                     $tries = $cache->{"$name:$Version:$problem".
1.1       stredwic  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: 
1.5       minaeibi  330: #$Apache::lonxml::debug=1;
                    331: #&Apache::lonhomework::showhash(%partData);
                    332: #$Apache::lonxml::debug=0;
                    333: 
1.1       stredwic  334:             # Loop through all the parts for the current problem in the 
                    335:             # correct order and prepare the output
1.7       minaeibi  336: 	    my $partCounter=0;
1.1       stredwic  337:             foreach (split(/\:/,$cache->{$sequence.':'.$problemID.
                    338:                                          ':parts'})) {
1.7       minaeibi  339: 		$partCounter++;
1.1       stredwic  340:                 my $Yes = 0;
                    341:                 if($partData{$_.':code'} eq 'C' || 
                    342:                    $partData{$_.':code'} eq 'O') {
                    343:                     $Yes=1;
                    344:                 }
1.5       minaeibi  345:                 my $pOrder=$partData{$_.':order'};
                    346:                 my $ptr = $tempSequenceOrder.':'.$pOrder.':'.$problemID;
1.1       stredwic  347: 
1.7       minaeibi  348:                 if($partData{'count'} > 1) {
1.1       stredwic  349:                     $ptr .= "*(part $_)";
                    350:                 }
1.7       minaeibi  351:                 #if($partCounter > 1) {
                    352:                     $discrim .= '&';
                    353:                 #}
1.1       stredwic  354: 
                    355: 		my ($pr_no,$dod)=split('&',$ptr);
                    356: #		my $DoDiff=$DoDiff->{$dod};
                    357: #               $r->print('<br>'.$name.'---'.$ptr.'==='.$DoDiff);
                    358: 
1.5       minaeibi  359:                 my $Fac = ($partData{$_.':tries'}) ? 
1.1       stredwic  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: 
1.3       minaeibi  368:                 if ($Discuss->{"$name:$problem"}) {
1.1       stredwic  369: 		    $TotDiscuss++;
                    370:                     $Discussed=1;
                    371:                 }
                    372:                 my $time = $cache->{"$name:$LatestVersion:$problem:timestamp"};
1.7       minaeibi  373:                 $discrim .= $tempSequenceOrder.'@'.$pOrder.'='.$DisF.'+'.$Yes;
1.5       minaeibi  374:                 $ptr .= '&'.$partData{$_.':tries'}.
                    375:                         '&'.$partData{$_.':wrong'}.
                    376:                         '&'.$partData{$_.':code'};
1.1       stredwic  377:                 push (@$list, $ptr."&$Discussed");
1.5       minaeibi  378: #                $r->print('<br>'.$_.$name.'---'.$ptr);
1.3       minaeibi  379: 		
1.1       stredwic  380: ####		if ($DoDiff>0.85) {
                    381: 
                    382:                 $TimeTot += $time;
                    383: 
1.5       minaeibi  384:                 if ($Yes==1 && $partData{$_.':tries'}==1) {
1.1       stredwic  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:         }
1.7       minaeibi  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;
1.1       stredwic  414:     }
                    415: }
                    416: 
1.14      minaeibi  417: sub NumericSort {
                    418:     $a <=> $b;
                    419: }
1.1       stredwic  420: 
1.14      minaeibi  421: sub OrderedSort  {
                    422:     if ($ENV{'form.order'} eq 'Descending') {
                    423: 	$b <=> $a;
                    424:     } else { 
                    425: 	$a <=> $b;
1.1       stredwic  426:     }
                    427: }
1.12      minaeibi  428: 
1.1       stredwic  429: 
1.3       minaeibi  430: 
1.1       stredwic  431: sub BuildStatisticsTable {
1.7       minaeibi  432:     my ($cache,$upper,$lower,$list,$headings,$students,$r,$color)=@_;
1.5       minaeibi  433:     my $NoElements = scalar @$list;
1.12      minaeibi  434:     my @list=sort(@$list);
1.5       minaeibi  435: 
1.1       stredwic  436: #6666666
                    437: #    my $file="/home/httpd/perl/tmp/183d.txt";
                    438: #    open(OUT, ">$file");
                    439: #6666666
1.2       minaeibi  440: ##     &Apache::lonstatistics::Create_PrgWin($r);
1.1       stredwic  441: ##777777
                    442: ##    my (%Activity) = &LoadActivityLog();
                    443: ##    $r->print('<script>popwin.document.popremain.remaining.value="'.
                    444: ##              'Loading Discussion...";</script>');
                    445: ##    my ($doDiffFile) = &LoadDoDiffFile();
                    446: 
1.5       minaeibi  447: ##777777
                    448: ##    $Str .= &Classify($discriminantFactor, $students);
                    449: 
1.1       stredwic  450:     my $p_count = 0;
                    451:     my $dummy;
                    452:     my $p_val;
                    453:     my $ResId;
1.12      minaeibi  454:     my %TempCache;
1.5       minaeibi  455:     my $cIdx=0;
1.3       minaeibi  456: 
1.1       stredwic  457:     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
1.9       stredwic  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'},
1.5       minaeibi  464:                                              $cache->{$sequence.':title'}, 
1.2       minaeibi  465:                                              $headings,$r);
1.5       minaeibi  466: 	my ($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,
1.12      minaeibi  467:                                                    $list[$cIdx]);
1.5       minaeibi  468:         my ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar);
                    469: 	$sequence+=100;
                    470: 	while ($SqOrd==$sequence && $cIdx<$NoElements) {
1.1       stredwic  471: 	    my %storestats=();
1.5       minaeibi  472: 	    my $pOrd=$PrOrd;
1.1       stredwic  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;
1.5       minaeibi  482: 	    while ($pOrd==$PrOrd && $cIdx<$NoElements)
1.1       stredwic  483: 	    {
1.5       minaeibi  484: 		$cIdx++;
1.1       stredwic  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++; }
1.5       minaeibi  492: 		elsif( $Code eq '-' ) { $StdNo--; }
                    493: 		($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,
1.12      minaeibi  494:                                                      $list[$cIdx]);
1.5       minaeibi  495: 	        ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar);
                    496: 	    }
                    497: 
1.1       stredwic  498: 	    $p_count++;
                    499: 	    my $Dummy;
                    500: 	    ($ResId,$Dummy)=split(/\*/,$Temp);
                    501: 
1.5       minaeibi  502: ######################
                    503: 	    $Temp = '<a href="'.$cache->{$ResId.':source'}.
                    504:                 '" target="_blank">'.$cache->{$ResId.':title'}.$Dummy.'</a>';
1.1       stredwic  505: 
1.8       minaeibi  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'});
1.1       stredwic  511: 	    my $urlres=$res;
                    512: 
                    513: 	    $ResId=~/(\d+)\.(\d+)/;
1.2       minaeibi  514: 	    my $Map = &Apache::lonnet::declutter( $cache->{'map_id_'.$1} );
1.1       stredwic  515: 	    $urlres=$Map;
1.5       minaeibi  516: #######################
                    517: 
1.10      stredwic  518: #	    $res = '<a href="'.$cache->{$ResId.':source'}.'">'.$res.'</a>';
1.1       stredwic  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: 
1.5       minaeibi  524: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;
1.1       stredwic  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
1.7       minaeibi  564:             my ($Up1,$Up2)=split(/\:/,$upper->{$sequence.'@'.$pOrd});
                    565: 	    my ($Lw1,$Lw2)=split(/\:/,$lower->{$sequence.'@'.$pOrd});
                    566: 
1.1       stredwic  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 );
1.12      minaeibi  578: 	    my $join = $sequence.'@'.$pOrd.'&'.$Temp.'&'.$StdNo.'&'.
1.1       stredwic  579:                        $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
                    580:                        $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
                    581: 		       $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
                    582:                        $DiscNo.'&'.$Prob;
1.11      minaeibi  583: 
                    584: #####{$sequence.'@'.$pOrd}
1.12      minaeibi  585: 	    $TempCache{'CacheTable:'.($p_count-1)}=$join;
1.1       stredwic  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); 
1.14      minaeibi  595:     }
1.1       stredwic  596: #-------------------------------- Row of statistical table
1.12      minaeibi  597:             &TableRow($cache,$join,$cIdx,($p_count-1),$r,$color,
                    598:                       \%TempCache);
1.1       stredwic  599: 	}
1.12      minaeibi  600: 	$TempCache{'ProblemCount'}=$p_count;
1.2       minaeibi  601: 	&CloseTable($cache,$r);
1.1       stredwic  602:     }
1.5       minaeibi  603: ###    &Close_PrgWin();
1.14      minaeibi  604: #6666666
1.1       stredwic  605: #    close( OUT );
                    606: #666666
1.12      minaeibi  607:     return \%TempCache;
1.1       stredwic  608: }
                    609: 
1.12      minaeibi  610: 
                    611: sub CacheStatisticsTable {
1.14      minaeibi  612:     my ($state,$cache,$headings,$r,$color)=@_;
                    613:     my @list = (); 
1.12      minaeibi  614:     my %TempCache;
1.14      minaeibi  615:     my %myHeader = reverse( %$headings );
1.12      minaeibi  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);
1.14      minaeibi  623: 	$list[$k]=$Temp[$pos].'+'.$key;
                    624:     }
                    625:     
                    626:     if ($pos>0) {
                    627: #	$r->print('<br>pos1='.$pos);
1.15    ! minaeibi  628:         @list = sort OrderedSort (@list);
1.14      minaeibi  629:     } else {
                    630:         @list = sort (@list);
1.1       stredwic  631:     }
1.14      minaeibi  632:     my $cIdx=0;
1.1       stredwic  633: 
1.14      minaeibi  634:     if ( $pos == 0 ) {
1.12      minaeibi  635: 	foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
                    636: 	    if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
                    637: 	       $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
                    638: 		next;
                    639: 	    }
1.14      minaeibi  640: 	    if ($cIdx==$p_count) {
                    641: 		return \%TempCache;
                    642: 	    }
1.12      minaeibi  643: 	    &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 
                    644:                                              $cache->{$sequence.':source'},
                    645:                                              $cache->{$sequence.':title'}, 
                    646:                                              $headings,$r);
                    647: 
1.14      minaeibi  648: 	    my ($tar)=split(/\&/,$list[$cIdx]);
                    649: 	    $tar=~s/\+//eg;
                    650: 	    my ($SqOrd)=split(/\@/,$tar);
1.12      minaeibi  651: 	    $sequence+=100;
1.14      minaeibi  652: 	    while ($SqOrd==$sequence && $cIdx<$p_count) {
                    653: 		my($Pre, $Post) = split(/\+/,$list[$cIdx]); 
                    654: 		&TableRow($cache,$Post,$cIdx,$cIdx,$r,$color,\%TempCache);
                    655: 		$cIdx++;
                    656: 		my ($tar)=split(/\&/,$list[$cIdx]);
                    657: 		$tar=~s/\+//eg;
                    658: 		($SqOrd)=split(/\@/,$tar);
1.1       stredwic  659: 	    }
1.14      minaeibi  660: 	    &CloseTable($cache,$r);
1.1       stredwic  661: 	}
                    662:     }
                    663:     else {
1.12      minaeibi  664:         &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 
1.14      minaeibi  665:                                              'Sorted by: ',
                    666: 					     $headings->{$pos-1},
1.12      minaeibi  667:                                              $headings,$r);
1.1       stredwic  668: 	for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
1.14      minaeibi  669: 	    my($Pre, $Post) = split(/\+/,$list[$nIndex]);
                    670: 	    &TableRow($cache,$Post,$nIndex,$nIndex,$r,$color,\%TempCache);
1.1       stredwic  671: 	} 
1.14      minaeibi  672: 	&CloseTable($cache,$r);
1.1       stredwic  673:     }
1.12      minaeibi  674: 
                    675:     return \%TempCache;
1.1       stredwic  676: }
1.12      minaeibi  677: 
1.1       stredwic  678: 
                    679: sub TableRow {
1.2       minaeibi  680:     my ($cache,$Str,$Idx,$RealIdx,$r,$color,$GraphDat)=@_;
1.1       stredwic  681:     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
                    682:        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);	
1.8       minaeibi  683:     my $Ptr;
1.9       stredwic  684:     if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
1.1       stredwic  685:         my ($ResId,$Dummy)=split(/\*/,$Prob);
1.8       minaeibi  686:         $Ptr="\n".'<br>'.
                    687:              "\n".'"'.($RealIdx+1).'",'.
1.10      stredwic  688:              "\n".'"'.$cache->{$ResId.':title'}.$Dummy.'",'.
                    689:              "\n".'"'.$cache->{$ResId.':source'}.'",'.
1.8       minaeibi  690:              "\n".'"'.$StdNo.'",'.
                    691:              "\n".'"'.$TotalTries.'",'.
                    692:              "\n".'"'.$MxTries.'",'.
                    693:              "\n".'"'.$Avg.'",'.
                    694:              "\n".'"'.$YES.'",'.
                    695:              "\n".'"'.$Override.'",'.
                    696:              "\n".'"'.$Wrng.'",'.
                    697:              "\n".'"'.$DoD.'",'.
                    698:              "\n".'"'.$SD.'",'.
                    699:              "\n".'"'.$Sk.'",'.
                    700:              "\n".'"'.$_D1.'",'.
                    701: 	     "\n".'"'.$_D2.'"'.
                    702: 	     "\n".'"'.$DiscNo.'"';
1.1       stredwic  703: 
                    704:         $r->print("\n".$Ptr);
1.8       minaeibi  705:     } else {
                    706:         $Ptr="\n".'<tr>'.
                    707:              "\n".'<td>'.($RealIdx+1).'</td>'.
                    708:              "\n".'<td>'.$Temp.'</td>'.
                    709:              "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
                    710:              "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
                    711:              "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
                    712:              "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
                    713:              "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
                    714:              "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
                    715:              "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
                    716:              "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
                    717:              "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
                    718:              "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
                    719:              "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
                    720: 	     "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
                    721:              "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
1.1       stredwic  722:         $r->print("\n".$Ptr.'</tr>' );
                    723:     }
1.14      minaeibi  724:     $GraphDat->{'GraphGif:'.$RealIdx}=$DoD.':'.$Wrng;
1.1       stredwic  725: }
1.5       minaeibi  726: 
                    727: 
                    728: # For loading the colored table for display or un-colored for print
                    729: sub setbgcolor {
                    730:     my $PrintTable=shift;
                    731:     my %color;
                    732:     if ($PrintTable){
                    733: 	$color{"gb"}="#FFFFFF";
                    734: 	$color{"red"}="#FFFFFF";
                    735: 	$color{"yellow"}="#FFFFFF";
                    736: 	$color{"green"}="#FFFFFF";
                    737: 	$color{"purple"}="#FFFFFF";
                    738:     } else {
                    739: 	$color{"gb"}="#DDFFFF";
                    740: 	$color{"red"}="#FFDDDD";
                    741: 	$color{"yellow"}="#EEFFCC";
                    742: 	$color{"green"}="#DDFFDD";
                    743: 	$color{"purple"}="#FFDDFF";
                    744:     }
                    745: 
                    746:     return \%color;
                    747: }
                    748: 
1.1       stredwic  749: sub ProblemStatisticsButtons {
                    750:     my ($displayFormat)=@_;
                    751: 
                    752:     my $Ptr = '<tr><td></td><td align="left">';
                    753:     $Ptr .= '<input type="submit" name="DoDiffGraph" ';
                    754:     $Ptr .= 'value="DoDiff Graph" />'."\n";
                    755:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    756:     $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
                    757:     $Ptr .= 'value="%Wrong Graph" />'."\n";
                    758:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    759:     $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
                    760:     if($displayFormat eq 'Display CSV Format') {
1.9       stredwic  761:         $Ptr .= 'value="Display Table Format" />'."\n";
                    762:     } else {
1.1       stredwic  763:         $Ptr .= 'value="Display CSV Format" />'."\n";
                    764:     }
                    765:     $Ptr .= '</td></tr>';
                    766: 
                    767:     return $Ptr;
                    768: }
                    769: 
                    770: sub ProblemStatisticsLegend {
                    771:     my $Ptr = '';
                    772:     $Ptr = '<table border="0">';
                    773:     $Ptr .= '<tr><td>';
1.6       minaeibi  774:     $Ptr .= '<b>#Stdnts</b></td>';
1.1       stredwic  775:     $Ptr .= '<td>Total Number of Students opened the problem.';
                    776:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  777:     $Ptr .= '<b>Tries</b></td>';
1.1       stredwic  778:     $Ptr .= '<td>Total Number of Tries for solving the problem.';
                    779:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  780:     $Ptr .= '<b>Mod</b></td>';
1.1       stredwic  781:     $Ptr .= '<td>Maximunm Number of Tries for solving the problem.';
                    782:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  783:     $Ptr .= '<b>Mean</b></td>';
1.1       stredwic  784:     $Ptr .= '<td>Average Number of the tries. [ Tries / #Stdnts ]';
                    785:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  786:     $Ptr .= '<b>#YES</b></td>';
1.1       stredwic  787:     $Ptr .= '<td>Number of students solved the problem correctly.';
                    788:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  789:     $Ptr .= '<b>#yes</b></td>';
1.1       stredwic  790:     $Ptr .= '<td>Number of students solved the problem by override.';
                    791:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  792:     $Ptr .= '<b>%Wrng</b></td>';
1.1       stredwic  793:     $Ptr .= '<td>Percentage of students tried to solve the problem ';
                    794:     $Ptr .= 'but still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
                    795:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  796:     $Ptr .= '<b>DoDiff</b></td>';
1.1       stredwic  797:     $Ptr .= '<td>Degree of Difficulty of the problem.  ';
                    798:     $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
                    799:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  800:     $Ptr .= '<b>S.D.</b></td>';
1.1       stredwic  801:     $Ptr .= '<td>Standard Deviation of the tries.  ';
                    802:     $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
                    803:     $Ptr .= 'where Xi denotes every student\'s tries ]';
                    804:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  805:     $Ptr .= '<b>Skew.</b></td>';
1.1       stredwic  806:     $Ptr .= '<td>Skewness of the students tries.';
                    807:     $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
                    808:     $Ptr .= '</td></tr><tr><td>';
1.6       minaeibi  809:     $Ptr .= '<b>Dis.F.</b></td>';
1.1       stredwic  810:     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
                    811:     $Ptr .= 'problem according to a Criterion<br>';
                    812:     $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
                    813:     $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
                    814:     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
                    815:     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
                    816:     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
                    817:     $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
                    818:     $Ptr .= '</td></tr>';
                    819:     $Ptr .= '<tr><td><b>Disc.</b></td>';
                    820:     $Ptr .= '<td>Number of Students had at least one discussion.';
                    821:     $Ptr .= '</td></tr></table>';
                    822: 
                    823:     return $Ptr;
                    824: }
                    825: 
1.4       minaeibi  826: #------- Processing upperlist and lowerlist according to each problem
                    827: sub ProcessDiscriminant {
1.7       minaeibi  828:     my ($List,$r) = @_;
1.4       minaeibi  829:     my @sortedList = sort (@$List);
                    830:     my $Count = scalar @sortedList;
                    831:     my $Problem;
                    832:     my @Dis;
                    833:     my $Slvd=0;
                    834:     my $tmp;
                    835:     my $Sum1=0;
                    836:     my $Sum2=0;
                    837:     my $nIndex=0;
                    838:     my $nStudent=0;
                    839:     my %Proc=undef;
                    840:     while ($nIndex<$Count) {
1.7       minaeibi  841: #        $r->print("<br> $nIndex) $sortedList[$nIndex]");
1.4       minaeibi  842: 	($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
                    843: 	@Dis=split(/\+/,$tmp);
                    844: 	my $Temp = $Problem;
                    845: 	do {
                    846: 	    $nIndex++;
                    847: 	    $nStudent++;
                    848: 	    $Sum1 += $Dis[0];
                    849: 	    $Sum2 += $Dis[1];
                    850: 	    ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
                    851: 	    @Dis=split(/\+/,$tmp);
                    852: 	} while ( $Problem eq $Temp && $nIndex < $Count );
                    853: 	$Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
1.7       minaeibi  854: #        $r->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
1.4       minaeibi  855: 	$Sum1=0;
                    856: 	$Sum2=0;
                    857: 	$nStudent=0;
                    858:     }
                    859: 
                    860:     return %Proc;
                    861: }
                    862: 
                    863: #------- Creating Discimination factor   
                    864: sub Discriminant {
1.7       minaeibi  865:     my ($discriminant,$r)=@_;
                    866: #$Apache::lonxml::debug=1;
                    867: #&Apache::lonhomework::showhash(%$discriminant);
                    868: #$Apache::lonxml::debug=0;
                    869:     my @discriminantKeys=keys(%$discriminant);
1.4       minaeibi  870:     my $Count = scalar @discriminantKeys;
                    871: 
                    872:     my $UpCnt = int(0.27*$Count);
                    873:     my $low=0;
                    874:     my $up=$Count-$UpCnt;
                    875:     my @UpList=();
                    876:     my @LowList=();
                    877: 
                    878:     $Count=0;
                    879:     foreach my $key (sort(@discriminantKeys)) { 
                    880: 	$Count++;    
                    881: 	if($low < $UpCnt || $Count > $up) {
                    882:             $low++;
1.7       minaeibi  883:             my $str=$discriminant->{$key};
                    884:             foreach(split(/\&/,$str)){
1.4       minaeibi  885:                 if($_) {
                    886:                     if($low<$UpCnt) { push(@LowList,$_); }
                    887:                     else            { push(@UpList,$_);  }
                    888:                 }
                    889:             }
                    890:         }
                    891:     }
1.7       minaeibi  892:     my %DisUp =  &ProcessDiscriminant(\@UpList,$r);
                    893:     my %DisLow = &ProcessDiscriminant(\@LowList,$r);
1.4       minaeibi  894: 
                    895:     return (\%DisUp, \%DisLow);
1.8       minaeibi  896: }   
1.4       minaeibi  897: 
1.1       stredwic  898: #---- END Problem Statistics Web Page ----------------------------------------
                    899: 
                    900: #---- Problem Statistics Graph Web Page --------------------------------------
                    901: 
                    902: # ------------------------------------------- Prepare data for Graphical chart
                    903: 
1.4       minaeibi  904: sub BuildDiffGraph {
                    905:     my ($r)=@_;
                    906: 
                    907:     my $graphData = &GetGraphData('DiffGraph', $r);
1.9       stredwic  908:     $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />');
                    909: 
                    910:     return;
1.4       minaeibi  911: }
                    912: 
                    913: sub BuildWrongGraph {
                    914:     my ($r)=@_;
                    915: 
                    916:     my $graphData = &GetGraphData('WrongGraph', $r);
1.9       stredwic  917:     $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />');
                    918: 
                    919:     return;
1.4       minaeibi  920: }
                    921: 
                    922: 
1.1       stredwic  923: sub GetGraphData {
1.14      minaeibi  924:     my ($ylab,$r,$cache)=@_;
1.1       stredwic  925:     my $Col;
                    926:     my $data='';
                    927:     my $count = 0;
                    928:     my $Max = 0;
                    929:     my $cid=$ENV{'request.course.id'};
1.14      minaeibi  930: 
                    931:     if ( $ylab eq 'DoDiff Graph' ) {
                    932: 	$ylab = 'Degree-of-Difficulty';
                    933: 	$Col = 0;
                    934:     }
                    935:     else {
                    936: 	$ylab = 'Wrong-Percentage';
                    937: 	$Col = 1;
1.1       stredwic  938:     }
1.14      minaeibi  939: 
                    940:     my $p_count = $cache->{'ProblemCount'};
                    941: 
                    942:     for ( my $k=0; $k<$p_count;$k++) {
                    943:         my $key=$cache->{'CacheTable:'.$k};
                    944:         my @Temp=split(/\&/,$key);
                    945:        # $list[$k]=$key;
                    946:     }
                    947: 
                    948:   #  foreach (sort NumericSort keys %GraphDat) { 
                    949: 	#	my @Temp=split(/\:/,$GraphDat{$_});
                    950:         #        my $inf = $Temp[$Col]; 
                    951: 	#	if ( $Max < $inf ) {$Max = $inf;}
                    952: 	#	$data .= $inf.',';
                    953: 	#	$count++;
                    954:   # }
                    955:     if ( $Max > 1 ) { 
                    956: 	$Max += (10 - $Max % 10);
                    957:       	$Max = int($Max);
                    958:     } else { $Max = 1; }
                    959: 
                    960:     #untie(%GraphDat);
                    961: 
                    962:     my $Course = $ENV{'course.'.$cid.'.description'};
                    963:     $Course =~ s/\ /"_"/eg;
                    964:     my $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'.
                    965: 	      $Max.'&'.$count.'&'.$data;
1.1       stredwic  966: }
1.4       minaeibi  967: 
                    968: 
1.1       stredwic  969: 1;
                    970: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>