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