1: # The LearningOnline Network with CAPA
2: # Quick Student Grades Display
3: #
4: # $Id: lonquickgrades.pm,v 1.56 2010/12/03 22:00:28 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: my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
76: my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
77: $r->print(&Apache::loncommon::start_page($title,undef,
78: {'bread_crumbs' => $brcrum})
79: );
80:
81: &startGradeScreen($r,'quick');
82:
83: $r->rflush();
84:
85: # my $uname='korte';
86: # my $udom='gerd';
87:
88: my $uname;
89: my $udom;
90:
91: my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=
92: &getData($showPoints,$uname,$udom);
93:
94: if ($showCategories) {
95: &outputCategories($r,$showPoints,$notshowTotals,
96: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
97: } else {
98: &outputTable($r,$showPoints,$notshowTotals,
99: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
100: }
101: &endGradeScreen($r);
102: return OK;
103:
104: }
105:
106: sub startGradeScreen {
107: my ($r,$mode)=@_;
108:
109: my $showPoints =
110: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
111: my $notshowSPRSlink =
112: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
113: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')
114: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'));
115: my $notshowTotals=
116: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
117: my $showCategories=
118: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
119:
120: my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
121: my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
122:
123: if ($allowed_to_view) {
124: $r->print('<div id="LC_head_subbox">');
125: if ($notshowTotals) { $r->print (' '.&mt('Students do not see total points.').' '); }
126: if ($notshowSPRSlink){ $r->print (' '.&mt('Students do not see link to spreadsheet.').' '); }
127: if ($showPoints) { $r->print (' '.&mt('Students will see points based on problem weights.').' '); }
128: if ($showCategories) { $r->print (' '.&mt('Students will see points based on categories.').' '); }
129: $r->print(' '.&Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading').'</div>');
130: }
131:
132:
133: $r->print("\n".'<ul class="LC_TabContentBigger" id="main">');
134: $r->print("\n".'<li'.($mode eq 'quick'?' class="active"':'').'><a href="/adm/quickgrades"><b>'.
135: ($showPoints?&mt('Points'):($showCategories?&mt('Grades'):&mt('Completion'))).'</b></a></li>');
136:
137: if (!($showPoints || $notshowSPRSlink) || ($allowed_to_view)) {
138: $r->print("\n".'<li'.($mode eq 'spreadsheet'?' class="active"':'').'><a href="/adm/'.($allowed_to_view?'classcalc':'studentcalc').'"><b>'.
139: &mt('Spreadsheet').'</b></a></li>');
140: }
141: $r->print("\n".'</ul>'."\n");
142: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
143: }
144:
145: sub endGradeScreen {
146: my ($r)=@_;
147: $r->print('</div></div></div>');
148: }
149:
150:
151: sub getData {
152:
153: my ($showPoints,$uname,$udom)=@_;
154:
155: &Apache::lonnet::logthis("About to call with $uname $udom");
156:
157: # Create the nav map
158: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
159:
160: my $res = $navmap->firstResource(); # temp resource to access constants
161:
162: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
163: my $depth = 1;
164: $iterator->next(); # ignore first BEGIN_MAP
165: my $curRes = $iterator->next();
166:
167: # General overview of the following: Walk along the course resources.
168: # For every problem in the resource, tell its parent maps how many
169: # parts and how many parts correct it has. After that, each map will
170: # have a count of the total parts underneath it, correct and otherwise.
171: # After that, we will walk through the course again and read off
172: # maps in order, with their data.
173: # (If in the future people decide not to be cumulative, only add
174: # the counts to the parent map.)
175: # For convenience, "totalParts" is also "totalPoints" when we're looking
176: # at points; I can't come up with a variable name that makes sense
177: # equally for both cases.
178:
179: my $totalParts = 0; my $totalPossible = 0; my $totalRight = 0;
180: my $totalAttempted = 0;
181: my $now = time();
182: my $topLevelParts = 0; my $topLevelRight = 0; my $topLevelAttempted = 0;
183:
184: # Pre-run: Count parts correct
185: while ( $depth > 0 ) {
186: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
187: if ($curRes == $iterator->END_MAP()) { $depth--; }
188:
189: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout)
190: {
191: # Get number of correct, incorrect parts
192: my $parts = $curRes->parts();
193: my $partsRight = 0;
194: my $partsCount = 0;
195: my $partsAttempted = 0;
196: my $stack = $iterator->getStack();
197:
198: for my $part (@{$parts}) {
199: my $completionStatus = $curRes->getCompletionStatus($part);
200: my $dateStatus = $curRes->getDateStatus($part);
201:
202: if ($completionStatus == $curRes->EXCUSED()) {
203: next;
204: }
205: if ($showPoints) {
206: my $score = 0;
207: # If we're not telling status and the answer date isn't passed yet,
208: # it's an "attempted" point
209: if ((($curRes->problemstatus($part) eq 'no') ||
210: ($curRes->problemstatus($part) eq 'no_feedback_ever')) &&
211: ($dateStatus != $curRes->ANSWER_OPEN)) {
212: my $status = $curRes->simpleStatus($part);
213: if ($status == $curRes->ATTEMPTED) {
214: $partsAttempted += $curRes->weight($part);
215: $totalAttempted += $partsAttempted;
216: }
217: } else {
218: $score = &Apache::grades::compute_points($curRes->weight($part), $curRes->awarded($part));
219: }
220: $partsRight += $score;
221: $totalRight += $score;
222: $partsCount += $curRes->weight($part);
223:
224: if ($curRes->opendate($part) < $now) {
225: $totalPossible += $curRes->weight($part);
226: }
227: $totalParts += $curRes->weight($part);
228: } else {
229: my $status = $curRes->simpleStatus($part);
230: my $thisright = 0;
231: $partsCount++;
232: if ($status == $curRes->CORRECT ||
233: $status == $curRes->PARTIALLY_CORRECT ) {
234: $partsRight++;
235: $totalRight++;
236: $thisright = 1;
237: }
238:
239: if ($status == $curRes->ATTEMPTED) {
240: $partsAttempted++;
241: $totalAttempted++;
242: }
243:
244: my $dateStatus = $curRes->getDateStatus($part);
245: $totalParts++;
246: if ($curRes->opendate($part) < $now) {
247: $totalPossible++;
248: }
249: }
250: }
251:
252: if ($depth == 1) { # in top-level only
253: $topLevelParts += $partsCount;
254: $topLevelRight += $partsRight;
255: $topLevelAttempted += $partsAttempted;
256: }
257:
258: # Crawl down stack and record parts correct and total
259: for my $res (@{$stack}) {
260: if (ref($res) && $res->is_map()) {
261: if (!defined($res->{DATA}->{CHILD_PARTS})) {
262: $res->{DATA}->{CHILD_PARTS} = 0;
263: $res->{DATA}->{CHILD_CORRECT} = 0;
264: $res->{DATA}->{CHILD_ATTEMPTED} = 0;
265: }
266:
267: $res->{DATA}->{CHILD_PARTS} += $partsCount;
268: $res->{DATA}->{CHILD_CORRECT} += $partsRight;
269: $res->{DATA}->{CHILD_ATTEMPTED} += $partsAttempted;
270: }
271: }
272: }
273: $curRes = $iterator->next();
274: }
275: return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
276: }
277:
278: #
279: # Outputting everything.
280: #
281:
282: sub outputTable {
283:
284: my ($r,$showPoints,$notshowTotals,
285: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
286:
287: my @start = (255, 255, 192);
288: my @end = (0, 192, 0);
289:
290: my $indentString = ' ';
291:
292: # Second pass: Print the maps.
293: $r->print(&Apache::loncommon::start_data_table()
294: .&Apache::loncommon::start_data_table_header_row()
295: .'<th>'.&mt('Folder').'</th>');
296: my $title = &mt($showPoints ? "Points Scored" : "Done");
297: if ($totalAttempted) {
298: $title .= " / " . &mt("Attempted");
299: }
300: $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
301: .&Apache::loncommon::end_data_table_header_row());
302: #
303: # Output of folder scores
304: #
305:
306: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
307: my $depth = 1;
308: $iterator->next(); # ignore first BEGIN_MAP
309: my $curRes = $iterator->next();
310:
311: while ($depth > 0) {
312: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
313: if ($curRes == $iterator->END_MAP()) { $depth--; }
314:
315: if (ref($curRes) && $curRes->is_map()) {
316: my $title = $curRes->compTitle();
317:
318: my $correct = $curRes->{DATA}->{CHILD_CORRECT};
319: my $total = $curRes->{DATA}->{CHILD_PARTS};
320: my $attempted = $curRes->{DATA}->{CHILD_ATTEMPTED};
321:
322: if ($total > 0) {
323: my $ratio;
324: $ratio = $correct / $total;
325: my $color = &mixColors(\@start, \@end, $ratio);
326: $r->print(&Apache::loncommon::start_data_table_row()
327: .'<td style="background-color:'.$color.';">');
328:
329: my $thisIndent = '';
330: for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; }
331:
332: $r->print("$thisIndent$title</td>");
333: if ($totalAttempted) {
334: $r->print('<td valign="top">'
335: .$thisIndent
336: .'<span class="LC_nobreak">'
337: .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total)
338: .'</span></td>'
339: .&Apache::loncommon::end_data_table_row()
340: );
341: } else {
342: $r->print('<td valign="top">'
343: .$thisIndent
344: .'<span class="LC_nobreak">'
345: .$correct.($notshowTotals?'':' / '.$total)
346: .'</span></td>'
347: .&Apache::loncommon::end_data_table_row());
348: }
349: }
350: }
351:
352: $curRes = $iterator->next();
353: }
354:
355: # If there were any problems at the top level, print an extra "catchall"
356: if ($topLevelParts > 0) {
357: my $ratio = $topLevelRight / $topLevelParts;
358: my $color = mixColors(\@start, \@end, $ratio);
359: $r->print(&Apache::loncommon::start_data_table_row()
360: .'<td style="background-color:'.$color.';">');
361: $r->print(&mt("Problems Not Contained In A Folder")."</td><td>");
362: $r->print("$topLevelRight / $topLevelParts</td>"
363: .&Apache::loncommon::end_data_table_row());
364: }
365:
366: #
367: # show totals (if applicable), close table
368: #
369: if ($showPoints) {
370: my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
371:
372: $title = $showPoints ? "Points" : "Parts Done";
373: my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
374: $r->print(&Apache::loncommon::start_data_table_row()
375: .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
376: $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
377: $title = $showPoints ? "Points" : "Parts";
378: $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
379: .&Apache::loncommon::end_data_table_row());
380: }
381:
382: $r->print(&Apache::loncommon::end_data_table()
383: .&Apache::loncommon::end_page());
384:
385: }
386:
387: #
388: # Outputting category-based grades.
389: #
390:
391: sub outputCategories {
392:
393: my ($r,$showPoints,$notshowTotals,
394: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
395: }
396:
397: # Pass this two refs to arrays for the start and end color, and a number
398: # from 0 to 1 for how much of the latter you want to mix in. It will
399: # return a string ready to show ("#FFC309");
400:
401: sub mixColors {
402: my $start = shift;
403: my $end = shift;
404: my $ratio = shift;
405:
406: my ($a,$b);
407: my $final = "";
408: $a = $start->[0]; $b = $end->[0];
409: my $mix1 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
410: $a = $start->[1]; $b = $end->[1];
411: my $mix2 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
412: $a = $start->[2]; $b = $end->[2];
413: my $mix3 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
414:
415: $final = sprintf "%02x%02x%02x", $mix1, $mix2, $mix3;
416: return "#" . $final;
417: }
418:
419: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>