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