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