Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.23
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.23 ! stredwic 4: # $Id: lonproblemstatistics.pm,v 1.22 2002/08/13 15:01:07 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.23 ! stredwic 181: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' &&
! 182: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
! 183: next;
! 184: }
1.19 stredwic 185:
1.21 stredwic 186: my $ref = '<a href="'.$cache->{$problem.':source'}.
187: '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
188: # my $ref = $cache->{$problem.':title'};
1.19 stredwic 189: my $title = $cache->{$problem.':title'};
190: my $source = 'source';
191: my $tableData = join('&', $ref, $title, $source,
1.21 stredwic 192: $cache->{$_.':studentCount'},
193: $cache->{$_.':totalTries'},
194: $cache->{$_.':maxTries'},
195: sprintf("%.2f", $cache->{$_.':mean'}),
196: $cache->{$_.':correct'},
197: $cache->{$_.':correctByOverride'},
198: sprintf("%.1f", $cache->{$_.':percentWrong'}),
199: sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}),
200: sprintf("%.1f", $cache->{$_.':standardDeviation'}),
201: sprintf("%.1f", $cache->{$_.':skewness'}),
202: sprintf("%.2f", $cache->{$_.':discriminationFactor1'}),
203: sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),
204: 0); # 0 is for discussion, need to figure out
1.1 stredwic 205:
206: #6666666
207: # $r->print('<br>'.$out.'&'.$DoD);
208: # print (OUT $out.'@'.$DoD.'&');
209: #6666666
210:
1.16 minaeibi 211: #check with Gerd
1.19 stredwic 212: # $urlres=~/^(\w+)\/(\w+)/;
213: # if ($StdNo) {
214: # &Apache::lonnet::put('nohist_resevaldata',\%storestats,
215: # $1,$2);
216: # }
1.1 stredwic 217: #-------------------------------- Row of statistical table
1.19 stredwic 218: &TableRow($displayFormat,$tableData,$count,$r,$color);
219: $count++;
220: }
221: if($cache->{'DisplayFormat'} ne 'Display CSV Format') {
222: $r->print('</table>'."\n");
1.1 stredwic 223: }
1.19 stredwic 224: $r->print('</td></tr></table>');
1.14 minaeibi 225: #6666666
1.1 stredwic 226: # close( OUT );
227: #666666
1.21 stredwic 228: return;
1.1 stredwic 229: }
230:
231: sub TableRow {
1.19 stredwic 232: my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
233: my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
1.1 stredwic 234: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);
1.8 minaeibi 235: my $Ptr;
1.19 stredwic 236: if($displayFormat eq 'Display CSV Format') {
1.8 minaeibi 237: $Ptr="\n".'<br>'.
1.19 stredwic 238: "\n".'"'.$RealIdx.'",'.
239: "\n".'"'.$title.'",'.
240: "\n".'"'.$source.'",'.
1.8 minaeibi 241: "\n".'"'.$StdNo.'",'.
242: "\n".'"'.$TotalTries.'",'.
243: "\n".'"'.$MxTries.'",'.
244: "\n".'"'.$Avg.'",'.
245: "\n".'"'.$YES.'",'.
246: "\n".'"'.$Override.'",'.
247: "\n".'"'.$Wrng.'",'.
248: "\n".'"'.$DoD.'",'.
249: "\n".'"'.$SD.'",'.
250: "\n".'"'.$Sk.'",'.
251: "\n".'"'.$_D1.'",'.
252: "\n".'"'.$_D2.'"'.
253: "\n".'"'.$DiscNo.'"';
1.1 stredwic 254:
255: $r->print("\n".$Ptr);
1.8 minaeibi 256: } else {
257: $Ptr="\n".'<tr>'.
1.19 stredwic 258: "\n".'<td bgcolor="#ffffe6">'.$RealIdx.'</td>'.
259: "\n".'<td bgcolor="#ffffe6">'.$ref.'</td>'.
1.8 minaeibi 260: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
261: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
262: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
263: "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
264: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
265: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
266: "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
267: "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
268: "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
269: "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
270: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
271: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
272: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
1.1 stredwic 273: $r->print("\n".$Ptr.'</tr>' );
274: }
1.19 stredwic 275:
276: return;
1.1 stredwic 277: }
1.5 minaeibi 278:
279: # For loading the colored table for display or un-colored for print
280: sub setbgcolor {
281: my $PrintTable=shift;
282: my %color;
283: if ($PrintTable){
284: $color{"gb"}="#FFFFFF";
285: $color{"red"}="#FFFFFF";
286: $color{"yellow"}="#FFFFFF";
287: $color{"green"}="#FFFFFF";
288: $color{"purple"}="#FFFFFF";
289: } else {
290: $color{"gb"}="#DDFFFF";
291: $color{"red"}="#FFDDDD";
292: $color{"yellow"}="#EEFFCC";
293: $color{"green"}="#DDFFDD";
294: $color{"purple"}="#FFDDFF";
295: }
296:
297: return \%color;
298: }
299:
1.1 stredwic 300: sub ProblemStatisticsButtons {
1.20 stredwic 301: my ($displayFormat, $displayLegend)=@_;
1.1 stredwic 302:
303: my $Ptr = '<tr><td></td><td align="left">';
304: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
305: $Ptr .= 'value="DoDiff Graph" />'."\n";
306: $Ptr .= ' ';
307: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
308: $Ptr .= 'value="%Wrong Graph" />'."\n";
1.20 stredwic 309: $Ptr .= '</td></tr><tr><td></td><td>'."\n";
310: $Ptr .= '<input type="submit" name="DisplayLegend" ';
311: if($displayLegend eq 'Show Legend') {
312: $Ptr .= 'value="Hide Legend" />'."\n";
313: } else {
314: $Ptr .= 'value="Show Legend" />'."\n";
315: }
1.1 stredwic 316: $Ptr .= ' ';
317: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
318: if($displayFormat eq 'Display CSV Format') {
1.9 stredwic 319: $Ptr .= 'value="Display Table Format" />'."\n";
320: } else {
1.1 stredwic 321: $Ptr .= 'value="Display CSV Format" />'."\n";
322: }
323: $Ptr .= '</td></tr>';
324:
325: return $Ptr;
326: }
327:
328: sub ProblemStatisticsLegend {
329: my $Ptr = '';
330: $Ptr = '<table border="0">';
331: $Ptr .= '<tr><td>';
1.6 minaeibi 332: $Ptr .= '<b>#Stdnts</b></td>';
1.19 stredwic 333: $Ptr .= '<td>Total number of students attempted the problem.';
1.1 stredwic 334: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 335: $Ptr .= '<b>Tries</b></td>';
1.19 stredwic 336: $Ptr .= '<td>Total number of tries for solving the problem.';
1.1 stredwic 337: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 338: $Ptr .= '<b>Mod</b></td>';
1.19 stredwic 339: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
1.1 stredwic 340: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 341: $Ptr .= '<b>Mean</b></td>';
1.19 stredwic 342: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
1.1 stredwic 343: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 344: $Ptr .= '<b>#YES</b></td>';
1.1 stredwic 345: $Ptr .= '<td>Number of students solved the problem correctly.';
346: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 347: $Ptr .= '<b>#yes</b></td>';
1.1 stredwic 348: $Ptr .= '<td>Number of students solved the problem by override.';
349: $Ptr .= '</td></tr><tr><td>';
1.19 stredwic 350: $Ptr .= '<b>%Wrong</b></td>';
351: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
352: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
1.1 stredwic 353: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 354: $Ptr .= '<b>DoDiff</b></td>';
1.1 stredwic 355: $Ptr .= '<td>Degree of Difficulty of the problem. ';
356: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
357: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 358: $Ptr .= '<b>S.D.</b></td>';
1.1 stredwic 359: $Ptr .= '<td>Standard Deviation of the tries. ';
360: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
361: $Ptr .= 'where Xi denotes every student\'s tries ]';
362: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 363: $Ptr .= '<b>Skew.</b></td>';
1.1 stredwic 364: $Ptr .= '<td>Skewness of the students tries.';
365: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
366: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 367: $Ptr .= '<b>Dis.F.</b></td>';
1.1 stredwic 368: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
369: $Ptr .= 'problem according to a Criterion<br>';
370: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
371: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
372: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
373: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
374: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
375: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
376: $Ptr .= '</td></tr>';
377: $Ptr .= '<tr><td><b>Disc.</b></td>';
378: $Ptr .= '<td>Number of Students had at least one discussion.';
379: $Ptr .= '</td></tr></table>';
380:
381: return $Ptr;
382: }
383:
1.4 minaeibi 384: #------- Processing upperlist and lowerlist according to each problem
1.19 stredwic 385:
386: sub ExtractStudentData {
387: my ($cache, $students)=@_;
388:
389: #$Apache::lonxml::debug=1;
390: #&Apache::lonhomework::showhash(%$cache);
391: #$Apache::lonxml::debug=0;
392:
393: my @problemList=();
394: my %problemData;
395: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
396: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
397: foreach my $part (split(/\:/,$cache->{$sequence.':'.
398: $problemID.
399: ':parts'})) {
400: my $id = $sequence.':'.$problemID.':'.$part;
401: push(@problemList, $id);
402: my $totalTries = 0;
403: my $totalAwarded = 0;
404: my $correct = 0;
405: my $correctByOverride = 0;
406: my $studentCount = 0;
407: my $maxTries = 0;
408: my $totalFirst = 0;
409: my @studentTries=();
410: foreach(@$students) {
411: my $code = $cache->{"$_:$problemID:$part:code"};
412:
413: if(defined($cache->{$_.':error'}) || $code eq ' ' ||
414: $cache->{"$_:$problemID:NoVersion"} eq 'true') {
415: next;
416: }
417:
418: $studentCount++;
419: my $tries = $cache->{"$_:$problemID:$part:tries"};
420: if($maxTries < $tries) {
421: $maxTries = $tries;
422: }
423: $totalTries += $tries;
424: push(@studentTries, $tries);
425:
426: my $awarded = $cache->{"$_:$problemID:$part:awarded"};
427: $totalAwarded += $awarded;
428:
429: if($code eq '*') {
430: $correct++;
431: if($tries == 1) {
432: $totalFirst++;
433: }
434: } elsif($code eq '+') {
435: $correctByOverride++;
436: }
437: }
438:
439: $problemData{$id.':sequenceTitle'} =
440: $cache->{$sequence.':title'};
441: $problemData{$id.':studentCount'} = $studentCount;
442: $problemData{$id.':totalTries'} = $totalTries;
443: $problemData{$id.':studentTries'} = \@studentTries;
444: $problemData{$id.':totalAwarded'} = $totalAwarded;
445: $problemData{$id.':correct'} = $correct;
446: $problemData{$id.':correctByOverride'} = $correctByOverride;
447: $problemData{$id.':wrong'} = $studentCount -
448: ($correct + $correctByOverride);
449: $problemData{$id.':maxTries'} = $maxTries;
450: $problemData{$id.':totalFirst'} = $totalFirst;
451: }
452: }
453: }
454:
1.21 stredwic 455: $problemData{'problemList'} = join(':::', @problemList);
1.19 stredwic 456: # $Discussed=0;
457: # if($Discuss->{"$name:$problem"}) {
458: # $TotDiscuss++;
459: # $Discussed=1;
460: # }
461:
462: return \%problemData;
463: }
464:
465: sub SortProblems {
466: my ($problemData,$sortBy,$ascend)=@_;
467:
1.21 stredwic 468: my @problems = split(':::', $problemData->{'problemList'});
1.19 stredwic 469: if($sortBy eq "Homework Sets Order") {
1.21 stredwic 470: return \@problems;
1.19 stredwic 471: }
472:
473: my $data;
474:
475: if ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
476: elsif($sortBy eq "Tries") { $data = ':totalTries'; }
477: elsif($sortBy eq "Mod") { $data = ':maxTries'; }
478: elsif($sortBy eq "Mean") { $data = ':mean'; }
479: elsif($sortBy eq "#YES") { $data = ':correct'; }
480: elsif($sortBy eq "#yes") { $data = ':correctByOverride'; }
481: elsif($sortBy eq "%Wrng") { $data = ':percentWrong'; }
482: elsif($sortBy eq "DoDiff") { $data = ':degreeOfDifficulty'; }
483: elsif($sortBy eq "S.D.") { $data = ':standardDeviation'; }
484: elsif($sortBy eq "Skew.") { $data = ':skewness'; }
485: elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }
486: elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }
487: elsif($sortBy eq "Disc.") { $data = ''; }
1.21 stredwic 488: else { return \@problems; }
1.19 stredwic 489:
490: my @orderedProblems =
491: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
1.21 stredwic 492: @problems;
1.19 stredwic 493: if($ascend eq 'Descending') {
494: @orderedProblems = reverse(@orderedProblems);
495: }
496:
1.21 stredwic 497: return \@orderedProblems;
1.19 stredwic 498: }
499:
500: sub CalculateStatistics {
501: my ($data)=@_;
502:
1.21 stredwic 503: my @problems = split(':::', $data->{'problemList'});
504: foreach(@problems) {
1.19 stredwic 505: # Mean
506: $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ?
507: ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
508:
509: # %Wrong
510: $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ?
511: (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :
512: 100.0;
513:
514: # Degree of Difficulty
515: $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ?
516: (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
517: $data->{$_.':totalTries'})) : 0;
518:
519: # Factor in mean
520: my $studentTries = $data->{$_.':studentTries'};
521: foreach(my $index=0; $index < scalar(@$studentTries); $index++) {
522: $studentTries->[$index] -= $data->{$_.':mean'};
523: }
524: my $sumSquared = 0;
525: my $sumCubed = 0;
526: foreach(@$studentTries) {
527: my $squared = ($_ * $_);
528: my $cubed = ($squared * $_);
529: $sumSquared += $squared;
530: $sumCubed += $cubed;
531: }
532:
533: # Standard deviation
534: $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ?
535: ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0;
536:
537: # Skewness
538: my $standardDeviation = $data->{$_.':standardDeviation'};
539: $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ?
540: (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) /
541: ($standardDeviation * $standardDeviation * $standardDeviation)) :
542: 0;
543:
544: # Discrimination Factor 1
545: $data->{$_.':discriminationFactor1'} = 0;
546:
547: # Discrimination Factor 2
548: $data->{$_.':discriminationFactor2'} = 0;
549: }
550:
551: return;
552: }
553:
1.4 minaeibi 554: sub ProcessDiscriminant {
1.19 stredwic 555: my ($List) = @_;
1.4 minaeibi 556: my @sortedList = sort (@$List);
557: my $Count = scalar @sortedList;
558: my $Problem;
559: my @Dis;
560: my $Slvd=0;
561: my $tmp;
562: my $Sum1=0;
563: my $Sum2=0;
564: my $nIndex=0;
565: my $nStudent=0;
566: my %Proc=undef;
567: while ($nIndex<$Count) {
1.19 stredwic 568: # $jr->print("<br> $nIndex) $sortedList[$nIndex]");
1.4 minaeibi 569: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
570: @Dis=split(/\+/,$tmp);
571: my $Temp = $Problem;
572: do {
573: $nIndex++;
574: $nStudent++;
575: $Sum1 += $Dis[0];
576: $Sum2 += $Dis[1];
577: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
578: @Dis=split(/\+/,$tmp);
579: } while ( $Problem eq $Temp && $nIndex < $Count );
580: $Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
1.19 stredwic 581: # $jr->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
1.4 minaeibi 582: $Sum1=0;
583: $Sum2=0;
584: $nStudent=0;
585: }
586:
587: return %Proc;
588: }
589:
590: #------- Creating Discimination factor
591: sub Discriminant {
1.19 stredwic 592: my ($discriminant)=@_;
1.7 minaeibi 593: my @discriminantKeys=keys(%$discriminant);
1.4 minaeibi 594: my $Count = scalar @discriminantKeys;
595:
596: my $UpCnt = int(0.27*$Count);
597: my $low=0;
598: my $up=$Count-$UpCnt;
599: my @UpList=();
600: my @LowList=();
601:
602: $Count=0;
603: foreach my $key (sort(@discriminantKeys)) {
604: $Count++;
605: if($low < $UpCnt || $Count > $up) {
606: $low++;
1.7 minaeibi 607: my $str=$discriminant->{$key};
608: foreach(split(/\&/,$str)){
1.4 minaeibi 609: if($_) {
610: if($low<$UpCnt) { push(@LowList,$_); }
611: else { push(@UpList,$_); }
612: }
613: }
614: }
615: }
1.19 stredwic 616: my %DisUp = &ProcessDiscriminant(\@UpList);
617: my %DisLow = &ProcessDiscriminant(\@LowList);
1.4 minaeibi 618:
619: return (\%DisUp, \%DisLow);
1.8 minaeibi 620: }
1.4 minaeibi 621:
1.1 stredwic 622: #---- END Problem Statistics Web Page ----------------------------------------
623:
624: #---- Problem Statistics Graph Web Page --------------------------------------
625:
626: # ------------------------------------------- Prepare data for Graphical chart
627:
1.16 minaeibi 628: sub BuildGraphicChart {
1.22 stredwic 629: my ($graph,$cacheDB,$courseDescription,$r)=@_;
1.16 minaeibi 630: my %cache;
1.22 stredwic 631: my $max = 0;
1.14 minaeibi 632:
1.18 albertel 633: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.16 minaeibi 634: return '<html><body>Unable to tie database.</body></html>';
1.1 stredwic 635: }
1.16 minaeibi 636:
1.22 stredwic 637: my @problems = split(':::', $cache{'problemList'});
638: my @values = ();
639: foreach (@problems) {
640: my $data = 0;
641: if($graph eq 'DoDiffGraph') {
642: $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
643: } else {
644: $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
645: }
646: if($max < $data) {
647: $max = $data;
648: }
649: push(@values, $data);
1.14 minaeibi 650: }
1.16 minaeibi 651: untie(%cache);
1.14 minaeibi 652:
1.22 stredwic 653: my $sendValues = join(',', @values);
654: # my $sendCount = $#values;
655: my $sendCount = scalar(@values);
656:
657: my $title = '';
658: if($graph eq 'DoDiffGraph') {
659: $title = 'Degree-of-Difficulty';
1.16 minaeibi 660: } else {
1.22 stredwic 661: $title = 'Wrong-Percentage';
1.16 minaeibi 662: }
1.22 stredwic 663: my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount,
664: $sendValues);
1.16 minaeibi 665:
1.22 stredwic 666: $r->print('</form>'."\n");
667: $r->print('<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData)).'" border="1" />');
668: $r->print('<form>'."\n");
1.16 minaeibi 669:
670: return;
1.1 stredwic 671: }
1.4 minaeibi 672:
1.1 stredwic 673: 1;
674: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>