Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.21
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.21 ! stredwic 4: # $Id: lonproblemstatistics.pm,v 1.20 2002/08/13 12:21:46 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.12 minaeibi 34: # 5/12,5/14,5/15,5/19,5/26,7/16,7/25,7/29,8/5 Behrouz Minaei
1.1 stredwic 35: #
36: ###
37:
38: package Apache::lonproblemstatistics;
39:
40: use strict;
41: use Apache::lonnet();
42: use Apache::lonhtmlcommon;
43: use Apache::loncoursedata;
44: use GDBM_File;
45:
1.19 stredwic 46: my $jr;
1.1 stredwic 47:
48: sub BuildProblemStatisticsPage {
1.5 minaeibi 49: my ($cacheDB, $students, $courseID, $c, $r)=@_;
1.1 stredwic 50: my %cache;
1.16 minaeibi 51:
1.19 stredwic 52: $jr = $r;
53:
1.18 albertel 54: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.21 ! stredwic 55: $r->print('Unable to tie database.');
! 56: return;
1.1 stredwic 57: }
58:
59: my $Ptr = '';
60: $Ptr .= '<table border="0"><tbody>';
61: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
62: $Ptr .= '<td align="left">';
1.9 stredwic 63: $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
64: 'Statistics');
65: $Ptr .= '</td></tr>'."\n";
66: $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
67: $Ptr .= '<td align="left">'."\n";
68: $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
69: $cache{'ProblemStatisticsAscend'},
70: 'ProblemStatistics',
71: 'Statistics');
1.1 stredwic 72: $Ptr .= '</td></tr>'."\n";
1.20 stredwic 73: $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
74: $cache{'DisplayLegend'});
1.2 minaeibi 75: $Ptr .= '</table>';
1.20 stredwic 76: if($cache{'DisplayLegend'} eq 'Show Legend') {
77: $Ptr .= &ProblemStatisticsLegend();
78: }
1.5 minaeibi 79: $r->print($Ptr);
1.13 stredwic 80: $r->rflush();
1.1 stredwic 81:
1.19 stredwic 82: my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
83: "Mean","#YES","#yes","%Wrng","DoDiff",
84: "S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");
1.5 minaeibi 85: my $color=&setbgcolor(0);
1.12 minaeibi 86:
1.19 stredwic 87: # my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
88: # my ($upper, $lower) = &Discriminant(\%discriminant,$r);
1.21 ! stredwic 89: if(!defined($cache{'StatisticsCached'})) {
! 90: untie(%cache);
! 91: &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
! 92: 'true',
! 93: $cacheDB,
! 94: 'true',
! 95: 'true',
! 96: $courseID,
! 97: $r, $c);
! 98: if($c->aborted()) { return; }
! 99:
! 100: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
! 101: $r->print('Unable to tie database.');
! 102: return;
! 103: }
! 104: my ($problemData) = &ExtractStudentData(\%cache, $students);
! 105: &CalculateStatistics($problemData);
! 106: untie(%cache);
! 107:
! 108: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
! 109: $r->print('Unable to tie database.');
! 110: return;
! 111: }
! 112: foreach(keys(%$problemData)) {
! 113: $cache{$_} = $problemData->{$_};
! 114: }
! 115: $cache{'StatisticsCached'} = 'true';
! 116: untie(%cache);
! 117:
! 118: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
! 119: $r->print('Unable to tie database.');
! 120: return;
! 121: }
! 122: }
! 123: my $orderedProblems = &SortProblems(\%cache,
! 124: $cache{'ProblemStatisticsSort'},
! 125: $cache{'ProblemStatisticsAscend'});
! 126: &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, $orderedProblems,
! 127: \@Header, $r, $color);
1.19 stredwic 128: untie(%cache);
1.12 minaeibi 129:
1.19 stredwic 130: return;
1.1 stredwic 131: }
132:
133:
134: #---- Problem Statistics Web Page ---------------------------------------
135:
136: sub CreateProblemStatisticsTableHeading {
1.19 stredwic 137: my ($headings,$r)=@_;
1.3 minaeibi 138:
1.19 stredwic 139: my $Str='';
140: $Str .= '<tr>'."\n";
141: $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
142: foreach(@$headings) {
143: $Str .= '<th bgcolor="#ffffe6">'.'<a href="/adm/statistics?reportSelected=';
144: $Str .= &Apache::lonnet::escape('Problem Statistics');
145: $Str .= '&ProblemStatisticsSort=';
146: $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a> </th>'."\n";
1.1 stredwic 147: }
1.19 stredwic 148: $Str .= "\n".'</tr>'."\n";
1.1 stredwic 149:
1.19 stredwic 150: return $Str;
1.1 stredwic 151: }
1.12 minaeibi 152:
1.1 stredwic 153: sub BuildStatisticsTable {
1.21 ! stredwic 154: my ($cache,$displayFormat,$orderedProblems,$headings,$r,$color)=@_;
1.5 minaeibi 155:
1.1 stredwic 156: #6666666
157: # my $file="/home/httpd/perl/tmp/183d.txt";
158: # open(OUT, ">$file");
159: #6666666
1.2 minaeibi 160: ## &Apache::lonstatistics::Create_PrgWin($r);
1.1 stredwic 161: ##777777
162: ## my (%Activity) = &LoadActivityLog();
163: ## $r->print('<script>popwin.document.popremain.remaining.value="'.
164: ## 'Loading Discussion...";</script>');
165: ## my ($doDiffFile) = &LoadDoDiffFile();
166:
1.5 minaeibi 167: ##777777
168: ## $Str .= &Classify($discriminantFactor, $students);
169:
1.21 ! stredwic 170: if($displayFormat ne 'Display CSV Format') {
1.19 stredwic 171: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
172: $r->print('<table border="0" cellpadding="3">'."\n");
173: $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
174: } else {
175: $r->print('<br>');
176: }
1.1 stredwic 177:
1.19 stredwic 178: my $count = 1;
1.21 ! stredwic 179: foreach(@$orderedProblems) {
1.19 stredwic 180: my ($sequence,$problem,$part)=split(':', $_);
1.21 ! stredwic 181: # if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' &&
! 182: # $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
! 183: # next;
! 184: # }
! 185:
1.19 stredwic 186:
1.21 ! stredwic 187: my $ref = '<a href="'.$cache->{$problem.':source'}.
! 188: '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
! 189: # my $ref = $cache->{$problem.':title'};
1.19 stredwic 190: my $title = $cache->{$problem.':title'};
191: my $source = 'source';
192: my $tableData = join('&', $ref, $title, $source,
1.21 ! stredwic 193: $cache->{$_.':studentCount'},
! 194: $cache->{$_.':totalTries'},
! 195: $cache->{$_.':maxTries'},
! 196: sprintf("%.2f", $cache->{$_.':mean'}),
! 197: $cache->{$_.':correct'},
! 198: $cache->{$_.':correctByOverride'},
! 199: sprintf("%.1f", $cache->{$_.':percentWrong'}),
! 200: sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}),
! 201: sprintf("%.1f", $cache->{$_.':standardDeviation'}),
! 202: sprintf("%.1f", $cache->{$_.':skewness'}),
! 203: sprintf("%.2f", $cache->{$_.':discriminationFactor1'}),
! 204: sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),
! 205: 0); # 0 is for discussion, need to figure out
1.1 stredwic 206:
207: #6666666
208: # $r->print('<br>'.$out.'&'.$DoD);
209: # print (OUT $out.'@'.$DoD.'&');
210: #6666666
211:
1.16 minaeibi 212: #check with Gerd
1.19 stredwic 213: # $urlres=~/^(\w+)\/(\w+)/;
214: # if ($StdNo) {
215: # &Apache::lonnet::put('nohist_resevaldata',\%storestats,
216: # $1,$2);
217: # }
1.1 stredwic 218: #-------------------------------- Row of statistical table
1.19 stredwic 219: &TableRow($displayFormat,$tableData,$count,$r,$color);
220: $count++;
221: }
222: if($cache->{'DisplayFormat'} ne 'Display CSV Format') {
223: $r->print('</table>'."\n");
1.1 stredwic 224: }
1.19 stredwic 225: $r->print('</td></tr></table>');
1.14 minaeibi 226: #6666666
1.1 stredwic 227: # close( OUT );
228: #666666
1.21 ! stredwic 229: return;
1.1 stredwic 230: }
231:
232: sub TableRow {
1.19 stredwic 233: my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
234: my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
1.1 stredwic 235: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);
1.8 minaeibi 236: my $Ptr;
1.19 stredwic 237: if($displayFormat eq 'Display CSV Format') {
1.8 minaeibi 238: $Ptr="\n".'<br>'.
1.19 stredwic 239: "\n".'"'.$RealIdx.'",'.
240: "\n".'"'.$title.'",'.
241: "\n".'"'.$source.'",'.
1.8 minaeibi 242: "\n".'"'.$StdNo.'",'.
243: "\n".'"'.$TotalTries.'",'.
244: "\n".'"'.$MxTries.'",'.
245: "\n".'"'.$Avg.'",'.
246: "\n".'"'.$YES.'",'.
247: "\n".'"'.$Override.'",'.
248: "\n".'"'.$Wrng.'",'.
249: "\n".'"'.$DoD.'",'.
250: "\n".'"'.$SD.'",'.
251: "\n".'"'.$Sk.'",'.
252: "\n".'"'.$_D1.'",'.
253: "\n".'"'.$_D2.'"'.
254: "\n".'"'.$DiscNo.'"';
1.1 stredwic 255:
256: $r->print("\n".$Ptr);
1.8 minaeibi 257: } else {
258: $Ptr="\n".'<tr>'.
1.19 stredwic 259: "\n".'<td bgcolor="#ffffe6">'.$RealIdx.'</td>'.
260: "\n".'<td bgcolor="#ffffe6">'.$ref.'</td>'.
1.8 minaeibi 261: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
262: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
263: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
264: "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
265: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
266: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
267: "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
268: "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
269: "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
270: "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
271: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
272: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
273: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
1.1 stredwic 274: $r->print("\n".$Ptr.'</tr>' );
275: }
1.19 stredwic 276:
277: return;
1.1 stredwic 278: }
1.5 minaeibi 279:
280: # For loading the colored table for display or un-colored for print
281: sub setbgcolor {
282: my $PrintTable=shift;
283: my %color;
284: if ($PrintTable){
285: $color{"gb"}="#FFFFFF";
286: $color{"red"}="#FFFFFF";
287: $color{"yellow"}="#FFFFFF";
288: $color{"green"}="#FFFFFF";
289: $color{"purple"}="#FFFFFF";
290: } else {
291: $color{"gb"}="#DDFFFF";
292: $color{"red"}="#FFDDDD";
293: $color{"yellow"}="#EEFFCC";
294: $color{"green"}="#DDFFDD";
295: $color{"purple"}="#FFDDFF";
296: }
297:
298: return \%color;
299: }
300:
1.1 stredwic 301: sub ProblemStatisticsButtons {
1.20 stredwic 302: my ($displayFormat, $displayLegend)=@_;
1.1 stredwic 303:
304: my $Ptr = '<tr><td></td><td align="left">';
305: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
306: $Ptr .= 'value="DoDiff Graph" />'."\n";
307: $Ptr .= ' ';
308: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
309: $Ptr .= 'value="%Wrong Graph" />'."\n";
1.20 stredwic 310: $Ptr .= '</td></tr><tr><td></td><td>'."\n";
311: $Ptr .= '<input type="submit" name="DisplayLegend" ';
312: if($displayLegend eq 'Show Legend') {
313: $Ptr .= 'value="Hide Legend" />'."\n";
314: } else {
315: $Ptr .= 'value="Show Legend" />'."\n";
316: }
1.1 stredwic 317: $Ptr .= ' ';
318: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
319: if($displayFormat eq 'Display CSV Format') {
1.9 stredwic 320: $Ptr .= 'value="Display Table Format" />'."\n";
321: } else {
1.1 stredwic 322: $Ptr .= 'value="Display CSV Format" />'."\n";
323: }
324: $Ptr .= '</td></tr>';
325:
326: return $Ptr;
327: }
328:
329: sub ProblemStatisticsLegend {
330: my $Ptr = '';
331: $Ptr = '<table border="0">';
332: $Ptr .= '<tr><td>';
1.6 minaeibi 333: $Ptr .= '<b>#Stdnts</b></td>';
1.19 stredwic 334: $Ptr .= '<td>Total number of students attempted the problem.';
1.1 stredwic 335: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 336: $Ptr .= '<b>Tries</b></td>';
1.19 stredwic 337: $Ptr .= '<td>Total number of tries for solving the problem.';
1.1 stredwic 338: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 339: $Ptr .= '<b>Mod</b></td>';
1.19 stredwic 340: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
1.1 stredwic 341: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 342: $Ptr .= '<b>Mean</b></td>';
1.19 stredwic 343: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
1.1 stredwic 344: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 345: $Ptr .= '<b>#YES</b></td>';
1.1 stredwic 346: $Ptr .= '<td>Number of students solved the problem correctly.';
347: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 348: $Ptr .= '<b>#yes</b></td>';
1.1 stredwic 349: $Ptr .= '<td>Number of students solved the problem by override.';
350: $Ptr .= '</td></tr><tr><td>';
1.19 stredwic 351: $Ptr .= '<b>%Wrong</b></td>';
352: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
353: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
1.1 stredwic 354: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 355: $Ptr .= '<b>DoDiff</b></td>';
1.1 stredwic 356: $Ptr .= '<td>Degree of Difficulty of the problem. ';
357: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
358: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 359: $Ptr .= '<b>S.D.</b></td>';
1.1 stredwic 360: $Ptr .= '<td>Standard Deviation of the tries. ';
361: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
362: $Ptr .= 'where Xi denotes every student\'s tries ]';
363: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 364: $Ptr .= '<b>Skew.</b></td>';
1.1 stredwic 365: $Ptr .= '<td>Skewness of the students tries.';
366: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
367: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 368: $Ptr .= '<b>Dis.F.</b></td>';
1.1 stredwic 369: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
370: $Ptr .= 'problem according to a Criterion<br>';
371: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
372: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
373: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
374: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
375: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
376: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
377: $Ptr .= '</td></tr>';
378: $Ptr .= '<tr><td><b>Disc.</b></td>';
379: $Ptr .= '<td>Number of Students had at least one discussion.';
380: $Ptr .= '</td></tr></table>';
381:
382: return $Ptr;
383: }
384:
1.4 minaeibi 385: #------- Processing upperlist and lowerlist according to each problem
1.19 stredwic 386:
387: sub ExtractStudentData {
388: my ($cache, $students)=@_;
389:
390: #$Apache::lonxml::debug=1;
391: #&Apache::lonhomework::showhash(%$cache);
392: #$Apache::lonxml::debug=0;
393:
394: my @problemList=();
395: my %problemData;
396: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
397: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
398: foreach my $part (split(/\:/,$cache->{$sequence.':'.
399: $problemID.
400: ':parts'})) {
401: my $id = $sequence.':'.$problemID.':'.$part;
402: push(@problemList, $id);
403: my $totalTries = 0;
404: my $totalAwarded = 0;
405: my $correct = 0;
406: my $correctByOverride = 0;
407: my $studentCount = 0;
408: my $maxTries = 0;
409: my $totalFirst = 0;
410: my @studentTries=();
411: foreach(@$students) {
412: my $code = $cache->{"$_:$problemID:$part:code"};
413:
414: if(defined($cache->{$_.':error'}) || $code eq ' ' ||
415: $cache->{"$_:$problemID:NoVersion"} eq 'true') {
416: next;
417: }
418:
419: $studentCount++;
420: my $tries = $cache->{"$_:$problemID:$part:tries"};
421: if($maxTries < $tries) {
422: $maxTries = $tries;
423: }
424: $totalTries += $tries;
425: push(@studentTries, $tries);
426:
427: my $awarded = $cache->{"$_:$problemID:$part:awarded"};
428: $totalAwarded += $awarded;
429:
430: if($code eq '*') {
431: $correct++;
432: if($tries == 1) {
433: $totalFirst++;
434: }
435: } elsif($code eq '+') {
436: $correctByOverride++;
437: }
438: }
439:
440: $problemData{$id.':sequenceTitle'} =
441: $cache->{$sequence.':title'};
442: $problemData{$id.':studentCount'} = $studentCount;
443: $problemData{$id.':totalTries'} = $totalTries;
444: $problemData{$id.':studentTries'} = \@studentTries;
445: $problemData{$id.':totalAwarded'} = $totalAwarded;
446: $problemData{$id.':correct'} = $correct;
447: $problemData{$id.':correctByOverride'} = $correctByOverride;
448: $problemData{$id.':wrong'} = $studentCount -
449: ($correct + $correctByOverride);
450: $problemData{$id.':maxTries'} = $maxTries;
451: $problemData{$id.':totalFirst'} = $totalFirst;
452: }
453: }
454: }
455:
1.21 ! stredwic 456: $problemData{'problemList'} = join(':::', @problemList);
1.19 stredwic 457: # $Discussed=0;
458: # if($Discuss->{"$name:$problem"}) {
459: # $TotDiscuss++;
460: # $Discussed=1;
461: # }
462:
463: return \%problemData;
464: }
465:
466: sub SortProblems {
467: my ($problemData,$sortBy,$ascend)=@_;
468:
1.21 ! stredwic 469: my @problems = split(':::', $problemData->{'problemList'});
1.19 stredwic 470: if($sortBy eq "Homework Sets Order") {
1.21 ! stredwic 471: return \@problems;
1.19 stredwic 472: }
473:
474: my $data;
475:
476: if ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
477: elsif($sortBy eq "Tries") { $data = ':totalTries'; }
478: elsif($sortBy eq "Mod") { $data = ':maxTries'; }
479: elsif($sortBy eq "Mean") { $data = ':mean'; }
480: elsif($sortBy eq "#YES") { $data = ':correct'; }
481: elsif($sortBy eq "#yes") { $data = ':correctByOverride'; }
482: elsif($sortBy eq "%Wrng") { $data = ':percentWrong'; }
483: elsif($sortBy eq "DoDiff") { $data = ':degreeOfDifficulty'; }
484: elsif($sortBy eq "S.D.") { $data = ':standardDeviation'; }
485: elsif($sortBy eq "Skew.") { $data = ':skewness'; }
486: elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }
487: elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }
488: elsif($sortBy eq "Disc.") { $data = ''; }
1.21 ! stredwic 489: else { return \@problems; }
1.19 stredwic 490:
491: my @orderedProblems =
492: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
1.21 ! stredwic 493: @problems;
1.19 stredwic 494: if($ascend eq 'Descending') {
495: @orderedProblems = reverse(@orderedProblems);
496: }
497:
1.21 ! stredwic 498: return \@orderedProblems;
1.19 stredwic 499: }
500:
501: sub CalculateStatistics {
502: my ($data)=@_;
503:
1.21 ! stredwic 504: my @problems = split(':::', $data->{'problemList'});
! 505: foreach(@problems) {
1.19 stredwic 506: # Mean
507: $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ?
508: ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
509:
510: # %Wrong
511: $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ?
512: (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :
513: 100.0;
514:
515: # Degree of Difficulty
516: $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ?
517: (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
518: $data->{$_.':totalTries'})) : 0;
519:
520: # Factor in mean
521: my $studentTries = $data->{$_.':studentTries'};
522: foreach(my $index=0; $index < scalar(@$studentTries); $index++) {
523: $studentTries->[$index] -= $data->{$_.':mean'};
524: }
525: my $sumSquared = 0;
526: my $sumCubed = 0;
527: foreach(@$studentTries) {
528: my $squared = ($_ * $_);
529: my $cubed = ($squared * $_);
530: $sumSquared += $squared;
531: $sumCubed += $cubed;
532: }
533:
534: # Standard deviation
535: $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ?
536: ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0;
537:
538: # Skewness
539: my $standardDeviation = $data->{$_.':standardDeviation'};
540: $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ?
541: (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) /
542: ($standardDeviation * $standardDeviation * $standardDeviation)) :
543: 0;
544:
545: # Discrimination Factor 1
546: $data->{$_.':discriminationFactor1'} = 0;
547:
548: # Discrimination Factor 2
549: $data->{$_.':discriminationFactor2'} = 0;
550: }
551:
552: return;
553: }
554:
1.4 minaeibi 555: sub ProcessDiscriminant {
1.19 stredwic 556: my ($List) = @_;
1.4 minaeibi 557: my @sortedList = sort (@$List);
558: my $Count = scalar @sortedList;
559: my $Problem;
560: my @Dis;
561: my $Slvd=0;
562: my $tmp;
563: my $Sum1=0;
564: my $Sum2=0;
565: my $nIndex=0;
566: my $nStudent=0;
567: my %Proc=undef;
568: while ($nIndex<$Count) {
1.19 stredwic 569: # $jr->print("<br> $nIndex) $sortedList[$nIndex]");
1.4 minaeibi 570: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
571: @Dis=split(/\+/,$tmp);
572: my $Temp = $Problem;
573: do {
574: $nIndex++;
575: $nStudent++;
576: $Sum1 += $Dis[0];
577: $Sum2 += $Dis[1];
578: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
579: @Dis=split(/\+/,$tmp);
580: } while ( $Problem eq $Temp && $nIndex < $Count );
581: $Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
1.19 stredwic 582: # $jr->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
1.4 minaeibi 583: $Sum1=0;
584: $Sum2=0;
585: $nStudent=0;
586: }
587:
588: return %Proc;
589: }
590:
591: #------- Creating Discimination factor
592: sub Discriminant {
1.19 stredwic 593: my ($discriminant)=@_;
1.7 minaeibi 594: my @discriminantKeys=keys(%$discriminant);
1.4 minaeibi 595: my $Count = scalar @discriminantKeys;
596:
597: my $UpCnt = int(0.27*$Count);
598: my $low=0;
599: my $up=$Count-$UpCnt;
600: my @UpList=();
601: my @LowList=();
602:
603: $Count=0;
604: foreach my $key (sort(@discriminantKeys)) {
605: $Count++;
606: if($low < $UpCnt || $Count > $up) {
607: $low++;
1.7 minaeibi 608: my $str=$discriminant->{$key};
609: foreach(split(/\&/,$str)){
1.4 minaeibi 610: if($_) {
611: if($low<$UpCnt) { push(@LowList,$_); }
612: else { push(@UpList,$_); }
613: }
614: }
615: }
616: }
1.19 stredwic 617: my %DisUp = &ProcessDiscriminant(\@UpList);
618: my %DisLow = &ProcessDiscriminant(\@LowList);
1.4 minaeibi 619:
620: return (\%DisUp, \%DisLow);
1.8 minaeibi 621: }
1.4 minaeibi 622:
1.1 stredwic 623: #---- END Problem Statistics Web Page ----------------------------------------
624:
625: #---- Problem Statistics Graph Web Page --------------------------------------
626:
627: # ------------------------------------------- Prepare data for Graphical chart
628:
1.16 minaeibi 629: sub BuildGraphicChart {
630: my ($ylab,$r,$cacheDB)=@_;
631: my %cache;
1.1 stredwic 632: my $Col;
633: my $data='';
634: my $count = 0;
635: my $Max = 0;
1.14 minaeibi 636:
1.18 albertel 637: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.16 minaeibi 638: return '<html><body>Unable to tie database.</body></html>';
1.1 stredwic 639: }
1.16 minaeibi 640:
641: my $p_count = $cache{'ProblemCount'};
1.14 minaeibi 642:
643: for ( my $k=0; $k<$p_count;$k++) {
1.16 minaeibi 644: my @Temp=split(/\:/,$cache{'GraphGif:'.$k});
645: my $inf = $Temp[$Col];
646: if ( $Max < $inf ) {$Max = $inf;}
647: $data .= $inf.',';
648: $count++;
1.14 minaeibi 649: }
1.16 minaeibi 650: untie(%cache);
651: # $r->print("<br>count=$p_count >>data= $data");
1.14 minaeibi 652:
653: if ( $Max > 1 ) {
654: $Max += (10 - $Max % 10);
655: $Max = int($Max);
656: } else { $Max = 1; }
657:
1.16 minaeibi 658: my $cid=$ENV{'request.course.id'};
1.14 minaeibi 659:
1.16 minaeibi 660: if ( $ylab eq 'DoDiff Graph' ) {
661: $ylab = 'Degree-of-Difficulty';
662: $Col = 0;
663: } else {
664: $ylab = 'Wrong-Percentage';
665: $Col = 1;
666: }
1.14 minaeibi 667: my $Course = $ENV{'course.'.$cid.'.description'};
668: $Course =~ s/\ /"_"/eg;
1.16 minaeibi 669: my $GData=$Course.'&'.'Problems#'.'&'.$ylab.'&'.
1.14 minaeibi 670: $Max.'&'.$count.'&'.$data;
1.16 minaeibi 671:
672: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
673:
674: return;
1.1 stredwic 675: }
1.4 minaeibi 676:
1.1 stredwic 677: 1;
678: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>