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