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