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