Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.27
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.27 ! stredwic 4: # $Id: lonproblemstatistics.pm,v 1.26 2002/08/14 17:45:19 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:
1.26 stredwic 48: sub InitializeProblemStatistics {
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.');
1.26 stredwic 56: return ('ERROR', undef);
1.1 stredwic 57: }
58:
1.25 stredwic 59: # Remove students who don't have the proper section.
60: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
61: for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
62: $studentIndex--) {
63: my $value = $cache{$students->[$studentIndex].':section'};
64: my $found = 0;
65: foreach (@sectionsSelected) {
66: if($_ eq 'none') {
67: if($value eq '' || !defined($value) || $value eq ' ') {
68: $found = 1;
69: last;
70: }
71: } else {
72: if($value eq $_) {
73: $found = 1;
74: last;
75: }
76: }
77: }
78: if($found == 0) {
79: splice(@$students, $studentIndex, 1);
80: }
81: }
82:
83: my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
84: $cache{'StatisticsLastStatus'} : 'Nothing';
85: my $whichStudents = join(':::',sort(@$students));
86: if(!defined($cache{'StatisticsCached'}) ||
87: $lastStatus ne $cache{'Status'} ||
88: $whichStudents ne $cache{'StatisticsWhichStudents'}) {
1.24 stredwic 89: if(defined($cache{'StatisticsCached'})) {
90: untie(%cache);
91: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
92: $r->print('Unable to tie database.');
1.26 stredwic 93: return ('ERROR', undef);
1.24 stredwic 94: }
95: my @statkeys = split(':::', $cache{'StatisticsKeys'});
96: delete $cache{'StatisticsKeys'};
97: delete $cache{'StatisticsCached'};
98: foreach(@statkeys) {
99: delete $cache{$_};
100: }
101: }
1.21 stredwic 102: untie(%cache);
103: &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
104: 'true',
105: $cacheDB,
106: 'true',
107: 'true',
108: $courseID,
109: $r, $c);
1.26 stredwic 110: if($c->aborted()) { return ('ERROR', undef); }
1.21 stredwic 111:
112: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
113: $r->print('Unable to tie database.');
1.26 stredwic 114: return ('ERROR', undef);
1.21 stredwic 115: }
116: my ($problemData) = &ExtractStudentData(\%cache, $students);
1.24 stredwic 117: &CalculateStatistics($problemData, \%cache);
1.21 stredwic 118: untie(%cache);
119:
120: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
121: $r->print('Unable to tie database.');
1.26 stredwic 122: return ('ERROR', undef);
1.21 stredwic 123: }
124: foreach(keys(%$problemData)) {
125: $cache{$_} = $problemData->{$_};
126: }
1.24 stredwic 127: $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
1.21 stredwic 128: $cache{'StatisticsCached'} = 'true';
1.25 stredwic 129: $cache{'StatisticsLastStatus'} = $cache{'Status'};
130: $cache{'StatisticsWhichStudents'} = $whichStudents;
1.21 stredwic 131: untie(%cache);
132:
133: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
134: $r->print('Unable to tie database.');
1.26 stredwic 135: return ('ERROR', undef);
1.21 stredwic 136: }
137: }
1.25 stredwic 138:
1.21 stredwic 139: my $orderedProblems = &SortProblems(\%cache,
140: $cache{'ProblemStatisticsSort'},
1.26 stredwic 141: $cache{'SortProblems'},
1.21 stredwic 142: $cache{'ProblemStatisticsAscend'});
1.26 stredwic 143: return ('OK', $orderedProblems);
144: }
145:
146: sub BuildProblemStatisticsPage {
147: my ($cacheDB, $students, $courseID, $c, $r)=@_;
148:
149: my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
150: "Mean","#YES","#yes","%Wrng","DoDiff",
1.27 ! stredwic 151: "S.D.","Skew.","D.F.1st","D.F.2nd");
1.26 stredwic 152: my $color=&setbgcolor(0);
153: my %cache;
154:
155: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
156: $r->print('Unable to tie database.');
157: return;
158: }
159: my $Ptr = '';
1.27 ! stredwic 160: $Ptr .= '<table border="0" cellspacing="5"><tbody>';
1.26 stredwic 161: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
162: $Ptr .= '<td align="left">';
163: $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
164: 'Statistics');
165: $Ptr .= '</td></tr>'."\n";
166: $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
167: $Ptr .= '<td align="left">'."\n";
168: $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
169: $cache{'ProblemStatisticsAscend'},
170: 'ProblemStatistics',
171: 'Statistics');
172: $Ptr .= '</td></tr>'."\n";
173: $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
174: $Ptr .= '</td>'."\n";
175: $Ptr .= '<td align="left">'."\n";
176: my @sections = split(':',$cache{'sectionList'});
177: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
178: $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
179: \@sectionsSelected,
180: 'Statistics');
181: $Ptr .= '</td></tr>'."\n";
182: $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
183: $cache{'DisplayLegend'},
184: $cache{'SortProblems'});
185: $Ptr .= '</table>';
186: if($cache{'DisplayLegend'} eq 'Show Legend') {
187: $Ptr .= &ProblemStatisticsLegend();
188: }
189: $r->print($Ptr);
190: $r->rflush();
191: untie(%cache);
192:
193: my ($result, $orderedProblems) =
194: &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
195: if($result ne 'OK') {
196: return;
197: }
198:
199: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
200: $r->print('Unable to tie database.');
201: return;
202: }
203: &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
204: $cache{'SortProblems'}, $orderedProblems,
1.21 stredwic 205: \@Header, $r, $color);
1.19 stredwic 206: untie(%cache);
1.12 minaeibi 207:
1.19 stredwic 208: return;
1.1 stredwic 209: }
210:
1.24 stredwic 211: sub BuildGraphicChart {
1.26 stredwic 212: my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
1.24 stredwic 213: my %cache;
214: my $max = 0;
215:
1.26 stredwic 216: my ($result, undef) =
217: &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
218: if($result ne 'OK') {
219: return;
220: }
221:
1.24 stredwic 222: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.26 stredwic 223: return 'Unable to tie database.';
1.24 stredwic 224: }
225:
226: my @problems = split(':::', $cache{'problemList'});
227: my @values = ();
228: foreach (@problems) {
229: my $data = 0;
230: if($graph eq 'DoDiffGraph') {
231: $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
232: } else {
233: $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
234: }
235: if($max < $data) {
236: $max = $data;
237: }
238: push(@values, $data);
239: }
240: untie(%cache);
241:
242: my $sendValues = join(',', @values);
243: my $sendCount = scalar(@values);
244:
245: my $title = '';
246: if($graph eq 'DoDiffGraph') {
247: $title = 'Degree-of-Difficulty';
248: } else {
249: $title = 'Wrong-Percentage';
250: }
251: my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount,
252: $sendValues);
253:
254: $r->print('</form>'."\n");
1.26 stredwic 255: $r->print('<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData)).
256: '" border="1" />');
1.24 stredwic 257: $r->print('<form>'."\n");
258:
259: return;
260: }
1.1 stredwic 261:
262: #---- Problem Statistics Web Page ---------------------------------------
263:
264: sub CreateProblemStatisticsTableHeading {
1.19 stredwic 265: my ($headings,$r)=@_;
1.3 minaeibi 266:
1.19 stredwic 267: my $Str='';
268: $Str .= '<tr>'."\n";
269: $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
270: foreach(@$headings) {
1.27 ! stredwic 271: $Str .= '<th bgcolor="#ffffe6">';
! 272: $Str .= '<a href="/adm/statistics?reportSelected=';
1.19 stredwic 273: $Str .= &Apache::lonnet::escape('Problem Statistics');
274: $Str .= '&ProblemStatisticsSort=';
275: $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a> </th>'."\n";
1.1 stredwic 276: }
1.19 stredwic 277: $Str .= "\n".'</tr>'."\n";
1.1 stredwic 278:
1.19 stredwic 279: return $Str;
1.1 stredwic 280: }
1.12 minaeibi 281:
1.1 stredwic 282: sub BuildStatisticsTable {
1.26 stredwic 283: my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,
284: $r,$color)=@_;
1.5 minaeibi 285:
1.19 stredwic 286: my $count = 1;
1.26 stredwic 287: my $currentSequence = -1;
1.21 stredwic 288: foreach(@$orderedProblems) {
1.19 stredwic 289: my ($sequence,$problem,$part)=split(':', $_);
1.25 stredwic 290: if($cache->{'StatisticsMaps'} ne 'All Maps' &&
291: $cache->{'StatisticsMaps'} ne $cache->{$sequence.':title'}) {
1.23 stredwic 292: next;
293: }
1.19 stredwic 294:
1.26 stredwic 295: if($currentSequence == -1 ||
296: ($sortProblems eq 'Sort Within Sequence' &&
297: $currentSequence != $sequence)) {
298: if($displayFormat ne 'Display CSV Format') {
299: if($currentSequence ne -1) {
300: $r->print('</table>');
301: $r->print('</td></tr></table><br>');
302: }
303: if($sortProblems eq 'Sort Within Sequence') {
304: $r->print('<b>'.$cache->{$sequence.':title'}.'</b>');
305: }
306: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
307: $r->print('<table border="0" cellpadding="3">'."\n");
308: $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
309: } else {
310: if($sortProblems eq 'Sort Within Sequence') {
311: $r->print('"'.$cache->{$sequence.':title'}.'"');
312: }
313: $r->print('<br>');
314: }
315: $currentSequence = $sequence;
316: }
317:
1.21 stredwic 318: my $ref = '<a href="'.$cache->{$problem.':source'}.
319: '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
1.19 stredwic 320: my $title = $cache->{$problem.':title'};
1.27 ! stredwic 321: if($part != 0) {
! 322: $title .= ' Part '.$part;
! 323: }
1.26 stredwic 324: my $source = $cache->{$problem.':source'};
1.19 stredwic 325: my $tableData = join('&', $ref, $title, $source,
1.21 stredwic 326: $cache->{$_.':studentCount'},
327: $cache->{$_.':totalTries'},
328: $cache->{$_.':maxTries'},
1.27 ! stredwic 329: $cache->{$_.':mean'},
1.21 stredwic 330: $cache->{$_.':correct'},
331: $cache->{$_.':correctByOverride'},
1.27 ! stredwic 332: $cache->{$_.':percentWrong'},
! 333: $cache->{$_.':degreeOfDifficulty'},
! 334: $cache->{$_.':standardDeviation'},
! 335: $cache->{$_.':skewness'},
! 336: $cache->{$_.':discriminationFactor1'},
! 337: $cache->{$_.':discriminationFactor2'});
1.1 stredwic 338:
1.19 stredwic 339: &TableRow($displayFormat,$tableData,$count,$r,$color);
1.26 stredwic 340:
1.19 stredwic 341: $count++;
342: }
1.26 stredwic 343: if($displayFormat ne 'Display CSV Format') {
1.19 stredwic 344: $r->print('</table>'."\n");
1.26 stredwic 345: $r->print('</td></tr></table>');
346: } else {
347: $r->print('<br>');
1.1 stredwic 348: }
1.27 ! stredwic 349:
1.21 stredwic 350: return;
1.1 stredwic 351: }
352:
353: sub TableRow {
1.19 stredwic 354: my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
355: my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
1.27 ! stredwic 356: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str);
1.8 minaeibi 357: my $Ptr;
1.19 stredwic 358: if($displayFormat eq 'Display CSV Format') {
1.26 stredwic 359: $Ptr='"'.$RealIdx.'",'."\n".
360: '"'.$title.'",'."\n".
361: '"'.$source.'",'."\n".
362: '"'.$StdNo.'",'."\n".
363: '"'.$TotalTries.'",'."\n".
364: '"'.$MxTries.'",'."\n".
365: '"'.$Avg.'",'."\n".
366: '"'.$YES.'",'."\n".
367: '"'.$Override.'",'."\n".
368: '"'.$Wrng.'",'."\n".
369: '"'.$DoD.'",'."\n".
370: '"'.$SD.'",'."\n".
371: '"'.$Sk.'",'."\n".
372: '"'.$_D1.'",'."\n".
373: '"'.$_D2.'"'."\n".
374: "<br>\n";
1.1 stredwic 375:
376: $r->print("\n".$Ptr);
1.8 minaeibi 377: } else {
1.26 stredwic 378: $Ptr='<tr>'."\n".
379: '<td bgcolor="#ffffe6">'.$RealIdx.'</td>'."\n".
380: '<td bgcolor="#ffffe6">'.$ref.'</td>'."\n".
381: '<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'."\n".
382: '<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'."\n".
383: '<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'."\n".
384: '<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'."\n".
385: '<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'."\n".
386: '<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'."\n".
387: '<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'."\n".
388: '<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'."\n".
389: '<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'."\n".
390: '<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'."\n".
391: '<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'."\n".
1.27 ! stredwic 392: '<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'."\n";
1.26 stredwic 393: $r->print($Ptr.'</tr>'."\n");
1.1 stredwic 394: }
1.19 stredwic 395:
396: return;
1.1 stredwic 397: }
1.5 minaeibi 398:
399: # For loading the colored table for display or un-colored for print
400: sub setbgcolor {
401: my $PrintTable=shift;
402: my %color;
403: if ($PrintTable){
404: $color{"gb"}="#FFFFFF";
405: $color{"red"}="#FFFFFF";
406: $color{"yellow"}="#FFFFFF";
407: $color{"green"}="#FFFFFF";
408: $color{"purple"}="#FFFFFF";
409: } else {
410: $color{"gb"}="#DDFFFF";
411: $color{"red"}="#FFDDDD";
412: $color{"yellow"}="#EEFFCC";
413: $color{"green"}="#DDFFDD";
414: $color{"purple"}="#FFDDFF";
415: }
416:
417: return \%color;
418: }
419:
1.1 stredwic 420: sub ProblemStatisticsButtons {
1.26 stredwic 421: my ($displayFormat, $displayLegend, $sortProblems)=@_;
1.1 stredwic 422:
423: my $Ptr = '<tr><td></td><td align="left">';
424: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
1.27 ! stredwic 425: $Ptr .= 'value="Degree of Difficulty" />'."\n";
! 426: $Ptr .= '</td><td align="left">';
1.1 stredwic 427: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
1.27 ! stredwic 428: $Ptr .= 'value="Percent Wrong" />'."\n";
1.20 stredwic 429: $Ptr .= '</td></tr><tr><td></td><td>'."\n";
1.26 stredwic 430: $Ptr .= '<input type="submit" name="SortProblems" ';
431: if($sortProblems eq 'Sort All Problems') {
432: $Ptr .= 'value="Sort Within Sequence" />'."\n";
433: } else {
434: $Ptr .= 'value="Sort All Problems" />'."\n";
435: }
1.27 ! stredwic 436: $Ptr .= '</td><td align="left">';
1.20 stredwic 437: $Ptr .= '<input type="submit" name="DisplayLegend" ';
438: if($displayLegend eq 'Show Legend') {
439: $Ptr .= 'value="Hide Legend" />'."\n";
440: } else {
441: $Ptr .= 'value="Show Legend" />'."\n";
442: }
1.27 ! stredwic 443: $Ptr .= '</td><td align="left">';
1.1 stredwic 444: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
445: if($displayFormat eq 'Display CSV Format') {
1.9 stredwic 446: $Ptr .= 'value="Display Table Format" />'."\n";
447: } else {
1.1 stredwic 448: $Ptr .= 'value="Display CSV Format" />'."\n";
449: }
450: $Ptr .= '</td></tr>';
451:
452: return $Ptr;
453: }
454:
455: sub ProblemStatisticsLegend {
456: my $Ptr = '';
457: $Ptr = '<table border="0">';
458: $Ptr .= '<tr><td>';
1.6 minaeibi 459: $Ptr .= '<b>#Stdnts</b></td>';
1.19 stredwic 460: $Ptr .= '<td>Total number of students attempted the problem.';
1.1 stredwic 461: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 462: $Ptr .= '<b>Tries</b></td>';
1.19 stredwic 463: $Ptr .= '<td>Total number of tries for solving the problem.';
1.1 stredwic 464: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 465: $Ptr .= '<b>Mod</b></td>';
1.19 stredwic 466: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
1.1 stredwic 467: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 468: $Ptr .= '<b>Mean</b></td>';
1.19 stredwic 469: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
1.1 stredwic 470: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 471: $Ptr .= '<b>#YES</b></td>';
1.1 stredwic 472: $Ptr .= '<td>Number of students solved the problem correctly.';
473: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 474: $Ptr .= '<b>#yes</b></td>';
1.1 stredwic 475: $Ptr .= '<td>Number of students solved the problem by override.';
476: $Ptr .= '</td></tr><tr><td>';
1.19 stredwic 477: $Ptr .= '<b>%Wrong</b></td>';
478: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
479: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
1.1 stredwic 480: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 481: $Ptr .= '<b>DoDiff</b></td>';
1.1 stredwic 482: $Ptr .= '<td>Degree of Difficulty of the problem. ';
483: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
484: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 485: $Ptr .= '<b>S.D.</b></td>';
1.1 stredwic 486: $Ptr .= '<td>Standard Deviation of the tries. ';
487: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
488: $Ptr .= 'where Xi denotes every student\'s tries ]';
489: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 490: $Ptr .= '<b>Skew.</b></td>';
1.1 stredwic 491: $Ptr .= '<td>Skewness of the students tries.';
492: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
493: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 494: $Ptr .= '<b>Dis.F.</b></td>';
1.1 stredwic 495: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
496: $Ptr .= 'problem according to a Criterion<br>';
497: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
498: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
499: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
500: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
501: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
502: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
503: $Ptr .= '</td></tr>';
504: $Ptr .= '<tr><td><b>Disc.</b></td>';
505: $Ptr .= '<td>Number of Students had at least one discussion.';
506: $Ptr .= '</td></tr></table>';
507:
508: return $Ptr;
509: }
510:
1.19 stredwic 511: sub ExtractStudentData {
512: my ($cache, $students)=@_;
513:
514: my @problemList=();
515: my %problemData;
516: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
517: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
518: foreach my $part (split(/\:/,$cache->{$sequence.':'.
519: $problemID.
520: ':parts'})) {
521: my $id = $sequence.':'.$problemID.':'.$part;
522: push(@problemList, $id);
523: my $totalTries = 0;
524: my $totalAwarded = 0;
525: my $correct = 0;
526: my $correctByOverride = 0;
527: my $studentCount = 0;
528: my $maxTries = 0;
529: my $totalFirst = 0;
530: my @studentTries=();
531: foreach(@$students) {
532: my $code = $cache->{"$_:$problemID:$part:code"};
533:
534: if(defined($cache->{$_.':error'}) || $code eq ' ' ||
535: $cache->{"$_:$problemID:NoVersion"} eq 'true') {
536: next;
537: }
538:
539: $studentCount++;
540: my $tries = $cache->{"$_:$problemID:$part:tries"};
541: if($maxTries < $tries) {
542: $maxTries = $tries;
543: }
544: $totalTries += $tries;
545: push(@studentTries, $tries);
546:
547: my $awarded = $cache->{"$_:$problemID:$part:awarded"};
548: $totalAwarded += $awarded;
549:
550: if($code eq '*') {
551: $correct++;
552: if($tries == 1) {
553: $totalFirst++;
554: }
555: } elsif($code eq '+') {
556: $correctByOverride++;
557: }
558: }
559:
1.27 ! stredwic 560: my $studentTriesJoined = join(':::', @studentTries);
1.19 stredwic 561: $problemData{$id.':sequenceTitle'} =
562: $cache->{$sequence.':title'};
563: $problemData{$id.':studentCount'} = $studentCount;
564: $problemData{$id.':totalTries'} = $totalTries;
1.27 ! stredwic 565: $problemData{$id.':studentTries'} = $studentTriesJoined;
1.19 stredwic 566: $problemData{$id.':totalAwarded'} = $totalAwarded;
567: $problemData{$id.':correct'} = $correct;
568: $problemData{$id.':correctByOverride'} = $correctByOverride;
569: $problemData{$id.':wrong'} = $studentCount -
570: ($correct + $correctByOverride);
571: $problemData{$id.':maxTries'} = $maxTries;
572: $problemData{$id.':totalFirst'} = $totalFirst;
573: }
574: }
575: }
576:
1.24 stredwic 577: my @upperStudents1=();
578: my @lowerStudents1=();
579: my @upperStudents2=();
580: my @lowerStudents2=();
581: my $upperCount = int(0.27*scalar(@$students));
582: # Discriminant Factor criterion 1
583: my $sortedStudents = &SortDivideByTries($students,$cache,':totalAwarded');
584:
585: for(my $i=0; $i<$upperCount; $i++) {
586: push(@lowerStudents1, $sortedStudents->[$i]);
587: push(@upperStudents1, $sortedStudents->[(scalar(@$students)-$i-1)]);
588: }
589:
590: $problemData{'studentsUpperListCriterion1'}=join(':::', @upperStudents1);
591: $problemData{'studentsLowerListCriterion1'}=join(':::', @lowerStudents1);
592:
593: # Discriminant Factor criterion 2
594: $sortedStudents = &SortDivideByTries($students, $cache, ':totalSolved');
595:
596: for(my $i=0; $i<$upperCount; $i++) {
597: push(@lowerStudents2, $sortedStudents->[$i]);
598: push(@upperStudents2, $sortedStudents->[(scalar(@$students)-$i-1)]);
599: }
600: $problemData{'studentsUpperListCriterion2'}=join(':::', @upperStudents2);
601: $problemData{'studentsLowerListCriterion2'}=join(':::', @lowerStudents2);
602:
1.21 stredwic 603: $problemData{'problemList'} = join(':::', @problemList);
1.19 stredwic 604:
605: return \%problemData;
606: }
607:
1.24 stredwic 608: sub SortDivideByTries {
609: my ($toSort, $data, $sortOn)=@_;
610: my @orderedData = sort { ($data->{$a.':totalTries'}) ?
611: ($data->{$a.$sortOn}/$data->{$a.':totalTries'}):0
612: <=>
613: ($data->{$b.':totalTries'}) ?
614: ($data->{$b.$sortOn}/$data->{$b.':totalTries'}):0
615: } @$toSort;
616:
617: return \@orderedData;
618: }
619:
1.19 stredwic 620: sub SortProblems {
1.26 stredwic 621: my ($problemData,$sortBy,$sortProblems,$ascend)=@_;
1.19 stredwic 622:
1.21 stredwic 623: my @problems = split(':::', $problemData->{'problemList'});
1.19 stredwic 624: if($sortBy eq "Homework Sets Order") {
1.21 stredwic 625: return \@problems;
1.19 stredwic 626: }
627:
628: my $data;
629:
630: if ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
631: elsif($sortBy eq "Tries") { $data = ':totalTries'; }
632: elsif($sortBy eq "Mod") { $data = ':maxTries'; }
633: elsif($sortBy eq "Mean") { $data = ':mean'; }
634: elsif($sortBy eq "#YES") { $data = ':correct'; }
635: elsif($sortBy eq "#yes") { $data = ':correctByOverride'; }
636: elsif($sortBy eq "%Wrng") { $data = ':percentWrong'; }
637: elsif($sortBy eq "DoDiff") { $data = ':degreeOfDifficulty'; }
638: elsif($sortBy eq "S.D.") { $data = ':standardDeviation'; }
639: elsif($sortBy eq "Skew.") { $data = ':skewness'; }
1.27 ! stredwic 640: elsif($sortBy eq "D.F.1st") { $data = ':discriminationFactor1'; }
! 641: elsif($sortBy eq "D.F.2nd") { $data = ':discriminationFactor2'; }
1.21 stredwic 642: else { return \@problems; }
1.19 stredwic 643:
1.26 stredwic 644: my %temp;
1.27 ! stredwic 645: my @sequenceList=();
1.26 stredwic 646: foreach(@problems) {
647: my ($sequence) = split(':', $_);
1.27 ! stredwic 648:
! 649: my @array=();
! 650: my $tempArray;
! 651: if(defined($temp{$sequence})) {
! 652: $tempArray = $temp{$sequence};
! 653: } else {
! 654: push(@sequenceList, $sequence);
! 655: $tempArray = \@array;
! 656: $temp{$sequence} = $tempArray;
! 657: }
! 658:
! 659: push(@$tempArray, $_);
1.26 stredwic 660: }
661:
662: my @orderedProblems;
663: if($sortProblems eq "Sort Within Sequence") {
1.27 ! stredwic 664: foreach(keys(%temp)) {
! 665: my $tempArray = $temp{$_};
! 666: my @tempOrder =
! 667: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
! 668: @$tempArray;
! 669: $temp{$_} = \@tempOrder;
! 670: }
! 671: foreach(@sequenceList) {
! 672: my $tempArray = $temp{$_};
! 673: @orderedProblems = (@orderedProblems, @$tempArray);
! 674: }
1.26 stredwic 675: } else {
676: @orderedProblems =
677: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
678: @problems;
679: }
680:
1.19 stredwic 681: if($ascend eq 'Descending') {
682: @orderedProblems = reverse(@orderedProblems);
683: }
684:
1.21 stredwic 685: return \@orderedProblems;
1.19 stredwic 686: }
687:
688: sub CalculateStatistics {
1.24 stredwic 689: my ($data, $cache)=@_;
1.19 stredwic 690:
1.21 stredwic 691: my @problems = split(':::', $data->{'problemList'});
692: foreach(@problems) {
1.19 stredwic 693: # Mean
1.27 ! stredwic 694: my $mean = ($data->{$_.':studentCount'}) ?
1.19 stredwic 695: ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
1.27 ! stredwic 696: $data->{$_.':mean'} = sprintf("%.2f", $mean);
1.19 stredwic 697:
698: # %Wrong
1.27 ! stredwic 699: my $pw = ($data->{$_.':studentCount'}) ?
1.19 stredwic 700: (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :
701: 100.0;
1.27 ! stredwic 702: $data->{$_.':percentWrong'} = sprintf("%.1f", $pw);
1.19 stredwic 703:
704: # Degree of Difficulty
1.27 ! stredwic 705: my $dod = ($data->{$_.':totalTries'}) ?
1.19 stredwic 706: (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
707: $data->{$_.':totalTries'})) : 0;
708:
1.27 ! stredwic 709: $data->{$_.':degreeOfDifficulty'} = sprintf("%.2f", $dod);
! 710:
1.19 stredwic 711: # Factor in mean
1.27 ! stredwic 712: my @studentTries = split(':::', $data->{$_.':studentTries'});
! 713: foreach(my $index=0; $index < scalar(@studentTries); $index++) {
! 714: $studentTries[$index] -= $mean;
1.19 stredwic 715: }
716: my $sumSquared = 0;
717: my $sumCubed = 0;
1.27 ! stredwic 718: foreach(@studentTries) {
1.19 stredwic 719: my $squared = ($_ * $_);
720: my $cubed = ($squared * $_);
721: $sumSquared += $squared;
722: $sumCubed += $cubed;
723: }
724:
725: # Standard deviation
1.27 ! stredwic 726: my $standardDeviation;
! 727: if($data->{$_.':studentCount'} - 1 > 0) {
! 728: $standardDeviation = (sqrt($sumSquared)) /
! 729: ($data->{$_.':studentCount'} - 1);
! 730: } else {
! 731: $standardDeviation = 0.0;
! 732: }
! 733: $data->{$_.':standardDeviation'} = sprintf("%.1f", $standardDeviation);
1.19 stredwic 734:
735: # Skewness
1.27 ! stredwic 736: my $skew;
! 737: if($standardDeviation > 0.0999 && $data->{$_.':studentCount'} > 0) {
! 738: $skew = (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) /
! 739: ($standardDeviation *
! 740: $standardDeviation *
! 741: $standardDeviation));
! 742: } else {
! 743: $skew = 0.0;
! 744: }
! 745:
! 746: $data->{$_.':skewness'} = sprintf("%.1f", $skew);
1.19 stredwic 747:
748: # Discrimination Factor 1
1.24 stredwic 749: my ($sequence, $problem, $part) = split(':', $_);
1.19 stredwic 750:
1.24 stredwic 751: my @upper1 = split(':::', $data->{'studentsUpperListCriterion1'});
752: my @lower1 = split(':::', $data->{'studentsLowerListCriterion1'});
1.19 stredwic 753:
1.24 stredwic 754: my $upper1Sum=0;
755: foreach my $name (@upper1) {
756: $upper1Sum += $cache->{"$name:$problem:$part:awarded"};
757: }
1.25 stredwic 758: $upper1Sum = (scalar(@upper1)) ? ($upper1Sum/(scalar(@upper1))) : 0;
1.19 stredwic 759:
1.24 stredwic 760: my $lower1Sum=0;
761: foreach my $name (@lower1) {
762: $lower1Sum += $cache->{"$name:$problem:$part:awarded"};
1.4 minaeibi 763: }
1.25 stredwic 764: $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0;
1.4 minaeibi 765:
1.27 ! stredwic 766: my $df1 = $upper1Sum - $lower1Sum;
! 767: $data->{$_.':discriminationFactor1'} = sprintf("%.2f", $df1);
1.4 minaeibi 768:
1.24 stredwic 769: # Discrimination Factor 2
770: my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'});
771: my @lower2 = split(':::', $data->{'studentsLowerListCriterion2'});
1.1 stredwic 772:
1.24 stredwic 773: my $upper2Sum=0;
774: foreach my $name (@upper2) {
775: $upper2Sum += $cache->{"$name:$problem:$part:awarded"};
776: }
1.25 stredwic 777: $upper2Sum = (scalar(@upper2)) ? ($upper2Sum/(scalar(@upper2))) : 0;
1.14 minaeibi 778:
1.24 stredwic 779: my $lower2Sum=0;
780: foreach my $name (@lower2) {
781: $lower2Sum += $cache->{"$name:$problem:$part:awarded"};
1.22 stredwic 782: }
1.25 stredwic 783: $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0;
1.22 stredwic 784:
1.27 ! stredwic 785: my $df2 = $upper2Sum - $lower2Sum;
! 786: $data->{$_.':discriminationFactor2'} = sprintf("%.2f", $df2);
1.16 minaeibi 787: }
788:
789: return;
1.1 stredwic 790: }
1.24 stredwic 791:
792: #---- END Problem Statistics Web Page ----------------------------------------
1.4 minaeibi 793:
1.1 stredwic 794: 1;
795: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>