1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonproblemstatistics.pm,v 1.35 2002/11/01 22:09:39 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/26,4/7,5/6 Behrouz Minaei
34: # 5/12,5/26,7/16,7/29,8/5,10/31 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:
47: sub InitializeProblemStatistics {
48: my ($cacheDB, $students, $courseID, $c, $r)=@_;
49: my %cache;
50:
51: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
52: $r->print('Unable to tie database1.');
53: return ('ERROR', undef);
54: }
55:
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:
80: my $isNotCached = 0;
81: my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
82: $cache{'StatisticsLastStatus'} : 'Nothing';
83: my $whichStudents = join(':::',sort(@$students));
84: if(!defined($cache{'StatisticsCached'}) ||
85: $lastStatus ne $cache{'Status'} ||
86: $whichStudents ne $cache{'StatisticsWhichStudents'}) {
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{$_};
101: }
102: }
103:
104: untie(%cache);
105: if($isNotCached) {
106: &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
107: 'true',
108: $cacheDB,
109: 'true',
110: 'true',
111: $courseID,
112: $r, $c);
113: }
114: if($c->aborted()) { return ('ERROR', undef); }
115:
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);
123: &CalculateStatistics($problemData, \%cache, $courseID);
124: }
125: untie(%cache);
126:
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) {
132: foreach(keys(%$problemData)) {
133: $cache{$_} = $problemData->{$_};
134: }
135: $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
136: $cache{'StatisticsCached'} = 'true';
137: $cache{'StatisticsLastStatus'} = $cache{'Status'};
138: $cache{'StatisticsWhichStudents'} = $whichStudents;
139: }
140: untie(%cache);
141:
142: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
143: $r->print('Unable to tie database.5');
144: return ('ERROR', undef);
145: }
146:
147: my $orderedProblems = &SortProblems(\%cache,
148: $cache{'ProblemStatisticsSort'},
149: $cache{'SortProblems'},
150: $cache{'ProblemStatisticsAscend'});
151: untie(%cache);
152:
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",
161: "S.D.","Skew.","D.F.1st","D.F.2nd");
162: my $color=&setbgcolor(0);
163: my %cache;
164:
165: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
166: $r->print('Unable to tie database.6');
167: return;
168: }
169: my $Ptr = '';
170: $Ptr .= '<table border="0" cellspacing="5"><tbody>';
171: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
172: $Ptr .= '<td align="left">';
173: $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'Statistics',
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(
179: $cache{'ProblemStatisticsAscend'},
180: 'ProblemStatistics',
181: 'Statistics');
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";
192: $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
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)) {
210: $r->print('Unable to tie database.6');
211: return;
212: }
213: &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
214: $cache{'SortProblems'}, $orderedProblems,
215: \@Header, $r, $color);
216: untie(%cache);
217:
218: return;
219: }
220:
221: sub BuildGraphicChart {
222: my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
223: my %cache;
224: my $max = 0;
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: }
235:
236: my $currentSequence = -1;
237: my $sortProblems = 'Sort Within Sequence';
238:
239: my ($result, $orderedProblems) =
240: &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
241: if($result ne 'OK') {
242: return;
243: }
244:
245: my @values = ();
246:
247: foreach(@$orderedProblems) {
248: my ($sequence,$problem,$part)=split(':', $_);
249: if($cache{'StatisticsMaps'} ne 'All Maps' &&
250: $cache{'StatisticsMaps'} ne $cache{$sequence.':title'}) {
251: next;
252: }
253:
254: if( $currentSequence == -1 ||
255: ($sortProblems eq 'Sort Within Sequence' &&
256: $currentSequence != $sequence)) {
257: if($currentSequence != -1) {
258: &DrawGraph(\@values,$courseDescription,$title,$max,$r);
259: }
260: if($sortProblems eq 'Sort Within Sequence') {
261: $r->print('<b>'.$cache{$sequence.':title'}.'</b>');
262: }
263:
264: $currentSequence = $sequence;
265: @values = ();
266: }
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: }
278: untie(%cache);
279:
280: &DrawGraph(\@values,$courseDescription,$title,$max,$r);
281:
282: return;
283: }
284:
285:
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:
307: #---- Problem Statistics Web Page ---------------------------------------
308:
309: sub CreateProblemStatisticsTableHeading {
310: my ($headings,$r)=@_;
311:
312: my $Str='';
313: $Str .= '<tr>'."\n";
314: $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
315: foreach(@$headings) {
316: $Str .= '<th bgcolor="#ffffe6">';
317: $Str .= '<a href="/adm/statistics?reportSelected=';
318: $Str .= &Apache::lonnet::escape('Problem Statistics');
319: $Str .= '&ProblemStatisticsSort=';
320: $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a> </th>'."\n";
321: }
322: $Str .= "\n".'</tr>'."\n";
323:
324: return $Str;
325: }
326:
327: sub BuildStatisticsTable {
328: my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,
329: $r,$color)=@_;
330:
331: my $count = 1;
332: my $currentSequence = -1;
333: foreach(@$orderedProblems) {
334: my ($sequence,$problem,$part)=split(':', $_);
335: if($cache->{'StatisticsMaps'} ne 'All Maps' &&
336: $cache->{'StatisticsMaps'} ne $cache->{$sequence.':title'}) {
337: next;
338: }
339:
340: if($currentSequence == -1 ||
341: ($sortProblems eq 'Sort Within Sequence' &&
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:
363: my $ref = '<a href="'.$cache->{$problem.':source'}.
364: '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
365: my $title = $cache->{$problem.':title'};
366: if($part != 0) {
367: $title .= ' Part '.$part;
368: }
369: my $source = $cache->{$problem.':source'};
370: my $tableData = join('&', $ref, $title, $source,
371: $cache->{$_.':studentCount'},
372: $cache->{$_.':totalTries'},
373: $cache->{$_.':maxTries'},
374: $cache->{$_.':mean'},
375: $cache->{$_.':correct'},
376: $cache->{$_.':correctByOverride'},
377: $cache->{$_.':percentWrong'},
378: $cache->{$_.':degreeOfDifficulty'},
379: $cache->{$_.':standardDeviation'},
380: $cache->{$_.':skewness'},
381: $cache->{$_.':discriminationFactor1'},
382: $cache->{$_.':discriminationFactor2'});
383:
384: &TableRow($displayFormat,$tableData,$count,$r,$color);
385:
386: $count++;
387: }
388: if($displayFormat ne 'Display CSV Format') {
389: $r->print('</table>'."\n");
390: $r->print('</td></tr></table>');
391: } else {
392: $r->print('<br>');
393: }
394:
395: return;
396: }
397:
398: sub TableRow {
399: my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
400: my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
401: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str);
402: my $Ptr;
403: if($displayFormat eq 'Display CSV Format') {
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";
420:
421: $r->print("\n".$Ptr);
422: } else {
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".
437: '<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'."\n";
438: $r->print($Ptr.'</tr>'."\n");
439: }
440:
441: return;
442: }
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:
465: sub ProblemStatisticsButtons {
466: my ($displayFormat, $displayLegend, $sortProblems)=@_;
467:
468: my $Ptr = '<tr><td></td><td align="left">';
469: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
470: $Ptr .= 'value="Plot Degree of Difficulty" />'."\n";
471: $Ptr .= '</td><td align="left">';
472: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
473: $Ptr .= 'value="Plot Percent Wrong" />'."\n";
474: $Ptr .= '</td></tr><tr><td></td><td>'."\n";
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: }
481: $Ptr .= '</td><td align="left">';
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: }
488: $Ptr .= '</td><td align="left">';
489: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
490: if($displayFormat eq 'Display CSV Format') {
491: $Ptr .= 'value="Display Table Format" />'."\n";
492: } else {
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>';
504: $Ptr .= '<b>#Stdnts</b></td>';
505: $Ptr .= '<td>Total number of students attempted the problem.';
506: $Ptr .= '</td></tr><tr><td>';
507: $Ptr .= '<b>Tries</b></td>';
508: $Ptr .= '<td>Total number of tries for solving the problem.';
509: $Ptr .= '</td></tr><tr><td>';
510: $Ptr .= '<b>Mod</b></td>';
511: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
512: $Ptr .= '</td></tr><tr><td>';
513: $Ptr .= '<b>Mean</b></td>';
514: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
515: $Ptr .= '</td></tr><tr><td>';
516: $Ptr .= '<b>#YES</b></td>';
517: $Ptr .= '<td>Number of students solved the problem correctly.';
518: $Ptr .= '</td></tr><tr><td>';
519: $Ptr .= '<b>#yes</b></td>';
520: $Ptr .= '<td>Number of students solved the problem by override.';
521: $Ptr .= '</td></tr><tr><td>';
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) ]';
525: $Ptr .= '</td></tr><tr><td>';
526: $Ptr .= '<b>DoDiff</b></td>';
527: $Ptr .= '<td>Degree of Difficulty of the problem. ';
528: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
529: $Ptr .= '</td></tr><tr><td>';
530: $Ptr .= '<b>S.D.</b></td>';
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>';
535: $Ptr .= '<b>Skew.</b></td>';
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>';
539: $Ptr .= '<b>Dis.F.</b></td>';
540: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
541: $Ptr .= 'problem according to a Criterion<br>';
542: $Ptr .= '<b>[Criterion to group students into %27 Upper Students - ';
543: $Ptr .= 'and %27 Lower Students]</b><br>';
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:
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:
605: my $studentTriesJoined = join(':::', @studentTries);
606: $problemData{$id.':sequenceTitle'} =
607: $cache->{$sequence.':title'};
608: $problemData{$id.':studentCount'} = $studentCount;
609: $problemData{$id.':totalTries'} = $totalTries;
610: $problemData{$id.':studentTries'} = $studentTriesJoined;
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:
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:
648: $problemData{'problemList'} = join(':::', @problemList);
649:
650: return \%problemData;
651: }
652:
653: sub SortDivideByTries {
654: my ($toSort, $data, $sortOn)=@_;
655: my @orderedData = sort { ($data->{$a.':totalTries'}) ?
656: ($data->{$a.$sortOn}/$data->{$a.':totalTries'}):0
657: <=>
658: ($data->{$b.':totalTries'}) ?
659: ($data->{$b.$sortOn}/$data->{$b.':totalTries'}):0
660: } @$toSort;
661:
662: return \@orderedData;
663: }
664:
665: sub SortProblems {
666: my ($problemData,$sortBy,$sortProblems,$ascend)=@_;
667:
668: my @problems = split(':::', $problemData->{'problemList'});
669: if($sortBy eq "Homework Sets Order") {
670: return \@problems;
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'; }
685: elsif($sortBy eq "D.F.1st") { $data = ':discriminationFactor1'; }
686: elsif($sortBy eq "D.F.2nd") { $data = ':discriminationFactor2'; }
687: else { return \@problems; }
688:
689: my %temp;
690: my @sequenceList=();
691: foreach(@problems) {
692: my ($sequence) = split(':', $_);
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, $_);
705: }
706:
707: my @orderedProblems;
708: if($sortProblems eq "Sort Within Sequence") {
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: }
720: } else {
721: @orderedProblems =
722: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
723: @problems;
724: }
725:
726: if($ascend eq 'Descending') {
727: @orderedProblems = reverse(@orderedProblems);
728: }
729:
730: return \@orderedProblems;
731: }
732:
733: sub CalculateStatistics {
734: my ($data, $cache, $courseID)=@_;
735:
736: my @problems = split(':::', $data->{'problemList'});
737: foreach(@problems) {
738: # Mean
739: my $mean = ($data->{$_.':studentCount'}) ?
740: ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
741: $data->{$_.':mean'} = sprintf("%.2f", $mean);
742:
743: # %Wrong
744: my $pw = ($data->{$_.':studentCount'}) ?
745: (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :
746: 100.0;
747: $data->{$_.':percentWrong'} = sprintf("%.1f", $pw);
748:
749: # Degree of Difficulty
750: my $dod = ($data->{$_.':totalTries'}) ?
751: (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
752: $data->{$_.':totalTries'})) : 0;
753:
754: $data->{$_.':degreeOfDifficulty'} = sprintf("%.2f", $dod);
755:
756: # Factor in mean
757: my @studentTries = split(':::', $data->{$_.':studentTries'});
758: foreach(my $index=0; $index < scalar(@studentTries); $index++) {
759: $studentTries[$index] -= $mean;
760: }
761: my $sumSquared = 0;
762: my $sumCubed = 0;
763: foreach(@studentTries) {
764: my $squared = ($_ * $_);
765: my $cubed = ($squared * $_);
766: $sumSquared += $squared;
767: $sumCubed += $cubed;
768: }
769:
770: # Standard deviation
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);
779:
780: # Skewness
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);
792:
793: # Discrimination Factor 1
794: my ($sequence, $problem, $part) = split(':', $_);
795:
796: my @upper1 = split(':::', $data->{'studentsUpperListCriterion1'});
797: my @lower1 = split(':::', $data->{'studentsLowerListCriterion1'});
798:
799: my $upper1Sum=0;
800: foreach my $name (@upper1) {
801: $upper1Sum += $cache->{"$name:$problem:$part:awarded"};
802: }
803: $upper1Sum = (scalar(@upper1)) ? ($upper1Sum/(scalar(@upper1))) : 0;
804:
805: my $lower1Sum=0;
806: foreach my $name (@lower1) {
807: $lower1Sum += $cache->{"$name:$problem:$part:awarded"};
808: }
809: $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0;
810:
811: my $df1 = $upper1Sum - $lower1Sum;
812: $data->{$_.':discriminationFactor1'} = sprintf("%.2f", $df1);
813:
814: # Discrimination Factor 2
815: my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'});
816: my @lower2 = split(':::', $data->{'studentsLowerListCriterion2'});
817:
818: my $upper2Sum=0;
819: foreach my $name (@upper2) {
820: $upper2Sum += $cache->{"$name:$problem:$part:awarded"};
821: }
822: $upper2Sum = (scalar(@upper2)) ? ($upper2Sum/(scalar(@upper2))) : 0;
823:
824: my $lower2Sum=0;
825: foreach my $name (@lower2) {
826: $lower2Sum += $cache->{"$name:$problem:$part:awarded"};
827: }
828: $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0;
829:
830: my $df2 = $upper2Sum - $lower2Sum;
831: $data->{$_.':discriminationFactor2'} = sprintf("%.2f", $df2);
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'}) {
846: &Apache::lonnet::put('nohist_resevaldata',\%storestats,$1,$2);
847: }
848: }
849:
850: return;
851: }
852:
853: #---- END Problem Statistics Web Page ----------------------------------------
854:
855: 1;
856: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>