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