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