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