File:
[LON-CAPA] /
loncom /
interface /
statistics /
lonpercentage.pm
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Fri Aug 30 17:11:44 2002 UTC (21 years, 10 months ago) by
stredwic
Branches:
MAIN
CVS tags:
HEAD
First, was getting a strange warning for doing scalar(split(...)) in
lonpercentage. Second I think I fixed the updating of symbols in
chart after they have been changed. I tried it out and it work for
my test case. We will see if it works for everyone. The problem
is as I suspected, and because I didn't remove the keys when the
students data was updated it was still using old data. This
would occur if the data didn't overwrite, but changed supporting
information.
1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonpercentage.pm,v 1.2 2002/08/30 17:11:44 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: ###
29:
30: package Apache::lonpercentage;
31:
32: use strict;
33: use Apache::lonhtmlcommon;
34: use Apache::loncoursedata;
35: use GDBM_File;
36:
37: #my $jr;
38:
39: sub BuildPercentageGraph {
40: my ($cacheDB, $students, $courseID, $c, $r)=@_;
41:
42: my %cache;
43: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
44: $r->print('Unable to tie database.6');
45: return;
46: }
47:
48: $r->print(&CreateInterface(\%cache));
49: $r->rflush();
50: untie(%cache);
51:
52: my ($result) = &InitializeSelectedStudents($cacheDB, $students,
53: $courseID, $c, $r);
54: if($result ne 'OK' || $c->aborted()) {
55: return;
56: }
57:
58: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
59: $r->print('Unable to tie database.6');
60: return;
61: }
62:
63: my ($Ptr, $percentage) = &GraphData(\%cache, $students);
64: $r->print($Ptr.'<br><br>');
65:
66: $r->print(&TableData(\%cache, $percentage));
67:
68: untie(%cache);
69:
70: return;
71: }
72:
73: sub CreateInterface {
74: my ($cache)=@_;
75:
76: my $Ptr = '';
77: $Ptr .= '<table border="0" cellspacing="5"><tbody>';
78: $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
79: $Ptr .= '<td align="left">';
80: $Ptr .= &Apache::lonhtmlcommon::MapOptions($cache, 'Statistics',
81: 'Statistics');
82: $Ptr .= '</td>'."\n";
83:
84: my $sequence = $cache->{'StatisticsMaps'};
85: if($sequence ne 'All Maps') {
86: $Ptr .= '<td align="right">'."\n";
87: $Ptr .= &Apache::lonhtmlcommon::ProblemOptions($cache,
88: 'Statistics',
89: $sequence,
90: 'Statistics');
91: $Ptr .= '<td>'."\n";
92:
93: my $problem = $cache->{'StatisticsProblemSelect'};
94: if($problem ne 'All Problems') {
95: my $parts = &GetParts($cache, $sequence, $problem);
96: if(scalar(@$parts) > 0) {
97: $Ptr .= '<td align="right">'."\n";
98: $Ptr .= &Apache::lonhtmlcommon::PartOptions($cache,
99: 'Statistics',
100: $parts,
101: 'Statistics');
102: $Ptr .= '</td>'."\n";
103: }
104: }
105: }
106:
107: $Ptr .= '</tr>'."\n";
108:
109: $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
110: $Ptr .= '</td>'."\n";
111: $Ptr .= '<td align="left">'."\n";
112: my @sections = split(':',$cache->{'sectionList'});
113: my @sectionsSelected = split(':',$cache->{'sectionsSelected'});
114: $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
115: \@sectionsSelected,
116: 'Statistics');
117: $Ptr .= '</td></tr>'."\n";
118: $Ptr .= '</table>';
119:
120: return $Ptr;
121: }
122:
123: sub GetParts {
124: my ($cache,$sequence,$problem)=@_;
125: my @parts = ();
126:
127: foreach my $sequenceNumber (split(':',$cache->{'orderedSequences'})) {
128: if($cache->{$sequenceNumber.':title'} eq $sequence) {
129: foreach my $problemNumber (split(':',
130: $cache->{$sequenceNumber.':problems'})) {
131: if($cache->{$problemNumber.':title'} eq $problem) {
132: @parts = split(':',
133: $cache->{$sequenceNumber.':'.$problemNumber.':parts'});
134: }
135: }
136: }
137: }
138:
139: return \@parts;
140: }
141:
142: sub InitializeSelectedStudents {
143: my ($cacheDB, $students, $courseID, $c, $r)=@_;
144: my %cache;
145:
146: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
147: $r->print('Unable to tie database1.1.');
148: return ('ERROR');
149: }
150:
151: # Remove students who don't have the proper section.
152: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
153: for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
154: $studentIndex--) {
155: my $value = $cache{$students->[$studentIndex].':section'};
156: my $found = 0;
157: foreach (@sectionsSelected) {
158: if($_ eq 'none') {
159: if($value eq '' || !defined($value) || $value eq ' ') {
160: $found = 1;
161: last;
162: }
163: } else {
164: if($value eq $_) {
165: $found = 1;
166: last;
167: }
168: }
169: }
170: if($found == 0) {
171: splice(@$students, $studentIndex, 1);
172: }
173: }
174:
175: untie(%cache);
176:
177: &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
178: 'true',
179: $cacheDB,
180: 'true',
181: 'true',
182: $courseID,
183: $r, $c);
184:
185: return ('OK');
186: }
187:
188: sub GraphData {
189: my ($cache,$students)=@_;
190:
191: my $sequenceSelected = $cache->{'StatisticsMaps'};
192: my $problemSelected = $cache->{'StatisticsProblemSelect'};
193: my $partSelected = $cache->{'StatisticsPartSelect'};
194:
195: my %percentages;
196: my $Ptr = '';
197:
198: foreach(@$students) {
199: my $totalCorrect = 0;
200: my $totalProblems = 0;
201:
202: foreach my $sequence (split(':',$cache->{'orderedSequences'})) {
203: next if($cache->{$sequence.':title'} ne $sequenceSelected &&
204: $sequenceSelected ne 'All Maps');
205: foreach my $problem (split(':',$cache->{$sequence.':problems'})) {
206: next if($cache->{$problem.':title'} ne $problemSelected &&
207: $problemSelected ne 'All Problems' &&
208: $sequenceSelected ne 'All Maps');
209: foreach my $part (split(':',$cache->{$sequence.':'.$problem.
210: ':parts'})) {
211: next if($part ne $partSelected &&
212: $partSelected ne 'All Parts' &&
213: $problemSelected ne 'All Problems' &&
214: $sequenceSelected ne 'All Maps');
215: my $code = $cache->{$_.':'.$problem.':'.$part.':code'};
216: if($code eq '*' || $code eq '+') {
217: $totalCorrect++;
218: $totalProblems++;
219: } elsif($code ne 'x') {
220: $totalProblems++;
221: }
222: }
223: }
224: }
225:
226: my $percent = sprintf("%d", ($totalProblems) ?
227: (($totalCorrect/$totalProblems)*100) : 0);
228: if(defined($percentages{$percent})) {
229: $percentages{$percent} .= ':::'.$_;
230: } else {
231: $percentages{$percent} = $_;
232: }
233: }
234:
235: my @percent = ();
236: my @percentCount = ();
237: my $max = 0;
238: foreach my $key (sort(keys(%percentages))) {
239: push(@percent, $key);
240: my @temp = split(':::', $percentages{$key});
241: my $count = scalar(@temp);
242: if($count > $max) {
243: $max = $count;
244: }
245: push(@percentCount, $count);
246: }
247:
248: my @GData = ('', 'Percentage', 'Number_of_Students',
249: $max, scalar(@percent),
250: join(',',@percent), join(',', @percentCount));
251:
252: $Ptr .= '</form>'."\n";
253: $Ptr .= '<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData));
254: $Ptr .= '" border="1" />';
255: $Ptr .= '<form>'."\n";
256:
257: return ($Ptr, \%percentages);
258: }
259:
260: sub TableData {
261: my($cache,$percentage)=@_;
262: my $Ptr;
263:
264: $Ptr .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
265: $Ptr .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
266:
267: $Ptr .= '<tr>'."\n";
268: $Ptr .= '<td>Percent Correct</td><td>Students</td>';
269: $Ptr .= '</tr>'."\n";
270:
271: my $alternate=0;
272: foreach (sort(keys(%$percentage))) {
273: if($alternate) {
274: $Ptr .= '<tr bgcolor="#ffffe6">';
275: } else {
276: $Ptr .= '<tr bgcolor="#ffffc6">';
277: }
278: $alternate = ($alternate + 1) % 2;
279:
280: $Ptr .= '<td>'.$_.'</td><td>';
281:
282: foreach my $name (sort(split(':::', $percentage->{$_}))) {
283: $Ptr .= '<a href="/adm/statistics?reportSelected=';
284: $Ptr .= &Apache::lonnet::escape('Student Assessment');
285: $Ptr .= '&StudentAssessmentStudent=';
286: $Ptr .= &Apache::lonnet::escape($cache->{$name.':fullname'}).'">';
287: $Ptr .= $cache->{$name.':fullname'};
288: $Ptr .= '</a>,  ';
289: }
290:
291: $Ptr .= '</td></tr>'."\n";
292: }
293:
294: $Ptr .= '</tr>'."\n";
295: $Ptr .= '</table></td></tr></table>'."\n";
296:
297: return $Ptr;
298: }
299:
300: 1;
301: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>