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

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

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