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