Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.17
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.17 ! albertel 4: # $Id: lonproblemstatistics.pm,v 1.16 2002/08/06 17:38:26 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+)/;
1.17 ! albertel 561: if ($StdNo) {
! 562: &Apache::lonnet::put('nohist_resevaldata',\%storestats,
! 563: $1,$2);
! 564: }
1.1 stredwic 565: #-------------------------------- Row of statistical table
1.12 minaeibi 566: &TableRow($cache,$join,$cIdx,($p_count-1),$r,$color,
567: \%TempCache);
1.1 stredwic 568: }
1.12 minaeibi 569: $TempCache{'ProblemCount'}=$p_count;
1.2 minaeibi 570: &CloseTable($cache,$r);
1.1 stredwic 571: }
1.5 minaeibi 572: ### &Close_PrgWin();
1.14 minaeibi 573: #6666666
1.1 stredwic 574: # close( OUT );
575: #666666
1.12 minaeibi 576: return \%TempCache;
1.1 stredwic 577: }
578:
1.12 minaeibi 579:
580: sub CacheStatisticsTable {
1.14 minaeibi 581: my ($state,$cache,$headings,$r,$color)=@_;
582: my @list = ();
1.12 minaeibi 583: my %TempCache;
1.14 minaeibi 584: my %myHeader = reverse( %$headings );
1.12 minaeibi 585: my $pos = $myHeader{$state};
586: if ($pos > 0) {$pos++;}
587: my $p_count = $cache->{'ProblemCount'};
588:
589: for ( my $k=0; $k<$p_count;$k++) {
590: my $key=$cache->{'CacheTable:'.$k};
591: my @Temp=split(/\&/,$key);
1.14 minaeibi 592: $list[$k]=$Temp[$pos].'+'.$key;
593: }
594:
595: if ($pos>0) {
1.15 minaeibi 596: @list = sort OrderedSort (@list);
1.14 minaeibi 597: } else {
598: @list = sort (@list);
1.1 stredwic 599: }
1.14 minaeibi 600: my $cIdx=0;
1.1 stredwic 601:
1.14 minaeibi 602: if ( $pos == 0 ) {
1.12 minaeibi 603: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
604: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' &&
605: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
606: next;
607: }
1.14 minaeibi 608: if ($cIdx==$p_count) {
609: return \%TempCache;
610: }
1.12 minaeibi 611: &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'},
612: $cache->{$sequence.':source'},
613: $cache->{$sequence.':title'},
614: $headings,$r);
615:
1.14 minaeibi 616: my ($tar)=split(/\&/,$list[$cIdx]);
617: $tar=~s/\+//eg;
618: my ($SqOrd)=split(/\@/,$tar);
1.12 minaeibi 619: $sequence+=100;
1.14 minaeibi 620: while ($SqOrd==$sequence && $cIdx<$p_count) {
621: my($Pre, $Post) = split(/\+/,$list[$cIdx]);
622: &TableRow($cache,$Post,$cIdx,$cIdx,$r,$color,\%TempCache);
623: $cIdx++;
624: my ($tar)=split(/\&/,$list[$cIdx]);
625: $tar=~s/\+//eg;
626: ($SqOrd)=split(/\@/,$tar);
1.1 stredwic 627: }
1.14 minaeibi 628: &CloseTable($cache,$r);
1.1 stredwic 629: }
630: }
631: else {
1.12 minaeibi 632: &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'},
1.14 minaeibi 633: 'Sorted by: ',
634: $headings->{$pos-1},
1.12 minaeibi 635: $headings,$r);
1.1 stredwic 636: for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
1.14 minaeibi 637: my($Pre, $Post) = split(/\+/,$list[$nIndex]);
638: &TableRow($cache,$Post,$nIndex,$nIndex,$r,$color,\%TempCache);
1.1 stredwic 639: }
1.14 minaeibi 640: &CloseTable($cache,$r);
1.1 stredwic 641: }
1.12 minaeibi 642:
643: return \%TempCache;
1.1 stredwic 644: }
1.12 minaeibi 645:
1.1 stredwic 646:
647: sub TableRow {
1.2 minaeibi 648: my ($cache,$Str,$Idx,$RealIdx,$r,$color,$GraphDat)=@_;
1.1 stredwic 649: my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
650: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);
1.8 minaeibi 651: my $Ptr;
1.9 stredwic 652: if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
1.1 stredwic 653: my ($ResId,$Dummy)=split(/\*/,$Prob);
1.8 minaeibi 654: $Ptr="\n".'<br>'.
655: "\n".'"'.($RealIdx+1).'",'.
1.10 stredwic 656: "\n".'"'.$cache->{$ResId.':title'}.$Dummy.'",'.
657: "\n".'"'.$cache->{$ResId.':source'}.'",'.
1.8 minaeibi 658: "\n".'"'.$StdNo.'",'.
659: "\n".'"'.$TotalTries.'",'.
660: "\n".'"'.$MxTries.'",'.
661: "\n".'"'.$Avg.'",'.
662: "\n".'"'.$YES.'",'.
663: "\n".'"'.$Override.'",'.
664: "\n".'"'.$Wrng.'",'.
665: "\n".'"'.$DoD.'",'.
666: "\n".'"'.$SD.'",'.
667: "\n".'"'.$Sk.'",'.
668: "\n".'"'.$_D1.'",'.
669: "\n".'"'.$_D2.'"'.
670: "\n".'"'.$DiscNo.'"';
1.1 stredwic 671:
672: $r->print("\n".$Ptr);
1.8 minaeibi 673: } else {
674: $Ptr="\n".'<tr>'.
675: "\n".'<td>'.($RealIdx+1).'</td>'.
676: "\n".'<td>'.$Temp.'</td>'.
677: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
678: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
679: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
680: "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
681: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
682: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
683: "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
684: "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
685: "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
686: "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
687: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
688: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
689: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
1.1 stredwic 690: $r->print("\n".$Ptr.'</tr>' );
691: }
1.14 minaeibi 692: $GraphDat->{'GraphGif:'.$RealIdx}=$DoD.':'.$Wrng;
1.1 stredwic 693: }
1.5 minaeibi 694:
695:
696: # For loading the colored table for display or un-colored for print
697: sub setbgcolor {
698: my $PrintTable=shift;
699: my %color;
700: if ($PrintTable){
701: $color{"gb"}="#FFFFFF";
702: $color{"red"}="#FFFFFF";
703: $color{"yellow"}="#FFFFFF";
704: $color{"green"}="#FFFFFF";
705: $color{"purple"}="#FFFFFF";
706: } else {
707: $color{"gb"}="#DDFFFF";
708: $color{"red"}="#FFDDDD";
709: $color{"yellow"}="#EEFFCC";
710: $color{"green"}="#DDFFDD";
711: $color{"purple"}="#FFDDFF";
712: }
713:
714: return \%color;
715: }
716:
1.1 stredwic 717: sub ProblemStatisticsButtons {
718: my ($displayFormat)=@_;
719:
720: my $Ptr = '<tr><td></td><td align="left">';
721: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
722: $Ptr .= 'value="DoDiff Graph" />'."\n";
723: $Ptr .= ' ';
724: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
725: $Ptr .= 'value="%Wrong Graph" />'."\n";
726: $Ptr .= ' ';
727: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
728: if($displayFormat eq 'Display CSV Format') {
1.9 stredwic 729: $Ptr .= 'value="Display Table Format" />'."\n";
730: } else {
1.1 stredwic 731: $Ptr .= 'value="Display CSV Format" />'."\n";
732: }
733: $Ptr .= '</td></tr>';
734:
735: return $Ptr;
736: }
737:
738: sub ProblemStatisticsLegend {
739: my $Ptr = '';
740: $Ptr = '<table border="0">';
741: $Ptr .= '<tr><td>';
1.6 minaeibi 742: $Ptr .= '<b>#Stdnts</b></td>';
1.1 stredwic 743: $Ptr .= '<td>Total Number of Students opened the problem.';
744: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 745: $Ptr .= '<b>Tries</b></td>';
1.1 stredwic 746: $Ptr .= '<td>Total Number of Tries for solving the problem.';
747: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 748: $Ptr .= '<b>Mod</b></td>';
1.1 stredwic 749: $Ptr .= '<td>Maximunm Number of Tries for solving the problem.';
750: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 751: $Ptr .= '<b>Mean</b></td>';
1.1 stredwic 752: $Ptr .= '<td>Average Number of the tries. [ Tries / #Stdnts ]';
753: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 754: $Ptr .= '<b>#YES</b></td>';
1.1 stredwic 755: $Ptr .= '<td>Number of students solved the problem correctly.';
756: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 757: $Ptr .= '<b>#yes</b></td>';
1.1 stredwic 758: $Ptr .= '<td>Number of students solved the problem by override.';
759: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 760: $Ptr .= '<b>%Wrng</b></td>';
1.1 stredwic 761: $Ptr .= '<td>Percentage of students tried to solve the problem ';
762: $Ptr .= 'but still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
763: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 764: $Ptr .= '<b>DoDiff</b></td>';
1.1 stredwic 765: $Ptr .= '<td>Degree of Difficulty of the problem. ';
766: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
767: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 768: $Ptr .= '<b>S.D.</b></td>';
1.1 stredwic 769: $Ptr .= '<td>Standard Deviation of the tries. ';
770: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
771: $Ptr .= 'where Xi denotes every student\'s tries ]';
772: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 773: $Ptr .= '<b>Skew.</b></td>';
1.1 stredwic 774: $Ptr .= '<td>Skewness of the students tries.';
775: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
776: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 777: $Ptr .= '<b>Dis.F.</b></td>';
1.1 stredwic 778: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
779: $Ptr .= 'problem according to a Criterion<br>';
780: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
781: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
782: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
783: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
784: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
785: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
786: $Ptr .= '</td></tr>';
787: $Ptr .= '<tr><td><b>Disc.</b></td>';
788: $Ptr .= '<td>Number of Students had at least one discussion.';
789: $Ptr .= '</td></tr></table>';
790:
791: return $Ptr;
792: }
793:
1.4 minaeibi 794: #------- Processing upperlist and lowerlist according to each problem
795: sub ProcessDiscriminant {
1.7 minaeibi 796: my ($List,$r) = @_;
1.4 minaeibi 797: my @sortedList = sort (@$List);
798: my $Count = scalar @sortedList;
799: my $Problem;
800: my @Dis;
801: my $Slvd=0;
802: my $tmp;
803: my $Sum1=0;
804: my $Sum2=0;
805: my $nIndex=0;
806: my $nStudent=0;
807: my %Proc=undef;
808: while ($nIndex<$Count) {
1.7 minaeibi 809: # $r->print("<br> $nIndex) $sortedList[$nIndex]");
1.4 minaeibi 810: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
811: @Dis=split(/\+/,$tmp);
812: my $Temp = $Problem;
813: do {
814: $nIndex++;
815: $nStudent++;
816: $Sum1 += $Dis[0];
817: $Sum2 += $Dis[1];
818: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
819: @Dis=split(/\+/,$tmp);
820: } while ( $Problem eq $Temp && $nIndex < $Count );
821: $Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
1.7 minaeibi 822: # $r->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
1.4 minaeibi 823: $Sum1=0;
824: $Sum2=0;
825: $nStudent=0;
826: }
827:
828: return %Proc;
829: }
830:
831: #------- Creating Discimination factor
832: sub Discriminant {
1.7 minaeibi 833: my ($discriminant,$r)=@_;
834: my @discriminantKeys=keys(%$discriminant);
1.4 minaeibi 835: my $Count = scalar @discriminantKeys;
836:
837: my $UpCnt = int(0.27*$Count);
838: my $low=0;
839: my $up=$Count-$UpCnt;
840: my @UpList=();
841: my @LowList=();
842:
843: $Count=0;
844: foreach my $key (sort(@discriminantKeys)) {
845: $Count++;
846: if($low < $UpCnt || $Count > $up) {
847: $low++;
1.7 minaeibi 848: my $str=$discriminant->{$key};
849: foreach(split(/\&/,$str)){
1.4 minaeibi 850: if($_) {
851: if($low<$UpCnt) { push(@LowList,$_); }
852: else { push(@UpList,$_); }
853: }
854: }
855: }
856: }
1.7 minaeibi 857: my %DisUp = &ProcessDiscriminant(\@UpList,$r);
858: my %DisLow = &ProcessDiscriminant(\@LowList,$r);
1.4 minaeibi 859:
860: return (\%DisUp, \%DisLow);
1.8 minaeibi 861: }
1.4 minaeibi 862:
1.1 stredwic 863: #---- END Problem Statistics Web Page ----------------------------------------
864:
865: #---- Problem Statistics Graph Web Page --------------------------------------
866:
867: # ------------------------------------------- Prepare data for Graphical chart
868:
1.16 minaeibi 869: sub BuildGraphicChart {
870: my ($ylab,$r,$cacheDB)=@_;
871: my %cache;
1.1 stredwic 872: my $Col;
873: my $data='';
874: my $count = 0;
875: my $Max = 0;
1.14 minaeibi 876:
1.16 minaeibi 877: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
878: return '<html><body>Unable to tie database.</body></html>';
1.1 stredwic 879: }
1.16 minaeibi 880:
881: my $p_count = $cache{'ProblemCount'};
1.14 minaeibi 882:
883: for ( my $k=0; $k<$p_count;$k++) {
1.16 minaeibi 884: my @Temp=split(/\:/,$cache{'GraphGif:'.$k});
885: my $inf = $Temp[$Col];
886: if ( $Max < $inf ) {$Max = $inf;}
887: $data .= $inf.',';
888: $count++;
1.14 minaeibi 889: }
1.16 minaeibi 890: untie(%cache);
891: # $r->print("<br>count=$p_count >>data= $data");
1.14 minaeibi 892:
893: if ( $Max > 1 ) {
894: $Max += (10 - $Max % 10);
895: $Max = int($Max);
896: } else { $Max = 1; }
897:
1.16 minaeibi 898: my $cid=$ENV{'request.course.id'};
1.14 minaeibi 899:
1.16 minaeibi 900: if ( $ylab eq 'DoDiff Graph' ) {
901: $ylab = 'Degree-of-Difficulty';
902: $Col = 0;
903: } else {
904: $ylab = 'Wrong-Percentage';
905: $Col = 1;
906: }
1.14 minaeibi 907: my $Course = $ENV{'course.'.$cid.'.description'};
908: $Course =~ s/\ /"_"/eg;
1.16 minaeibi 909: my $GData=$Course.'&'.'Problems#'.'&'.$ylab.'&'.
1.14 minaeibi 910: $Max.'&'.$count.'&'.$data;
1.16 minaeibi 911:
912: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
913:
914: return;
1.1 stredwic 915: }
1.4 minaeibi 916:
1.1 stredwic 917: 1;
918: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>