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