File:  [LON-CAPA] / loncom / interface / Attic / lonchart.pm
Revision 1.20: download - view: text, annotated - select for diffs
Wed Nov 28 18:18:17 2001 UTC (22 years, 7 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
correct

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

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