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