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