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

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

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