Annotation of loncom/interface/lonquickgrades.pm, revision 1.58

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>