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