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