File:  [LON-CAPA] / loncom / interface / Attic / lonchart.pm
Revision 1.23: download - view: text, annotated - select for diffs
Thu Dec 6 21:57:23 2001 UTC (22 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: stable_2001_fall, HEAD
- added notice of ungraded_attempted

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

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