File:  [LON-CAPA] / loncom / interface / Attic / lonchart.pm
Revision 1.28: download - view: text, annotated - select for diffs
Mon Feb 4 13:52:09 2002 UTC (22 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: stable_2002_spring, HEAD
- adding No_cache call

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonchart.pm,v 1.28 2002/02/04 13:52:09 albertel 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: # Homework Performance Chart
   30: #
   31: # (Navigate Maps Handler
   32: #
   33: # (Page Handler
   34: #
   35: # (TeX Content Handler
   36: # YEAR=2000
   37: # 05/29/00,05/30 Gerd Kortemeyer)
   38: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
   39: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
   40: # YEAR=2001
   41: # 3/1/1,6/1,17/1,29/1,30/1,31/1 Gerd Kortemeyer)
   42: # 7/10/01 Behrouz Minaei
   43: # 9/8 Gerd Kortemeyer
   44: # 10/1, 10/19, 11/17, 11/22, 11/24, 11/28 12/18 Behrouz Minaei
   45: # YEAR=2002
   46: # 2/1 Behrouz Minaei
   47: #
   48: ###
   49: 
   50: package Apache::lonchart;
   51: 
   52: use strict;
   53: use Apache::Constants qw(:common :http);
   54: use Apache::lonnet();
   55: use Apache::loncommon();
   56: use HTML::TokeParser;
   57: use GDBM_File;
   58: 
   59: # -------------------------------------------------------------- Module Globals
   60: my %hash;
   61: my @cols;
   62: my @rowlabels;
   63: my @students;
   64: 
   65: # ------------------------------------------------------------- Find out status
   66: 
   67: sub ExtractStudentData {
   68:     my ($index,$coid)=@_;
   69:     my ($sname,$sdom) = split( /\:/, $students[$index] );
   70:     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );          
   71:     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );
   72:     my %result=();
   73:     my $ResId;
   74:     my $Code;
   75:     my $Tries;
   76:     my $Wrongs;
   77:     my %TempHash;
   78:     my $Version;
   79:     my $ProbNo;
   80:     my $ProbSolved;
   81:     my $ProbTotal;
   82:     my $LatestVersion;                     
   83:     my $Str=substr($students[$index].
   84:             '                                                        ',0,14).' ! '.
   85:             substr($rowlabels[$index].
   86:             '                                                        ',0,45).' ! ';
   87:     unless ($reply=~/^error\:/) {
   88:         map {
   89:             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
   90:             $result{$name}=$value;
   91:         } split(/\&/,$reply);
   92: 	$ProbNo = 0;
   93: 	$ProbTotal = 0;
   94:         $ProbSolved = 0;
   95: 	my $IterationNo = 0;
   96:         foreach $ResId (@cols) {
   97: 	    if ($IterationNo == 0) {$IterationNo++; next;}
   98: 	    if (!$ResId) { 
   99: 		my $PrNo = sprintf( "%3d", $ProbNo );
  100: 		$Str .= ' '.'<font color="#007700">'.$PrNo.'</font> ';
  101: 		$ProbSolved += $ProbNo;
  102: 		$ProbNo=0;
  103: 		next; 
  104: 	    }
  105:             $ResId=~/(\d+)\.(\d+)/;
  106: 	    my $meta=$hash{'src_'.$ResId};
  107: 	    my $PartNo = 0;
  108: 	    undef %TempHash;
  109: 	    map {
  110: 		if ($_=~/^stores\_(\d+)\_tries$/) {
  111:                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  112: 		    if ( $TempHash{"$Part"} eq '' ) { 
  113: 			$TempHash{"$Part"} = $Part;
  114: 			$TempHash{$PartNo}=$Part;
  115: 			$TempHash{"$Part.Code"} = ' ';  
  116: 			$PartNo++;
  117: 		    }
  118: 		}
  119:             } split(/\,/,&Apache::lonnet::metadata($meta,'keys'));
  120: 
  121:             my $Prob = &Apache::lonnet::declutter( $hash{'map_id_'.$1} ).
  122:                        '___'.$2.'___'.
  123:                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
  124:             $Code=' ';
  125:             $Tries = 0;
  126:   	    $LatestVersion = $result{"version:$Prob"};
  127: 
  128:             if ( $LatestVersion ) {
  129: 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
  130: 		    my $vkeys = $result{"$Version:keys:$Prob"};
  131: 		    my @keys = split(/\:/,$vkeys);		  
  132: 
  133: 		    foreach my $Key (@keys) {		  
  134: 			if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
  135: 			    my $Part = $1;
  136: 			    $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
  137: 			    $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0;
  138: 			    my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
  139: 			    if ($Val eq 'correct_by_student'){$Code='*';} 
  140: 			    elsif ($Val eq 'correct_by_override'){$Code = '+';}                        
  141: 			    elsif ($Val eq 'incorrect_attempted'){$Code = '.';} 
  142: 			    elsif ($Val eq 'incorrect_by_override'){$Code = '-';}
  143: 			    elsif ($Val eq 'excused'){$Code = 'x';}
  144: 			    elsif ($Val eq 'ungraded_attempted'){$Code = '#';}
  145: 			    else {$Code = ' ';}
  146: 			    $TempHash{"$Part.Code"} = $Code;
  147: 			}
  148:       		    }
  149:                 } 
  150: 		for ( my $n = 0; $n < $PartNo; $n++ ) {		  
  151: 		    my $part = $TempHash{$n};
  152: 		    my $Code = $TempHash{"$part.Code"};
  153:                     if ( $Code eq '*') {
  154: 			$ProbNo++;
  155:                         if (($TempHash{"$part.Tries"}<10) ||
  156:                             ($TempHash{"$part.Tries"} eq '')) {
  157: 			    $TempHash{"$part.Code"}=$TempHash{"$part.Tries"};
  158: 			}
  159:                     }
  160: 		    elsif ( $Code eq '+' ) {$ProbNo++;}
  161: 		    $Str .= $TempHash{"$part.Code"};
  162: 		    if ( $Code ne 'x' ) {$ProbTotal++;}
  163: 		}
  164:             }   
  165: 	    else {
  166: 		for(my $n=0; $n<$PartNo; $n++) {
  167: 		    $Str.=' ';
  168: 		    $ProbTotal++;
  169: 		}
  170: 	    }
  171:         } 
  172:     }
  173:     my $PrTot = sprintf( "%5d", $ProbTotal );
  174:     my $PrSvd = sprintf( "%5d", $ProbSolved );
  175:     $Str .= ' '.'<font color="#000088">'.$PrSvd.'  /'.$PrTot.'</font> ';
  176: 
  177:     return $Str ;
  178: }
  179: 
  180: 
  181: # ------------------------------------------------------------ Build page table
  182: 
  183: sub tracetable {
  184:     my ($rid,$beenhere)=@_;
  185:     unless ($beenhere=~/\&$rid\&/) {
  186:        $beenhere.=$rid.'&';  
  187: # new ... updating the map according to sequence and page
  188:        if (defined($hash{'is_map_'.$rid})) {
  189: 	   my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
  190:            if ( $cmap eq 'sequence' || $cmap eq 'page' ) { 
  191:                $cols[$#cols+1]=0; 
  192:            }
  193:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
  194:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
  195:               my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
  196: 
  197:                 &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
  198:                 '&'.$frid.'&');
  199: 
  200:               if ($hash{'src_'.$frid}) {
  201:                  if ($hash{'src_'.$frid}=~
  202:                                  /\.(problem|exam|quiz|assess|survey|form)$/) {
  203: 		     $cols[$#cols+1]=$frid;
  204:                  }
  205: 	      }
  206: 
  207: 	   }
  208:        } else {
  209:           if ($hash{'src_'.$rid}) {
  210:              if ($hash{'src_'.$rid}=~
  211:                                  /\.(problem|exam|quiz|assess|survey|form)$/) {
  212: 	         $cols[$#cols+1]=$rid;
  213:              }
  214:           }
  215:        }
  216:        if (defined($hash{'to_'.$rid})) {
  217:           map {
  218:               &tracetable($hash{'goesto_'.$_},$beenhere);
  219:           } split(/\,/,$hash{'to_'.$rid});
  220:        }
  221:     }
  222: }
  223: 
  224: # ================================================================ Main Handler
  225: 
  226: sub handler {
  227: 
  228:   undef %hash;
  229:   undef @students;
  230:   undef @cols;
  231:   undef @rowlabels;
  232: 
  233:   my $r=shift;
  234: 
  235:   if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  236: # ------------------------------------------- Set document type for header only
  237: 
  238:   if ($r->header_only) {
  239:        if ($ENV{'browser.mathml'}) {
  240:            $r->content_type('text/xml');
  241:        } else {
  242:            $r->content_type('text/html');
  243:        }
  244:        &Apache::loncommon::no_cache($r);
  245:        $r->send_http_header;
  246:        return OK;
  247:    }
  248: 
  249:   my $requrl=$r->uri;
  250: # ----------------------------------------------------------------- Tie db file
  251:   if ($ENV{'request.course.fn'}) {
  252:       my $fn=$ENV{'request.course.fn'};
  253:       if (-e "$fn.db") {
  254:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
  255: # ------------------------------------------------------------------- Hash tied
  256: 
  257: 
  258: # ------------------------------------------------------------------ Build page
  259: 
  260: # ---------------------------------------------------------------- Send headers
  261: 
  262:              $r->content_type('text/html');
  263:              $r->send_http_header;
  264:              $r->print(
  265:   '<html><head><title>LON-CAPA Assessment Chart</title></head>');
  266: 
  267: 	     $r->print('<body bgcolor="#FFFFFF">'.
  268:                                     '<script>window.focus();</script>'.
  269:                            '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
  270:                                     '<h1>Assessment Chart</h1>');
  271: 
  272: # ---------------------------------------------------------------- Course title
  273: 
  274:     $r->print('<h1>'.
  275:     $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'</h1><h3>'.
  276:     localtime()."</h3><p><pre>1..9: correct by student in 1..9 tries\n".
  277:                             "   *: correct by student in more than 9 tries\n".
  278: 	                    "   +: correct by override\n".
  279:                             "   -: incorrect by override\n".
  280: 	                    "   .: incorrect attempted\n".
  281: 	                    "   #: ungraded attempted\n".
  282:                             "    : not attempted\n".
  283: 	                    "   x: excused</pre><p>");
  284:   
  285: # ------------------------------- This is going to take a while, produce output
  286: 
  287:              $r->rflush();
  288: 
  289: # ----------------------- Get first and last resource, see if there is anything
  290: 
  291: 
  292:               my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
  293:               my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
  294:               if (($firstres) && ($lastres)) {
  295: # ----------------------------------------------------------------- Render page
  296: 
  297:                  my $cid=$ENV{'request.course.id'};
  298:                  my $chome=$ENV{'course.'.$cid.'.home'};
  299:                  my ($cdom,$cnum)=split(/\_/,$cid);
  300: 
  301: # ---------------------------------------------- Read class list and row labels
  302: 
  303:     my $classlst=&Apache::lonnet::reply
  304:                                  ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
  305:     my $now=time;
  306:     unless ($classlst=~/^error\:/) {
  307:         map {
  308:             my ($name,$value)=split(/\=/,$_);
  309:             my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
  310:             my $active=1;
  311:             if (($end) && ($now>$end)) { $active=0; }
  312:             if ($active) {
  313:                 my $thisindex=$#students+1;
  314:                 $name=&Apache::lonnet::unescape($name);
  315:                 $students[$thisindex]=$name;
  316:                 my ($sname,$sdom)=split(/\:/,$name);
  317:                 my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
  318:                 if ($ssec==-1) {
  319:                     $rowlabels[$thisindex]=
  320:                       'Data not available: '.$name;
  321:                 } else {
  322:                     my %reply=&Apache::lonnet::idrget($sdom,$sname);
  323: 		    my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
  324:                                                      ':environment:lastname&generation&firstname&middlename',
  325:                                                      &Apache::lonnet::homeserver($sname,$sdom));
  326: 
  327:                     $ssec=(int($ssec)) ? int($ssec) : $ssec;
  328: 
  329:                     $rowlabels[$thisindex]=
  330:                       sprintf('%3s ',$ssec).' '.$reply{$sname}.' ';
  331:                     my $i=0;
  332:                     map {
  333:                       $i++;
  334:                       if ( $_ ne '') {
  335:                         $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' ';
  336:                       }
  337:                       if ($i == 2) {
  338:                         chop($rowlabels[$thisindex]);
  339:                         $rowlabels[$thisindex].=', ';
  340:                       }
  341:                     } split(/\&/,$reply);
  342: 
  343:                 }
  344:             }
  345:         } sort split(/\&/,$classlst);
  346: 
  347:     } else {
  348:         $r->print('<h1>Could not access course data</h1>');
  349:     }
  350: 
  351:     my $allstudents=$#students+1;
  352:     $r->print('<h3>'.$allstudents.' students</h3>');
  353:     $r->rflush();
  354: 
  355: # --------------- Find all assessments and put them into some linear-like order
  356: 
  357:    &tracetable($firstres,'&'.$lastres.'&');
  358: 
  359: # ----------------------------------------------------------------- Start table
  360: 
  361:                           $r->print('<p><pre>');
  362:  			  my $index;
  363:                            for ($index=0;$index<=$#students;$index++) {
  364:                               $r->print(&ExtractStudentData($index,$cid).'<br>');
  365:                               $r->rflush();
  366:                           }
  367:                           $r->print('</pre>');
  368: 
  369: 	     } else {
  370:                  $r->print('<h3>Undefined course sequence</h3>');
  371:              }
  372: 
  373:                       $r->print('</body></html>');
  374:                                      
  375: # ------------------------------------------------------------- End render page
  376:               } else {
  377:                   $r->content_type('text/html');
  378:                   $r->send_http_header;
  379: 		  $r->print('<html><body>Coursemap undefined.</body></html>');
  380:               }
  381: # ------------------------------------------------------------------ Untie hash
  382:               unless (untie(%hash)) {
  383:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  384:                        "Could not untie coursemap $fn (browse).</font>"); 
  385:               }
  386: 
  387: # -------------------------------------------------------------------- All done
  388: 	      return OK;
  389: # ----------------------------------------------- Errors, hash could no be tied
  390:       }
  391:   } else {
  392:   $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  393:   return HTTP_NOT_ACCEPTABLE; 
  394: }
  395: } else {
  396:       $ENV{'user.error.msg'}=
  397:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
  398:       return HTTP_NOT_ACCEPTABLE; 
  399: 
  400: }
  401: }
  402: 1;
  403: __END__
  404: 
  405: 
  406: 
  407: 
  408: 
  409: 
  410: 

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