1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonproblemstatistics.pm,v 1.24 2002/08/14 13:13:37 stredwic 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 BuildProblemStatisticsPage {
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 database.');
56: return;
57: }
58:
59: my $Ptr = '';
60: $Ptr .= '<table border="0"><tbody>';
61: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
62: $Ptr .= '<td align="left">';
63: $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
64: 'Statistics');
65: $Ptr .= '</td></tr>'."\n";
66: $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
67: $Ptr .= '<td align="left">'."\n";
68: $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
69: $cache{'ProblemStatisticsAscend'},
70: 'ProblemStatistics',
71: 'Statistics');
72: $Ptr .= '</td></tr>'."\n";
73: $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
74: $cache{'DisplayLegend'});
75: $Ptr .= '</table>';
76: if($cache{'DisplayLegend'} eq 'Show Legend') {
77: $Ptr .= &ProblemStatisticsLegend();
78: }
79: $r->print($Ptr);
80: $r->rflush();
81:
82: my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
83: "Mean","#YES","#yes","%Wrng","DoDiff",
84: "S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");
85: my $color=&setbgcolor(0);
86:
87: # my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
88: # my ($upper, $lower) = &Discriminant(\%discriminant,$r);
89: if(!defined($cache{'StatisticsCached'})) {
90: if(defined($cache{'StatisticsCached'})) {
91: untie(%cache);
92: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
93: $r->print('Unable to tie database.');
94: return;
95: }
96: my @statkeys = split(':::', $cache{'StatisticsKeys'});
97: delete $cache{'StatisticsKeys'};
98: delete $cache{'StatisticsCached'};
99: foreach(@statkeys) {
100: delete $cache{$_};
101: }
102: }
103: untie(%cache);
104: &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
105: 'true',
106: $cacheDB,
107: 'true',
108: 'true',
109: $courseID,
110: $r, $c);
111: if($c->aborted()) { return; }
112:
113: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
114: $r->print('Unable to tie database.');
115: return;
116: }
117: my ($problemData) = &ExtractStudentData(\%cache, $students);
118: &CalculateStatistics($problemData, \%cache);
119: untie(%cache);
120:
121: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
122: $r->print('Unable to tie database.');
123: return;
124: }
125: foreach(keys(%$problemData)) {
126: $cache{$_} = $problemData->{$_};
127: }
128: $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
129: $cache{'StatisticsCached'} = 'true';
130: untie(%cache);
131:
132: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
133: $r->print('Unable to tie database.');
134: return;
135: }
136: }
137: my $orderedProblems = &SortProblems(\%cache,
138: $cache{'ProblemStatisticsSort'},
139: $cache{'ProblemStatisticsAscend'});
140: &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, $orderedProblems,
141: \@Header, $r, $color);
142: untie(%cache);
143:
144: return;
145: }
146:
147: sub BuildGraphicChart {
148: my ($graph,$cacheDB,$courseDescription,$r)=@_;
149: my %cache;
150: my $max = 0;
151:
152: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
153: return '<html><body>Unable to tie database.</body></html>';
154: }
155:
156: my @problems = split(':::', $cache{'problemList'});
157: my @values = ();
158: foreach (@problems) {
159: my $data = 0;
160: if($graph eq 'DoDiffGraph') {
161: $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
162: } else {
163: $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
164: }
165: if($max < $data) {
166: $max = $data;
167: }
168: push(@values, $data);
169: }
170: untie(%cache);
171:
172: my $sendValues = join(',', @values);
173: # my $sendCount = $#values;
174: my $sendCount = scalar(@values);
175:
176: my $title = '';
177: if($graph eq 'DoDiffGraph') {
178: $title = 'Degree-of-Difficulty';
179: } else {
180: $title = 'Wrong-Percentage';
181: }
182: my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount,
183: $sendValues);
184:
185: $r->print('</form>'."\n");
186: $r->print('<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData)).'" border="1" />');
187: $r->print('<form>'."\n");
188:
189: return;
190: }
191:
192: #---- Problem Statistics Web Page ---------------------------------------
193:
194: sub CreateProblemStatisticsTableHeading {
195: my ($headings,$r)=@_;
196:
197: my $Str='';
198: $Str .= '<tr>'."\n";
199: $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
200: foreach(@$headings) {
201: $Str .= '<th bgcolor="#ffffe6">'.'<a href="/adm/statistics?reportSelected=';
202: $Str .= &Apache::lonnet::escape('Problem Statistics');
203: $Str .= '&ProblemStatisticsSort=';
204: $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a> </th>'."\n";
205: }
206: $Str .= "\n".'</tr>'."\n";
207:
208: return $Str;
209: }
210:
211: sub BuildStatisticsTable {
212: my ($cache,$displayFormat,$orderedProblems,$headings,$r,$color)=@_;
213:
214: #6666666
215: # my $file="/home/httpd/perl/tmp/183d.txt";
216: # open(OUT, ">$file");
217: #6666666
218: ## &Apache::lonstatistics::Create_PrgWin($r);
219: ##777777
220: ## my (%Activity) = &LoadActivityLog();
221: ## $r->print('<script>popwin.document.popremain.remaining.value="'.
222: ## 'Loading Discussion...";</script>');
223: ## my ($doDiffFile) = &LoadDoDiffFile();
224:
225: ##777777
226: ## $Str .= &Classify($discriminantFactor, $students);
227:
228: if($displayFormat ne 'Display CSV Format') {
229: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
230: $r->print('<table border="0" cellpadding="3">'."\n");
231: $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
232: } else {
233: $r->print('<br>');
234: }
235:
236: my $count = 1;
237: foreach(@$orderedProblems) {
238: my ($sequence,$problem,$part)=split(':', $_);
239: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' &&
240: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
241: next;
242: }
243:
244: my $ref = '<a href="'.$cache->{$problem.':source'}.
245: '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
246: # my $ref = $cache->{$problem.':title'};
247: my $title = $cache->{$problem.':title'};
248: my $source = 'source';
249: my $tableData = join('&', $ref, $title, $source,
250: $cache->{$_.':studentCount'},
251: $cache->{$_.':totalTries'},
252: $cache->{$_.':maxTries'},
253: sprintf("%.2f", $cache->{$_.':mean'}),
254: $cache->{$_.':correct'},
255: $cache->{$_.':correctByOverride'},
256: sprintf("%.1f", $cache->{$_.':percentWrong'}),
257: sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}),
258: sprintf("%.1f", $cache->{$_.':standardDeviation'}),
259: sprintf("%.1f", $cache->{$_.':skewness'}),
260: sprintf("%.2f", $cache->{$_.':discriminationFactor1'}),
261: sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),
262: 0); # 0 is for discussion, need to figure out
263:
264: #6666666
265: # $r->print('<br>'.$out.'&'.$DoD);
266: # print (OUT $out.'@'.$DoD.'&');
267: #6666666
268:
269: #check with Gerd
270: # $urlres=~/^(\w+)\/(\w+)/;
271: # if ($StdNo) {
272: # &Apache::lonnet::put('nohist_resevaldata',\%storestats,
273: # $1,$2);
274: # }
275: #-------------------------------- Row of statistical table
276: &TableRow($displayFormat,$tableData,$count,$r,$color);
277: $count++;
278: }
279: if($cache->{'DisplayFormat'} ne 'Display CSV Format') {
280: $r->print('</table>'."\n");
281: }
282: $r->print('</td></tr></table>');
283: #6666666
284: # close( OUT );
285: #666666
286: return;
287: }
288:
289: sub TableRow {
290: my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
291: my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
292: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);
293: my $Ptr;
294: if($displayFormat eq 'Display CSV Format') {
295: $Ptr="\n".'<br>'.
296: "\n".'"'.$RealIdx.'",'.
297: "\n".'"'.$title.'",'.
298: "\n".'"'.$source.'",'.
299: "\n".'"'.$StdNo.'",'.
300: "\n".'"'.$TotalTries.'",'.
301: "\n".'"'.$MxTries.'",'.
302: "\n".'"'.$Avg.'",'.
303: "\n".'"'.$YES.'",'.
304: "\n".'"'.$Override.'",'.
305: "\n".'"'.$Wrng.'",'.
306: "\n".'"'.$DoD.'",'.
307: "\n".'"'.$SD.'",'.
308: "\n".'"'.$Sk.'",'.
309: "\n".'"'.$_D1.'",'.
310: "\n".'"'.$_D2.'"'.
311: "\n".'"'.$DiscNo.'"';
312:
313: $r->print("\n".$Ptr);
314: } else {
315: $Ptr="\n".'<tr>'.
316: "\n".'<td bgcolor="#ffffe6">'.$RealIdx.'</td>'.
317: "\n".'<td bgcolor="#ffffe6">'.$ref.'</td>'.
318: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
319: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
320: "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
321: "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
322: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
323: "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
324: "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
325: "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
326: "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
327: "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
328: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
329: "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
330: "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
331: $r->print("\n".$Ptr.'</tr>' );
332: }
333:
334: return;
335: }
336:
337: # For loading the colored table for display or un-colored for print
338: sub setbgcolor {
339: my $PrintTable=shift;
340: my %color;
341: if ($PrintTable){
342: $color{"gb"}="#FFFFFF";
343: $color{"red"}="#FFFFFF";
344: $color{"yellow"}="#FFFFFF";
345: $color{"green"}="#FFFFFF";
346: $color{"purple"}="#FFFFFF";
347: } else {
348: $color{"gb"}="#DDFFFF";
349: $color{"red"}="#FFDDDD";
350: $color{"yellow"}="#EEFFCC";
351: $color{"green"}="#DDFFDD";
352: $color{"purple"}="#FFDDFF";
353: }
354:
355: return \%color;
356: }
357:
358: sub ProblemStatisticsButtons {
359: my ($displayFormat, $displayLegend)=@_;
360:
361: my $Ptr = '<tr><td></td><td align="left">';
362: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
363: $Ptr .= 'value="DoDiff Graph" />'."\n";
364: $Ptr .= ' ';
365: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
366: $Ptr .= 'value="%Wrong Graph" />'."\n";
367: $Ptr .= '</td></tr><tr><td></td><td>'."\n";
368: $Ptr .= '<input type="submit" name="DisplayLegend" ';
369: if($displayLegend eq 'Show Legend') {
370: $Ptr .= 'value="Hide Legend" />'."\n";
371: } else {
372: $Ptr .= 'value="Show Legend" />'."\n";
373: }
374: $Ptr .= ' ';
375: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
376: if($displayFormat eq 'Display CSV Format') {
377: $Ptr .= 'value="Display Table Format" />'."\n";
378: } else {
379: $Ptr .= 'value="Display CSV Format" />'."\n";
380: }
381: $Ptr .= '</td></tr>';
382:
383: return $Ptr;
384: }
385:
386: sub ProblemStatisticsLegend {
387: my $Ptr = '';
388: $Ptr = '<table border="0">';
389: $Ptr .= '<tr><td>';
390: $Ptr .= '<b>#Stdnts</b></td>';
391: $Ptr .= '<td>Total number of students attempted the problem.';
392: $Ptr .= '</td></tr><tr><td>';
393: $Ptr .= '<b>Tries</b></td>';
394: $Ptr .= '<td>Total number of tries for solving the problem.';
395: $Ptr .= '</td></tr><tr><td>';
396: $Ptr .= '<b>Mod</b></td>';
397: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
398: $Ptr .= '</td></tr><tr><td>';
399: $Ptr .= '<b>Mean</b></td>';
400: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
401: $Ptr .= '</td></tr><tr><td>';
402: $Ptr .= '<b>#YES</b></td>';
403: $Ptr .= '<td>Number of students solved the problem correctly.';
404: $Ptr .= '</td></tr><tr><td>';
405: $Ptr .= '<b>#yes</b></td>';
406: $Ptr .= '<td>Number of students solved the problem by override.';
407: $Ptr .= '</td></tr><tr><td>';
408: $Ptr .= '<b>%Wrong</b></td>';
409: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
410: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
411: $Ptr .= '</td></tr><tr><td>';
412: $Ptr .= '<b>DoDiff</b></td>';
413: $Ptr .= '<td>Degree of Difficulty of the problem. ';
414: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
415: $Ptr .= '</td></tr><tr><td>';
416: $Ptr .= '<b>S.D.</b></td>';
417: $Ptr .= '<td>Standard Deviation of the tries. ';
418: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
419: $Ptr .= 'where Xi denotes every student\'s tries ]';
420: $Ptr .= '</td></tr><tr><td>';
421: $Ptr .= '<b>Skew.</b></td>';
422: $Ptr .= '<td>Skewness of the students tries.';
423: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
424: $Ptr .= '</td></tr><tr><td>';
425: $Ptr .= '<b>Dis.F.</b></td>';
426: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
427: $Ptr .= 'problem according to a Criterion<br>';
428: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
429: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
430: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
431: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
432: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
433: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
434: $Ptr .= '</td></tr>';
435: $Ptr .= '<tr><td><b>Disc.</b></td>';
436: $Ptr .= '<td>Number of Students had at least one discussion.';
437: $Ptr .= '</td></tr></table>';
438:
439: return $Ptr;
440: }
441:
442: #------- Processing upperlist and lowerlist according to each problem
443:
444: sub ExtractStudentData {
445: my ($cache, $students)=@_;
446:
447: #$Apache::lonxml::debug=1;
448: #&Apache::lonhomework::showhash(%$cache);
449: #$Apache::lonxml::debug=0;
450:
451: my @problemList=();
452: my %problemData;
453: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
454: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
455: foreach my $part (split(/\:/,$cache->{$sequence.':'.
456: $problemID.
457: ':parts'})) {
458: my $id = $sequence.':'.$problemID.':'.$part;
459: push(@problemList, $id);
460: my $totalTries = 0;
461: my $totalAwarded = 0;
462: my $correct = 0;
463: my $correctByOverride = 0;
464: my $studentCount = 0;
465: my $maxTries = 0;
466: my $totalFirst = 0;
467: my @studentTries=();
468: foreach(@$students) {
469: my $code = $cache->{"$_:$problemID:$part:code"};
470:
471: if(defined($cache->{$_.':error'}) || $code eq ' ' ||
472: $cache->{"$_:$problemID:NoVersion"} eq 'true') {
473: next;
474: }
475:
476: $studentCount++;
477: my $tries = $cache->{"$_:$problemID:$part:tries"};
478: if($maxTries < $tries) {
479: $maxTries = $tries;
480: }
481: $totalTries += $tries;
482: push(@studentTries, $tries);
483:
484: my $awarded = $cache->{"$_:$problemID:$part:awarded"};
485: $totalAwarded += $awarded;
486:
487: if($code eq '*') {
488: $correct++;
489: if($tries == 1) {
490: $totalFirst++;
491: }
492: } elsif($code eq '+') {
493: $correctByOverride++;
494: }
495: }
496:
497: $problemData{$id.':sequenceTitle'} =
498: $cache->{$sequence.':title'};
499: $problemData{$id.':studentCount'} = $studentCount;
500: $problemData{$id.':totalTries'} = $totalTries;
501: $problemData{$id.':studentTries'} = \@studentTries;
502: $problemData{$id.':totalAwarded'} = $totalAwarded;
503: $problemData{$id.':correct'} = $correct;
504: $problemData{$id.':correctByOverride'} = $correctByOverride;
505: $problemData{$id.':wrong'} = $studentCount -
506: ($correct + $correctByOverride);
507: $problemData{$id.':maxTries'} = $maxTries;
508: $problemData{$id.':totalFirst'} = $totalFirst;
509: }
510: }
511: }
512:
513: my @upperStudents1=();
514: my @lowerStudents1=();
515: my @upperStudents2=();
516: my @lowerStudents2=();
517: my $upperCount = int(0.27*scalar(@$students));
518: # Discriminant Factor criterion 1
519: my $sortedStudents = &SortDivideByTries($students,$cache,':totalAwarded');
520:
521: for(my $i=0; $i<$upperCount; $i++) {
522: push(@lowerStudents1, $sortedStudents->[$i]);
523: push(@upperStudents1, $sortedStudents->[(scalar(@$students)-$i-1)]);
524: }
525:
526: $problemData{'studentsUpperListCriterion1'}=join(':::', @upperStudents1);
527: $problemData{'studentsLowerListCriterion1'}=join(':::', @lowerStudents1);
528:
529: # Discriminant Factor criterion 2
530: $sortedStudents = &SortDivideByTries($students, $cache, ':totalSolved');
531:
532: for(my $i=0; $i<$upperCount; $i++) {
533: push(@lowerStudents2, $sortedStudents->[$i]);
534: push(@upperStudents2, $sortedStudents->[(scalar(@$students)-$i-1)]);
535: }
536: $problemData{'studentsUpperListCriterion2'}=join(':::', @upperStudents2);
537: $problemData{'studentsLowerListCriterion2'}=join(':::', @lowerStudents2);
538:
539: $problemData{'problemList'} = join(':::', @problemList);
540: # $Discussed=0;
541: # if($Discuss->{"$name:$problem"}) {
542: # $TotDiscuss++;
543: # $Discussed=1;
544: # }
545:
546: return \%problemData;
547: }
548:
549: sub SortDivideByTries {
550: my ($toSort, $data, $sortOn)=@_;
551: my @orderedData = sort { ($data->{$a.':totalTries'}) ?
552: ($data->{$a.$sortOn}/$data->{$a.':totalTries'}):0
553: <=>
554: ($data->{$b.':totalTries'}) ?
555: ($data->{$b.$sortOn}/$data->{$b.':totalTries'}):0
556: } @$toSort;
557:
558: return \@orderedData;
559: }
560:
561: sub SortProblems {
562: my ($problemData,$sortBy,$ascend)=@_;
563:
564: my @problems = split(':::', $problemData->{'problemList'});
565: if($sortBy eq "Homework Sets Order") {
566: return \@problems;
567: }
568:
569: my $data;
570:
571: if ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
572: elsif($sortBy eq "Tries") { $data = ':totalTries'; }
573: elsif($sortBy eq "Mod") { $data = ':maxTries'; }
574: elsif($sortBy eq "Mean") { $data = ':mean'; }
575: elsif($sortBy eq "#YES") { $data = ':correct'; }
576: elsif($sortBy eq "#yes") { $data = ':correctByOverride'; }
577: elsif($sortBy eq "%Wrng") { $data = ':percentWrong'; }
578: elsif($sortBy eq "DoDiff") { $data = ':degreeOfDifficulty'; }
579: elsif($sortBy eq "S.D.") { $data = ':standardDeviation'; }
580: elsif($sortBy eq "Skew.") { $data = ':skewness'; }
581: elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }
582: elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }
583: elsif($sortBy eq "Disc.") { $data = ''; }
584: else { return \@problems; }
585:
586: my @orderedProblems =
587: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
588: @problems;
589: if($ascend eq 'Descending') {
590: @orderedProblems = reverse(@orderedProblems);
591: }
592:
593: return \@orderedProblems;
594: }
595:
596: sub CalculateStatistics {
597: my ($data, $cache)=@_;
598:
599: my @problems = split(':::', $data->{'problemList'});
600: foreach(@problems) {
601: # Mean
602: $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ?
603: ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
604:
605: # %Wrong
606: $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ?
607: (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :
608: 100.0;
609:
610: # Degree of Difficulty
611: $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ?
612: (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
613: $data->{$_.':totalTries'})) : 0;
614:
615: # Factor in mean
616: my $studentTries = $data->{$_.':studentTries'};
617: foreach(my $index=0; $index < scalar(@$studentTries); $index++) {
618: $studentTries->[$index] -= $data->{$_.':mean'};
619: }
620: my $sumSquared = 0;
621: my $sumCubed = 0;
622: foreach(@$studentTries) {
623: my $squared = ($_ * $_);
624: my $cubed = ($squared * $_);
625: $sumSquared += $squared;
626: $sumCubed += $cubed;
627: }
628:
629: # Standard deviation
630: $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ?
631: ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0;
632:
633: # Skewness
634: my $standardDeviation = $data->{$_.':standardDeviation'};
635: $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ?
636: (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) /
637: ($standardDeviation * $standardDeviation * $standardDeviation)) :
638: 0;
639:
640: # Discrimination Factor 1
641: my ($sequence, $problem, $part) = split(':', $_);
642:
643: my @upper1 = split(':::', $data->{'studentsUpperListCriterion1'});
644: my @lower1 = split(':::', $data->{'studentsLowerListCriterion1'});
645:
646: my $upper1Sum=0;
647: foreach my $name (@upper1) {
648: $upper1Sum += $cache->{"$name:$problem:$part:awarded"};
649: }
650: $upper1Sum /= (scalar(@upper1)) ? (scalar(@upper1)) : 0;
651:
652: my $lower1Sum=0;
653: foreach my $name (@lower1) {
654: $lower1Sum += $cache->{"$name:$problem:$part:awarded"};
655: }
656: $lower1Sum /= (scalar(@lower1)) ? (scalar(@lower1)) : 0;
657:
658: $data->{$_.':discriminationFactor1'} = $upper1Sum - $lower1Sum;
659:
660: # Discrimination Factor 2
661: my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'});
662: my @lower2 = split(':::', $data->{'studentsLowerListCriterion2'});
663:
664: my $upper2Sum=0;
665: foreach my $name (@upper2) {
666: $upper2Sum += $cache->{"$name:$problem:$part:awarded"};
667: }
668: $upper2Sum /= (scalar(@upper2)) ? (scalar(@upper2)) : 0;
669:
670: my $lower2Sum=0;
671: foreach my $name (@lower2) {
672: $lower2Sum += $cache->{"$name:$problem:$part:awarded"};
673: }
674: $lower2Sum /= (scalar(@lower2)) ? (scalar(@lower2)) : 0;
675:
676: $data->{$_.':discriminationFactor2'} = $upper2Sum - $lower2Sum;
677: }
678:
679: return;
680: }
681:
682: #---- END Problem Statistics Web Page ----------------------------------------
683:
684: 1;
685: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>