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