Annotation of loncom/interface/lonchart.pm, revision 1.24

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

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