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