File:
[LON-CAPA] /
loncom /
interface /
statistics /
lonproblemstatistics.pm
Revision
1.19:
download - view:
text,
annotated -
select for diffs
Tue Aug 13 00:37:18 2002 UTC (22 years ago) by
stredwic
Branches:
MAIN
CVS tags:
HEAD
First, added unescaping of $key in lond dump command.
Next, I added a new way to download student course data. There are now
two functions for storing data, DownloadStudentCourseData and
DownloadStudentCourseDataSeparate. These two functions base their running
on input parameters. The option parameters are whether or not to check
the date for downloading, whether or not to store all the dumped data or
extract out the data you want, whether or not to display a status window.
The extracting data parameter will be best utilized if someone adds in the
ability to send a list of what parameters are desired and perhaps some simple
commands to affect how that data is processed, like tries, sum would
sum record the sum of all the tries for a student. This is just an idea.
Currently, I have all the statistics modules using the extract ability.
This slightly increases in download time, but drastically reduces cache
size. Possible ideas include pushing the extract to the lond side with a
list of parameter/commands, or even downloading everything to a temp cache,
then extract the necessary data into the cache then removing the temp
cache. There are lots of other possibilities, which can change the download
time, cache size, and other factors. Now, only loncoursedata handles the
downloading of data to a hash.
lonstudentassessment was changed slightly to remove ' ' as a link if the
student actually hadn't attempted the problem.
lonproblemanalysis was updated for the new str2hash type functions. There
are a couple of (cludges/fixes) for it. Depending on whether or not the
str2hash type functions are changed, these may or may not need to be
updated.
lonproblemstatistics was drastically overhauled. Most of the processing
was removed. Now, it just does its few statistics functions and outputs
the table. Currently, I broke the graph, discussion column, and
discriminant factor columns. These will be fixed on the next commit soon.
There is also no caching done. This will also be remedied soon. The
problem that will need attention with caching is to know when to update
the statistics cached data when a student's course data is updated.
Lastly, I plan to add perhaps a toggle legend display button, another graph
button(percentage correct), a button to send the CSV format(not just display),
and add a toggle button for sorting within a sequence and sorting all
the problems.
Also, I changed the look and feel to be the same as the class list page.
Also, the displaying of sequence headers and child sequences are not
working. This will be fixed, but thought will be put into how best to
make it look and have a similiar fill for all the table combinations.
1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonproblemstatistics.pm,v 1.19 2002/08/13 00:37:18 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: return '<html><body>Unable to tie database.</body></html>';
56: }
57:
58: my $Ptr = '';
59: $Ptr .= '<table border="0"><tbody>';
60: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
61: $Ptr .= '<td align="left">';
62: $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
63: 'Statistics');
64: $Ptr .= '</td></tr>'."\n";
65: $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
66: $Ptr .= '<td align="left">'."\n";
67: $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
68: $cache{'ProblemStatisticsAscend'},
69: 'ProblemStatistics',
70: 'Statistics');
71: $Ptr .= '</td></tr>'."\n";
72: $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'});
73: $Ptr .= '</table>';
74: $Ptr .= &ProblemStatisticsLegend();
75: $r->print($Ptr);
76: $r->rflush();
77:
78: untie(%cache);
79:
80: &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,'true',
81: $cacheDB,'true',
82: 'true',$courseID,
83: $r, $c);
84: if($c->aborted()) { return; }
85:
86: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
87: return '<html><body>Unable to tie database.</body></html>';
88: }
89:
90: my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
91: "Mean","#YES","#yes","%Wrng","DoDiff",
92: "S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");
93: my $color=&setbgcolor(0);
94:
95: # my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
96: # my ($upper, $lower) = &Discriminant(\%discriminant,$r);
97: my ($problemData) = &ExtractStudentData(\%cache, $students);
98: &CalculateStatistics($problemData);
99: &SortProblems($problemData, $cache{'ProblemStatisticsSort'},
100: $cache{'ProblemStatisticsAscend'});
101: #$TempCache=
102: &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
103: $problemData, \@Header, $r, $color);
104: untie(%cache);
105:
106: # foreach (keys %$TempCache) {
107: # last if ($c->aborted());
108: # if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
109: # $cache{$_}=$TempCache->{$_};
110: # untie(%cache);
111: # }
112: # }
113:
114: # if($c->aborted()) { return; }
115: # untie(%cache);
116:
117: return;
118: }
119:
120:
121: #---- Problem Statistics Web Page ---------------------------------------
122:
123: sub CreateProblemStatisticsTableHeading {
124: my ($headings,$r)=@_;
125:
126: my $Str='';
127: $Str .= '<tr>'."\n";
128: $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
129: foreach(@$headings) {
130: $Str .= '<th bgcolor="#ffffe6">'.'<a href="/adm/statistics?reportSelected=';
131: $Str .= &Apache::lonnet::escape('Problem Statistics');
132: $Str .= '&ProblemStatisticsSort=';
133: $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a> </th>'."\n";
134: }
135: $Str .= "\n".'</tr>'."\n";
136:
137: return $Str;
138: }
139:
140: sub BuildStatisticsTable {
141: my ($cache,$displayFormat,$data,$headings,$r,$color)=@_;
142:
143: #6666666
144: # my $file="/home/httpd/perl/tmp/183d.txt";
145: # open(OUT, ">$file");
146: #6666666
147: ## &Apache::lonstatistics::Create_PrgWin($r);
148: ##777777
149: ## my (%Activity) = &LoadActivityLog();
150: ## $r->print('<script>popwin.document.popremain.remaining.value="'.
151: ## 'Loading Discussion...";</script>');
152: ## my ($doDiffFile) = &LoadDoDiffFile();
153:
154: ##777777
155: ## $Str .= &Classify($discriminantFactor, $students);
156:
157: my %TempCache;
158: my $problems = $data->{'problemList'};
159: if($displayFormat ne 'Display CSV Format') {
160: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
161: $r->print('<table border="0" cellpadding="3">'."\n");
162: $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
163: } else {
164: $r->print('<br>');
165: }
166:
167: my $count = 1;
168: foreach(@$problems) {
169: my ($sequence,$problem,$part)=split(':', $_);
170: # my $problemRef = '<a href="'.$cache->{$problem.':source'}.
171: # '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
172:
173: my $ref = $cache->{$problem.':title'};
174: my $title = $cache->{$problem.':title'};
175: my $source = 'source';
176: my $tableData = join('&', $ref, $title, $source,
177: $data->{$_.':studentCount'},
178: $data->{$_.':totalTries'},
179: $data->{$_.':maxTries'},
180: sprintf("%.2f", $data->{$_.':mean'}),
181: $data->{$_.':correct'},
182: $data->{$_.':correctByOverride'},
183: sprintf("%.1f", $data->{$_.':percentWrong'}),
184: sprintf("%.2f", $data->{$_.':degreeOfDifficulty'}),
185: sprintf("%.1f", $data->{$_.':standardDeviation'}),
186: sprintf("%.1f", $data->{$_.':skewness'}),
187: sprintf("%.2f", $data->{$_.':discriminationFactor1'}),
188: sprintf("%.2f", $data->{$_.':discriminationFactor2'}),
189: 0); # 0 is for discussion, need to figure out
190: # $TempCache{'CacheTable:'.$_}=$join;
191:
192: #6666666
193: # $r->print('<br>'.$out.'&'.$DoD);
194: # print (OUT $out.'@'.$DoD.'&');
195: #6666666
196:
197: #check with Gerd
198: # $urlres=~/^(\w+)\/(\w+)/;
199: # if ($StdNo) {
200: # &Apache::lonnet::put('nohist_resevaldata',\%storestats,
201: # $1,$2);
202: # }
203: #-------------------------------- Row of statistical table
204: &TableRow($displayFormat,$tableData,$count,$r,$color);
205: # $GraphDat->{'GraphGif:'.($count-1)}=$DoD.':'.$Wrng;
206: $count++;
207: }
208: # $TempCache{'ProblemCount'}=$count;
209: if($cache->{'DisplayFormat'} ne 'Display CSV Format') {
210: $r->print('</table>'."\n");
211: }
212: $r->print('</td></tr></table>');
213: #6666666
214: # close( OUT );
215: #666666
216: return \%TempCache;
217: }
218:
219: =pod
220: sub CacheStatisticsTable {
221: my ($state,$cache,$headings,$r,$color)=@_;
222: my @list = ();
223: my %TempCache;
224: my %myHeader = reverse( %$headings );
225: my $pos = $myHeader{$state};
226: if ($pos > 0) {$pos++;}
227: my $p_count = $cache->{'ProblemCount'};
228:
229: for ( my $k=0; $k<$p_count;$k++) {
230: my $key=$cache->{'CacheTable:'.$k};
231: my @Temp=split(/\&/,$key);
232: $list[$k]=$Temp[$pos].'+'.$key;
233: }
234:
235: if ($pos>0) {
236: @list = sort OrderedSort (@list);
237: } else {
238: @list = sort (@list);
239: }
240: my $cIdx=0;
241:
242: if ( $pos == 0 ) {
243: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
244: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' &&
245: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
246: next;
247: }
248: if ($cIdx==$p_count) {
249: return \%TempCache;
250: }
251: $r->print(&CreateProblemStatisticsTableHeading(
252: $cache->{'DisplayFormat'},
253: $cache->{$sequence.':source'},
254: $cache->{$sequence.':title'},
255: $headings,$r));
256:
257: my ($tar)=split(/\&/,$list[$cIdx]);
258: $tar=~s/\+//eg;
259: my ($SqOrd)=split(/\@/,$tar);
260: $sequence+=100;
261: while ($SqOrd==$sequence && $cIdx<$p_count) {
262: my($Pre, $Post) = split(/\+/,$list[$cIdx]);
263: &TableRow($cache,$Post,$cIdx,$cIdx,$r,$color,\%TempCache);
264: $cIdx++;
265: my ($tar)=split(/\&/,$list[$cIdx]);
266: $tar=~s/\+//eg;
267: ($SqOrd)=split(/\@/,$tar);
268: }
269: &CloseTable($cache,$r);
270: }
271: }
272: else {
273: $r->print(&CreateProblemStatisticsTableHeading(
274: $cache->{'DisplayFormat'},
275: 'Sorted by: ',
276: $headings->{$pos-1},
277: $headings,$r));
278: for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
279: my($Pre, $Post) = split(/\+/,$list[$nIndex]);
280: &TableRow($cache,$Post,$nIndex,$nIndex,$r,$color,\%TempCache);
281: }
282: &CloseTable($cache,$r);
283: }
284:
285: return \%TempCache;
286: }
287: =cut
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)=@_;
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 .= ' ';
368: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
369: if($displayFormat eq 'Display CSV Format') {
370: $Ptr .= 'value="Display Table Format" />'."\n";
371: } else {
372: $Ptr .= 'value="Display CSV Format" />'."\n";
373: }
374: $Ptr .= '</td></tr>';
375:
376: return $Ptr;
377: }
378:
379: sub ProblemStatisticsLegend {
380: my $Ptr = '';
381: $Ptr = '<table border="0">';
382: $Ptr .= '<tr><td>';
383: $Ptr .= '<b>#Stdnts</b></td>';
384: $Ptr .= '<td>Total number of students attempted the problem.';
385: $Ptr .= '</td></tr><tr><td>';
386: $Ptr .= '<b>Tries</b></td>';
387: $Ptr .= '<td>Total number of tries for solving the problem.';
388: $Ptr .= '</td></tr><tr><td>';
389: $Ptr .= '<b>Mod</b></td>';
390: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
391: $Ptr .= '</td></tr><tr><td>';
392: $Ptr .= '<b>Mean</b></td>';
393: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
394: $Ptr .= '</td></tr><tr><td>';
395: $Ptr .= '<b>#YES</b></td>';
396: $Ptr .= '<td>Number of students solved the problem correctly.';
397: $Ptr .= '</td></tr><tr><td>';
398: $Ptr .= '<b>#yes</b></td>';
399: $Ptr .= '<td>Number of students solved the problem by override.';
400: $Ptr .= '</td></tr><tr><td>';
401: $Ptr .= '<b>%Wrong</b></td>';
402: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
403: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
404: $Ptr .= '</td></tr><tr><td>';
405: $Ptr .= '<b>DoDiff</b></td>';
406: $Ptr .= '<td>Degree of Difficulty of the problem. ';
407: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
408: $Ptr .= '</td></tr><tr><td>';
409: $Ptr .= '<b>S.D.</b></td>';
410: $Ptr .= '<td>Standard Deviation of the tries. ';
411: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
412: $Ptr .= 'where Xi denotes every student\'s tries ]';
413: $Ptr .= '</td></tr><tr><td>';
414: $Ptr .= '<b>Skew.</b></td>';
415: $Ptr .= '<td>Skewness of the students tries.';
416: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
417: $Ptr .= '</td></tr><tr><td>';
418: $Ptr .= '<b>Dis.F.</b></td>';
419: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
420: $Ptr .= 'problem according to a Criterion<br>';
421: $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
422: $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
423: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
424: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
425: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
426: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
427: $Ptr .= '</td></tr>';
428: $Ptr .= '<tr><td><b>Disc.</b></td>';
429: $Ptr .= '<td>Number of Students had at least one discussion.';
430: $Ptr .= '</td></tr></table>';
431:
432: return $Ptr;
433: }
434:
435: #------- Processing upperlist and lowerlist according to each problem
436:
437: sub ExtractStudentData {
438: my ($cache, $students)=@_;
439:
440: #$Apache::lonxml::debug=1;
441: #&Apache::lonhomework::showhash(%$cache);
442: #$Apache::lonxml::debug=0;
443:
444: my @problemList=();
445: my %problemData;
446: foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
447: if($cache->{'ProblemStatisticsMaps'} ne 'All Maps' &&
448: $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
449: next;
450: }
451:
452: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
453: foreach my $part (split(/\:/,$cache->{$sequence.':'.
454: $problemID.
455: ':parts'})) {
456: my $id = $sequence.':'.$problemID.':'.$part;
457: push(@problemList, $id);
458: my $totalTries = 0;
459: my $totalAwarded = 0;
460: my $correct = 0;
461: my $correctByOverride = 0;
462: my $studentCount = 0;
463: my $maxTries = 0;
464: my $totalFirst = 0;
465: my @studentTries=();
466: foreach(@$students) {
467: my $code = $cache->{"$_:$problemID:$part:code"};
468:
469: if(defined($cache->{$_.':error'}) || $code eq ' ' ||
470: $cache->{"$_:$problemID:NoVersion"} eq 'true') {
471: next;
472: }
473:
474: $studentCount++;
475: my $tries = $cache->{"$_:$problemID:$part:tries"};
476: if($maxTries < $tries) {
477: $maxTries = $tries;
478: }
479: $totalTries += $tries;
480: push(@studentTries, $tries);
481:
482: my $awarded = $cache->{"$_:$problemID:$part:awarded"};
483: $totalAwarded += $awarded;
484:
485: if($code eq '*') {
486: $correct++;
487: if($tries == 1) {
488: $totalFirst++;
489: }
490: } elsif($code eq '+') {
491: $correctByOverride++;
492: }
493: }
494:
495: $problemData{$id.':sequenceTitle'} =
496: $cache->{$sequence.':title'};
497: $problemData{$id.':studentCount'} = $studentCount;
498: $problemData{$id.':totalTries'} = $totalTries;
499: $problemData{$id.':studentTries'} = \@studentTries;
500: $problemData{$id.':totalAwarded'} = $totalAwarded;
501: $problemData{$id.':correct'} = $correct;
502: $problemData{$id.':correctByOverride'} = $correctByOverride;
503: $problemData{$id.':wrong'} = $studentCount -
504: ($correct + $correctByOverride);
505: $problemData{$id.':maxTries'} = $maxTries;
506: $problemData{$id.':totalFirst'} = $totalFirst;
507: }
508: }
509: }
510:
511: $problemData{'problemList'} = \@problemList;
512: # $Discussed=0;
513: # if($Discuss->{"$name:$problem"}) {
514: # $TotDiscuss++;
515: # $Discussed=1;
516: # }
517:
518: return \%problemData;
519: }
520:
521: sub SortProblems {
522: my ($problemData,$sortBy,$ascend)=@_;
523:
524: if($sortBy eq "Homework Sets Order") {
525: return;
526: }
527:
528: my $data;
529:
530: if ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
531: elsif($sortBy eq "Tries") { $data = ':totalTries'; }
532: elsif($sortBy eq "Mod") { $data = ':maxTries'; }
533: elsif($sortBy eq "Mean") { $data = ':mean'; }
534: elsif($sortBy eq "#YES") { $data = ':correct'; }
535: elsif($sortBy eq "#yes") { $data = ':correctByOverride'; }
536: elsif($sortBy eq "%Wrng") { $data = ':percentWrong'; }
537: elsif($sortBy eq "DoDiff") { $data = ':degreeOfDifficulty'; }
538: elsif($sortBy eq "S.D.") { $data = ':standardDeviation'; }
539: elsif($sortBy eq "Skew.") { $data = ':skewness'; }
540: elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }
541: elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }
542: elsif($sortBy eq "Disc.") { $data = ''; }
543: else { return; }
544:
545: my $problems = $problemData->{'problemList'};
546: my @orderedProblems =
547: sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
548: @$problems;
549: if($ascend eq 'Descending') {
550: @orderedProblems = reverse(@orderedProblems);
551: }
552:
553: $problemData->{'problemList'} = \@orderedProblems;
554:
555: return;
556: }
557:
558: sub CalculateStatistics {
559: my ($data)=@_;
560:
561: my $problems = $data->{'problemList'};
562: foreach(@$problems) {
563: # Mean
564: $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ?
565: ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
566:
567: # %Wrong
568: $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ?
569: (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :
570: 100.0;
571:
572: # Degree of Difficulty
573: $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ?
574: (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
575: $data->{$_.':totalTries'})) : 0;
576:
577: # Factor in mean
578: my $studentTries = $data->{$_.':studentTries'};
579: foreach(my $index=0; $index < scalar(@$studentTries); $index++) {
580: $studentTries->[$index] -= $data->{$_.':mean'};
581: }
582: my $sumSquared = 0;
583: my $sumCubed = 0;
584: foreach(@$studentTries) {
585: my $squared = ($_ * $_);
586: my $cubed = ($squared * $_);
587: $sumSquared += $squared;
588: $sumCubed += $cubed;
589: }
590:
591: # Standard deviation
592: $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ?
593: ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0;
594:
595: # Skewness
596: my $standardDeviation = $data->{$_.':standardDeviation'};
597: $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ?
598: (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) /
599: ($standardDeviation * $standardDeviation * $standardDeviation)) :
600: 0;
601:
602: # Discrimination Factor 1
603: $data->{$_.':discriminationFactor1'} = 0;
604:
605: # Discrimination Factor 2
606: $data->{$_.':discriminationFactor2'} = 0;
607: }
608:
609: return;
610: }
611:
612: sub ProcessDiscriminant {
613: my ($List) = @_;
614: my @sortedList = sort (@$List);
615: my $Count = scalar @sortedList;
616: my $Problem;
617: my @Dis;
618: my $Slvd=0;
619: my $tmp;
620: my $Sum1=0;
621: my $Sum2=0;
622: my $nIndex=0;
623: my $nStudent=0;
624: my %Proc=undef;
625: while ($nIndex<$Count) {
626: # $jr->print("<br> $nIndex) $sortedList[$nIndex]");
627: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
628: @Dis=split(/\+/,$tmp);
629: my $Temp = $Problem;
630: do {
631: $nIndex++;
632: $nStudent++;
633: $Sum1 += $Dis[0];
634: $Sum2 += $Dis[1];
635: ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
636: @Dis=split(/\+/,$tmp);
637: } while ( $Problem eq $Temp && $nIndex < $Count );
638: $Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
639: # $jr->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
640: $Sum1=0;
641: $Sum2=0;
642: $nStudent=0;
643: }
644:
645: return %Proc;
646: }
647:
648: #------- Creating Discimination factor
649: sub Discriminant {
650: my ($discriminant)=@_;
651: my @discriminantKeys=keys(%$discriminant);
652: my $Count = scalar @discriminantKeys;
653:
654: my $UpCnt = int(0.27*$Count);
655: my $low=0;
656: my $up=$Count-$UpCnt;
657: my @UpList=();
658: my @LowList=();
659:
660: $Count=0;
661: foreach my $key (sort(@discriminantKeys)) {
662: $Count++;
663: if($low < $UpCnt || $Count > $up) {
664: $low++;
665: my $str=$discriminant->{$key};
666: foreach(split(/\&/,$str)){
667: if($_) {
668: if($low<$UpCnt) { push(@LowList,$_); }
669: else { push(@UpList,$_); }
670: }
671: }
672: }
673: }
674: my %DisUp = &ProcessDiscriminant(\@UpList);
675: my %DisLow = &ProcessDiscriminant(\@LowList);
676:
677: return (\%DisUp, \%DisLow);
678: }
679:
680: #---- END Problem Statistics Web Page ----------------------------------------
681:
682: #---- Problem Statistics Graph Web Page --------------------------------------
683:
684: # ------------------------------------------- Prepare data for Graphical chart
685:
686: sub BuildGraphicChart {
687: my ($ylab,$r,$cacheDB)=@_;
688: my %cache;
689: my $Col;
690: my $data='';
691: my $count = 0;
692: my $Max = 0;
693:
694: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
695: return '<html><body>Unable to tie database.</body></html>';
696: }
697:
698: my $p_count = $cache{'ProblemCount'};
699:
700: for ( my $k=0; $k<$p_count;$k++) {
701: my @Temp=split(/\:/,$cache{'GraphGif:'.$k});
702: my $inf = $Temp[$Col];
703: if ( $Max < $inf ) {$Max = $inf;}
704: $data .= $inf.',';
705: $count++;
706: }
707: untie(%cache);
708: # $r->print("<br>count=$p_count >>data= $data");
709:
710: if ( $Max > 1 ) {
711: $Max += (10 - $Max % 10);
712: $Max = int($Max);
713: } else { $Max = 1; }
714:
715: my $cid=$ENV{'request.course.id'};
716:
717: if ( $ylab eq 'DoDiff Graph' ) {
718: $ylab = 'Degree-of-Difficulty';
719: $Col = 0;
720: } else {
721: $ylab = 'Wrong-Percentage';
722: $Col = 1;
723: }
724: my $Course = $ENV{'course.'.$cid.'.description'};
725: $Course =~ s/\ /"_"/eg;
726: my $GData=$Course.'&'.'Problems#'.'&'.$ylab.'&'.
727: $Max.'&'.$count.'&'.$data;
728:
729: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
730:
731: return;
732: }
733:
734: 1;
735: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>