1: # The LearningOnline Network with CAPA
2: # Quick Student Grades Display
3: #
4: # $Id: lonquickgrades.pm,v 1.53 2010/12/03 15:19:09 www 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: package Apache::lonquickgrades;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use POSIX;
34: use Apache::loncommon;
35: use Apache::lonlocal;
36: use Apache::lonnet;
37: use Apache::grades;
38:
39: sub handler {
40: my $r = shift;
41: return real_handler($r);
42: }
43:
44: sub real_handler {
45: my $r = shift;
46:
47: &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
48:
49: # Handle header-only request
50: if ($env{'browser.mathml'}) {
51: &Apache::loncommon::content_type($r,'text/xml');
52: } else {
53: &Apache::loncommon::content_type($r,'text/html');
54: }
55: if ($r->header_only) {
56: $r->send_http_header;
57: return OK;
58: }
59:
60: # Send header, don't cache this page
61: &Apache::loncommon::no_cache($r);
62: $r->send_http_header;
63:
64: my $showPoints =
65: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
66: my $notshowSPRSlink =
67: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
68: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'));
69: my $notshowTotals=
70: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
71: my $showCategories=
72: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
73:
74:
75: # Header
76: my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
77: my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
78: $r->print(&Apache::loncommon::start_page($title,undef,
79: {'bread_crumbs' => $brcrum})
80: );
81:
82: $r->print(&Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading'));
83:
84: if (!$showPoints && !$notshowSPRSlink ) {
85: $r->print('<p>'
86: .&mt('This screen shows how many problems (or problem parts) you have completed'
87: .', and how many you have not yet done.'
88: .' You can also look at [_1]a detailed score sheet[_2].'
89: ,'<a href="/adm/studentcalc">','</a>')
90: .'</p>');
91: }
92:
93: $r->print('<p class="LC_info">'.&mt('This may take a few moments to display.').'</p>');
94:
95: $r->rflush();
96:
97: my $uname='korte';
98: my $udom='gerd';
99:
100: my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=
101: &getData($showPoints,$uname,$udom);
102:
103: if ($showCategories) {
104: &outputCategories($r,$showPoints,$notshowTotals,
105: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
106: } else {
107: &outputTable($r,$showPoints,$notshowTotals,
108: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
109: }
110: return OK;
111:
112: }
113:
114: sub getData {
115:
116: my ($showPoints,$uname,$udom)=@_;
117:
118: &Apache::lonnet::logthis("About to call with $uname $udom");
119:
120: # Create the nav map
121: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
122:
123: my $res = $navmap->firstResource(); # temp resource to access constants
124:
125: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
126: my $depth = 1;
127: $iterator->next(); # ignore first BEGIN_MAP
128: my $curRes = $iterator->next();
129:
130: # General overview of the following: Walk along the course resources.
131: # For every problem in the resource, tell its parent maps how many
132: # parts and how many parts correct it has. After that, each map will
133: # have a count of the total parts underneath it, correct and otherwise.
134: # After that, we will walk through the course again and read off
135: # maps in order, with their data.
136: # (If in the future people decide not to be cumulative, only add
137: # the counts to the parent map.)
138: # For convenience, "totalParts" is also "totalPoints" when we're looking
139: # at points; I can't come up with a variable name that makes sense
140: # equally for both cases.
141:
142: my $totalParts = 0; my $totalPossible = 0; my $totalRight = 0;
143: my $totalAttempted = 0;
144: my $now = time();
145: my $topLevelParts = 0; my $topLevelRight = 0; my $topLevelAttempted = 0;
146:
147: # Pre-run: Count parts correct
148: while ( $depth > 0 ) {
149: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
150: if ($curRes == $iterator->END_MAP()) { $depth--; }
151:
152: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout)
153: {
154: # Get number of correct, incorrect parts
155: my $parts = $curRes->parts();
156: my $partsRight = 0;
157: my $partsCount = 0;
158: my $partsAttempted = 0;
159: my $stack = $iterator->getStack();
160:
161: for my $part (@{$parts}) {
162: my $completionStatus = $curRes->getCompletionStatus($part);
163: my $dateStatus = $curRes->getDateStatus($part);
164:
165: if ($completionStatus == $curRes->EXCUSED()) {
166: next;
167: }
168: if ($showPoints) {
169: my $score = 0;
170: # If we're not telling status and the answer date isn't passed yet,
171: # it's an "attempted" point
172: if ((($curRes->problemstatus($part) eq 'no') ||
173: ($curRes->problemstatus($part) eq 'no_feedback_ever')) &&
174: ($dateStatus != $curRes->ANSWER_OPEN)) {
175: my $status = $curRes->simpleStatus($part);
176: if ($status == $curRes->ATTEMPTED) {
177: $partsAttempted += $curRes->weight($part);
178: $totalAttempted += $partsAttempted;
179: }
180: } else {
181: $score = &Apache::grades::compute_points($curRes->weight($part), $curRes->awarded($part));
182: }
183: $partsRight += $score;
184: $totalRight += $score;
185: $partsCount += $curRes->weight($part);
186:
187: if ($curRes->opendate($part) < $now) {
188: $totalPossible += $curRes->weight($part);
189: }
190: $totalParts += $curRes->weight($part);
191: } else {
192: my $status = $curRes->simpleStatus($part);
193: my $thisright = 0;
194: $partsCount++;
195: if ($status == $curRes->CORRECT ||
196: $status == $curRes->PARTIALLY_CORRECT ) {
197: $partsRight++;
198: $totalRight++;
199: $thisright = 1;
200: }
201:
202: if ($status == $curRes->ATTEMPTED) {
203: $partsAttempted++;
204: $totalAttempted++;
205: }
206:
207: my $dateStatus = $curRes->getDateStatus($part);
208: $totalParts++;
209: if ($curRes->opendate($part) < $now) {
210: $totalPossible++;
211: }
212: }
213: }
214:
215: if ($depth == 1) { # in top-level only
216: $topLevelParts += $partsCount;
217: $topLevelRight += $partsRight;
218: $topLevelAttempted += $partsAttempted;
219: }
220:
221: # Crawl down stack and record parts correct and total
222: for my $res (@{$stack}) {
223: if (ref($res) && $res->is_map()) {
224: if (!defined($res->{DATA}->{CHILD_PARTS})) {
225: $res->{DATA}->{CHILD_PARTS} = 0;
226: $res->{DATA}->{CHILD_CORRECT} = 0;
227: $res->{DATA}->{CHILD_ATTEMPTED} = 0;
228: }
229:
230: $res->{DATA}->{CHILD_PARTS} += $partsCount;
231: $res->{DATA}->{CHILD_CORRECT} += $partsRight;
232: $res->{DATA}->{CHILD_ATTEMPTED} += $partsAttempted;
233: }
234: }
235: }
236: $curRes = $iterator->next();
237: }
238: return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
239: }
240:
241: #
242: # Outputting everything.
243: #
244:
245: sub outputTable {
246:
247: my ($r,$showPoints,$notshowTotals,
248: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
249:
250: my @start = (255, 255, 192);
251: my @end = (0, 192, 0);
252:
253: my $indentString = ' ';
254:
255: # Second pass: Print the maps.
256: $r->print(&Apache::loncommon::start_data_table()
257: .&Apache::loncommon::start_data_table_header_row()
258: .'<th>'.&mt('Folder').'</th>');
259: my $title = &mt($showPoints ? "Points Scored" : "Done");
260: if ($totalAttempted) {
261: $title .= " / " . &mt("Attempted");
262: }
263: $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
264: .&Apache::loncommon::end_data_table_header_row());
265: #
266: # Output of folder scores
267: #
268:
269: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
270: my $depth = 1;
271: $iterator->next(); # ignore first BEGIN_MAP
272: my $curRes = $iterator->next();
273:
274: while ($depth > 0) {
275: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
276: if ($curRes == $iterator->END_MAP()) { $depth--; }
277:
278: if (ref($curRes) && $curRes->is_map()) {
279: my $title = $curRes->compTitle();
280:
281: my $correct = $curRes->{DATA}->{CHILD_CORRECT};
282: my $total = $curRes->{DATA}->{CHILD_PARTS};
283: my $attempted = $curRes->{DATA}->{CHILD_ATTEMPTED};
284:
285: if ($total > 0) {
286: my $ratio;
287: $ratio = $correct / $total;
288: my $color = &mixColors(\@start, \@end, $ratio);
289: $r->print(&Apache::loncommon::start_data_table_row()
290: .'<td style="background-color:'.$color.';">');
291:
292: my $thisIndent = '';
293: for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; }
294:
295: $r->print("$thisIndent$title</td>");
296: if ($totalAttempted) {
297: $r->print('<td valign="top">'
298: .$thisIndent
299: .'<span class="LC_nobreak">'
300: .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total)
301: .'</span></td>'
302: .&Apache::loncommon::end_data_table_row()
303: );
304: } else {
305: $r->print('<td valign="top">'
306: .$thisIndent
307: .'<span class="LC_nobreak">'
308: .$correct.($notshowTotals?'':' / '.$total)
309: .'</span></td>'
310: .&Apache::loncommon::end_data_table_row());
311: }
312: }
313: }
314:
315: $curRes = $iterator->next();
316: }
317:
318: # If there were any problems at the top level, print an extra "catchall"
319: if ($topLevelParts > 0) {
320: my $ratio = $topLevelRight / $topLevelParts;
321: my $color = mixColors(\@start, \@end, $ratio);
322: $r->print(&Apache::loncommon::start_data_table_row()
323: .'<td style="background-color:'.$color.';">');
324: $r->print(&mt("Problems Not Contained In A Folder")."</td><td>");
325: $r->print("$topLevelRight / $topLevelParts</td>"
326: .&Apache::loncommon::end_data_table_row());
327: }
328:
329: #
330: # show totals (if applicable), close table
331: #
332: if ($showPoints) {
333: my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
334:
335: $title = $showPoints ? "Points" : "Parts Done";
336: my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
337: $r->print(&Apache::loncommon::start_data_table_row()
338: .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
339: $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
340: $title = $showPoints ? "Points" : "Parts";
341: $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
342: .&Apache::loncommon::end_data_table_row());
343: }
344:
345: $r->print(&Apache::loncommon::end_data_table()
346: .&Apache::loncommon::end_page());
347:
348: }
349:
350: #
351: # Outputting category-based grades.
352: #
353:
354: sub outputCategories {
355:
356: my ($r,$showPoints,$notshowTotals,
357: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
358: }
359:
360: # Pass this two refs to arrays for the start and end color, and a number
361: # from 0 to 1 for how much of the latter you want to mix in. It will
362: # return a string ready to show ("#FFC309");
363:
364: sub mixColors {
365: my $start = shift;
366: my $end = shift;
367: my $ratio = shift;
368:
369: my ($a,$b);
370: my $final = "";
371: $a = $start->[0]; $b = $end->[0];
372: my $mix1 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
373: $a = $start->[1]; $b = $end->[1];
374: my $mix2 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
375: $a = $start->[2]; $b = $end->[2];
376: my $mix3 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
377:
378: $final = sprintf "%02x%02x%02x", $mix1, $mix2, $mix3;
379: return "#" . $final;
380: }
381:
382: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>