Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.9
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.9 ! stredwic 4: # $Id: lonproblemstatistics.pm,v 1.8 2002/07/30 23:08:56 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">';
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:
453: # $res = '<a href="'.$cache->{'src_'.$ResId}.'">'.$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.2 minaeibi 518: ##8888 $CachData{($p_count-1)}=$join;
1.1 stredwic 519:
520: #6666666
521: # $r->print('<br>'.$out.'&'.$DoD);
522: # print (OUT $out.'@'.$DoD.'&');
523: #6666666
524:
525: $urlres=~/^(\w+)\/(\w+)/;
526: if ($StdNo) {
527: &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);
528: }
529: #-------------------------------- Row of statistical table
1.5 minaeibi 530: &TableRow($cache,$join,$cIdx,($p_count-1),$r,$color,\%GraphDat);
1.1 stredwic 531: }
1.2 minaeibi 532: &CloseTable($cache,$r);
1.1 stredwic 533: }
1.5 minaeibi 534: ### &Close_PrgWin();
1.1 stredwic 535: #666666
536: # close( OUT );
537: #666666
538: }
539:
540: =pod
541: sub Cache_Statistics {
1.2 minaeibi 542: my ($cache,$color)=@_;
1.1 stredwic 543: my @list = ();
544: my $Useful;
545: my $UnUseful;
546: # $r->print('<input type="hidden" name="show" value="excel" />'."\n");
547: my %myHeader = reverse( %Header );
548: $Pos = $myHeader{$ENV{'form.sort'}};
549: if ($Pos > 0) {$Pos++;}
550: my $p_count = 0;
551: foreach my $key( keys %CachData) {
552: my @Temp=split(/\&/,$CachData{$key});
553: if ( $Pos == 0 ) {
554: ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
555: }
556: else {
557: $Useful = $Temp[$Pos];
558: }
559: $list[$p_count]=$Useful.'@'.$CachData{$key};
560: $p_count++;
561: }
562:
563: @list = sort MySort (@list);
564:
565: my $nIndex=0;
566:
567: if ( $Pos == 0 ) {
568: foreach (sort keys %mapsort) {
569: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
570: &CreateProblemStatisticsTableHeading($cache,1,$Hid);
571: my @lpr=split(/\&/,$pr);
572: for (my $i=1; $i<=$#lpr; $i++) {
573: my($Pre, $Post) = split(/\@/,$list[$nIndex]);
574: #$r->print('<br>'.$Pre.'---'.$Post);
1.5 minaeibi 575: &TableRow($cache,$Post,$i,$nIndex,$color,\%GraphDat);
1.1 stredwic 576: $nIndex++;
577: }
578: &CloseTable($cache);
579: }
580: }
581: else {
582: &CreateProblemStatisticsTableHeading($cache,0);
583: for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
584: my($Pre, $Post) = split(/\@/,$list[$nIndex]);
1.5 minaeibi 585: &TableRow($cache,$Post,$nIndex,$nIndex,$color,\%GraphDat);
1.1 stredwic 586: }
587: &CloseTable($cache);
588: }
589: }
590: =cut
591:
592: sub TableRow {
1.2 minaeibi 593: my ($cache,$Str,$Idx,$RealIdx,$r,$color,$GraphDat)=@_;
1.1 stredwic 594: my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
595: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);
1.5 minaeibi 596: # $r->print('<br>'.$Str);
1.8 minaeibi 597: my $Ptr;
1.9 ! stredwic 598: if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
1.1 stredwic 599: my ($ResId,$Dummy)=split(/\*/,$Prob);
1.8 minaeibi 600: $Ptr="\n".'<br>'.
601: "\n".'"'.($RealIdx+1).'",'.
602: "\n".'"'.$cache->{'title_'.$ResId}.$Dummy.'",'.
603: "\n".'"'.$cache->{'src_'.$ResId}.'",'.
604: "\n".'"'.$StdNo.'",'.
605: "\n".'"'.$TotalTries.'",'.
606: "\n".'"'.$MxTries.'",'.
607: "\n".'"'.$Avg.'",'.
608: "\n".'"'.$YES.'",'.
609: "\n".'"'.$Override.'",'.
610: "\n".'"'.$Wrng.'",'.
611: "\n".'"'.$DoD.'",'.
612: "\n".'"'.$SD.'",'.
613: "\n".'"'.$Sk.'",'.
614: "\n".'"'.$_D1.'",'.
615: "\n".'"'.$_D2.'"'.
616: "\n".'"'.$DiscNo.'"';
1.1 stredwic 617:
618: $r->print("\n".$Ptr);
1.8 minaeibi 619: } else {
620: $Ptr="\n".'<tr>'.
621: "\n".'<td>'.($RealIdx+1).'</td>'.
622: # "\n".'<td>'.$PrOrd.$Temp.'</td>'.
623: "\n".'<td>'.$Temp.'</td>'.
624: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
625: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
626: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
627: "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
628: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
629: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
630: "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
631: "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
632: "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
633: "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
634: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
635: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
636: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
1.1 stredwic 637: $r->print("\n".$Ptr.'</tr>' );
638: }
1.5 minaeibi 639: # $GraphDat->{$RealIdx}=$DoD.':'.$Wrng;
1.1 stredwic 640: }
1.5 minaeibi 641:
642:
643: # For loading the colored table for display or un-colored for print
644: sub setbgcolor {
645: my $PrintTable=shift;
646: my %color;
647: if ($PrintTable){
648: $color{"gb"}="#FFFFFF";
649: $color{"red"}="#FFFFFF";
650: $color{"yellow"}="#FFFFFF";
651: $color{"green"}="#FFFFFF";
652: $color{"purple"}="#FFFFFF";
653: } else {
654: $color{"gb"}="#DDFFFF";
655: $color{"red"}="#FFDDDD";
656: $color{"yellow"}="#EEFFCC";
657: $color{"green"}="#DDFFDD";
658: $color{"purple"}="#FFDDFF";
659: }
660:
661: return \%color;
662: }
663:
1.1 stredwic 664: sub ProblemStatisticsButtons {
665: my ($displayFormat)=@_;
666:
667: my $Ptr = '<tr><td></td><td align="left">';
668: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
669: $Ptr .= 'value="DoDiff Graph" />'."\n";
670: $Ptr .= ' ';
671: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
672: $Ptr .= 'value="%Wrong Graph" />'."\n";
673: $Ptr .= ' ';
674: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
675: if($displayFormat eq 'Display CSV Format') {
1.9 ! stredwic 676: $Ptr .= 'value="Display Table Format" />'."\n";
! 677: } else {
1.1 stredwic 678: $Ptr .= 'value="Display CSV Format" />'."\n";
679: }
680: $Ptr .= '</td></tr>';
681:
682: return $Ptr;
683: }
684:
685: sub ProblemStatisticsLegend {
686: my $Ptr = '';
687: $Ptr = '<table border="0">';
688: $Ptr .= '<tr><td>';
1.6 minaeibi 689: $Ptr .= '<b>#Stdnts</b></td>';
1.1 stredwic 690: $Ptr .= '<td>Total Number of Students opened the problem.';
691: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 692: $Ptr .= '<b>Tries</b></td>';
1.1 stredwic 693: $Ptr .= '<td>Total Number of Tries for solving the problem.';
694: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 695: $Ptr .= '<b>Mod</b></td>';
1.1 stredwic 696: $Ptr .= '<td>Maximunm Number of Tries for solving the problem.';
697: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 698: $Ptr .= '<b>Mean</b></td>';
1.1 stredwic 699: $Ptr .= '<td>Average Number of the tries. [ Tries / #Stdnts ]';
700: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 701: $Ptr .= '<b>#YES</b></td>';
1.1 stredwic 702: $Ptr .= '<td>Number of students solved the problem correctly.';
703: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 704: $Ptr .= '<b>#yes</b></td>';
1.1 stredwic 705: $Ptr .= '<td>Number of students solved the problem by override.';
706: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 707: $Ptr .= '<b>%Wrng</b></td>';
1.1 stredwic 708: $Ptr .= '<td>Percentage of students tried to solve the problem ';
709: $Ptr .= 'but still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
710: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 711: $Ptr .= '<b>DoDiff</b></td>';
1.1 stredwic 712: $Ptr .= '<td>Degree of Difficulty of the problem. ';
713: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
714: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 715: $Ptr .= '<b>S.D.</b></td>';
1.1 stredwic 716: $Ptr .= '<td>Standard Deviation of the tries. ';
717: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
718: $Ptr .= 'where Xi denotes every student\'s tries ]';
719: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 720: $Ptr .= '<b>Skew.</b></td>';
1.1 stredwic 721: $Ptr .= '<td>Skewness of the students tries.';
722: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
723: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 724: $Ptr .= '<b>Dis.F.</b></td>';
1.1 stredwic 725: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
726: $Ptr .= 'problem according to a Criterion<br>';
727: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
728: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
729: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
730: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
731: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
732: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
733: $Ptr .= '</td></tr>';
734: $Ptr .= '<tr><td><b>Disc.</b></td>';
735: $Ptr .= '<td>Number of Students had at least one discussion.';
736: $Ptr .= '</td></tr></table>';
737:
738: return $Ptr;
739: }
740:
1.4 minaeibi 741: #------- Processing upperlist and lowerlist according to each problem
742: sub ProcessDiscriminant {
1.7 minaeibi 743: my ($List,$r) = @_;
1.4 minaeibi 744: my @sortedList = sort (@$List);
745: my $Count = scalar @sortedList;
746: my $Problem;
747: my @Dis;
748: my $Slvd=0;
749: my $tmp;
750: my $Sum1=0;
751: my $Sum2=0;
752: my $nIndex=0;
753: my $nStudent=0;
754: my %Proc=undef;
755: while ($nIndex<$Count) {
1.7 minaeibi 756: # $r->print("<br> $nIndex) $sortedList[$nIndex]");
1.4 minaeibi 757: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
758: @Dis=split(/\+/,$tmp);
759: my $Temp = $Problem;
760: do {
761: $nIndex++;
762: $nStudent++;
763: $Sum1 += $Dis[0];
764: $Sum2 += $Dis[1];
765: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
766: @Dis=split(/\+/,$tmp);
767: } while ( $Problem eq $Temp && $nIndex < $Count );
768: $Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
1.7 minaeibi 769: # $r->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
1.4 minaeibi 770: $Sum1=0;
771: $Sum2=0;
772: $nStudent=0;
773: }
774:
775: return %Proc;
776: }
777:
778: #------- Creating Discimination factor
779: sub Discriminant {
1.7 minaeibi 780: my ($discriminant,$r)=@_;
781: #$Apache::lonxml::debug=1;
782: #&Apache::lonhomework::showhash(%$discriminant);
783: #$Apache::lonxml::debug=0;
784: my @discriminantKeys=keys(%$discriminant);
1.4 minaeibi 785: my $Count = scalar @discriminantKeys;
786:
787: my $UpCnt = int(0.27*$Count);
788: my $low=0;
789: my $up=$Count-$UpCnt;
790: my @UpList=();
791: my @LowList=();
792:
793: $Count=0;
794: foreach my $key (sort(@discriminantKeys)) {
795: $Count++;
796: if($low < $UpCnt || $Count > $up) {
797: $low++;
1.7 minaeibi 798: my $str=$discriminant->{$key};
799: foreach(split(/\&/,$str)){
1.4 minaeibi 800: if($_) {
801: if($low<$UpCnt) { push(@LowList,$_); }
802: else { push(@UpList,$_); }
803: }
804: }
805: }
806: }
1.7 minaeibi 807: my %DisUp = &ProcessDiscriminant(\@UpList,$r);
808: my %DisLow = &ProcessDiscriminant(\@LowList,$r);
1.4 minaeibi 809:
810: return (\%DisUp, \%DisLow);
1.8 minaeibi 811: }
1.4 minaeibi 812:
1.1 stredwic 813: #---- END Problem Statistics Web Page ----------------------------------------
814:
815: #---- Problem Statistics Graph Web Page --------------------------------------
816:
817: # ------------------------------------------- Prepare data for Graphical chart
818:
1.4 minaeibi 819: sub BuildDiffGraph {
820: my ($r)=@_;
821:
822: my $graphData = &GetGraphData('DiffGraph', $r);
1.9 ! stredwic 823: $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />');
! 824:
! 825: return;
1.4 minaeibi 826: }
827:
828: sub BuildWrongGraph {
829: my ($r)=@_;
830:
831: my $graphData = &GetGraphData('WrongGraph', $r);
1.9 ! stredwic 832: $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />');
! 833:
! 834: return;
1.4 minaeibi 835: }
836:
837:
1.1 stredwic 838: sub GetGraphData {
1.2 minaeibi 839: my ($ylab,$r,%GraphDat)=@_;
1.1 stredwic 840: my $Col;
841: my $data='';
842: my $count = 0;
843: my $Max = 0;
844: my $cid=$ENV{'request.course.id'};
845: my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
846: "_$ENV{'user.domain'}_$cid\_graph.db";
847: foreach (keys %GraphDat) {delete $GraphDat{$_};}
848: if (-e "$GraphDB") {
849: if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
850: if ( $ylab eq 'DoDiff Graph' ) {
851: $ylab = 'Degree-of-Difficulty';
852: $Col = 0;
853: }
854: else {
855: $ylab = 'Wrong-Percentage';
856: $Col = 1;
857: }
858: foreach (sort NumericSort keys %GraphDat) {
859: my @Temp=split(/\:/,$GraphDat{$_});
860: my $inf = $Temp[$Col];
861: if ( $Max < $inf ) {$Max = $inf;}
862: $data .= $inf.',';
863: $count++;
864: }
865: if ( $Max > 1 ) {
866: $Max += (10 - $Max % 10);
867: $Max = int($Max);
868: }
869: else { $Max = 1; }
870: untie(%GraphDat);
871: my $Course = $ENV{'course.'.$cid.'.description'};
872: $Course =~ s/\ /"_"/eg;
1.3 minaeibi 873: my $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'.
874: $Max.'&'.$count.'&'.$data;
1.1 stredwic 875: }
876: else {
877: $r->print("Unable to tie hash to db file");
878: }
879: }
880: }
1.4 minaeibi 881:
882:
1.1 stredwic 883: 1;
884: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>