File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.21: download - view: text, annotated - select for diffs
Mon Oct 7 13:50:36 2002 UTC (21 years, 7 months ago) by www
Branches: MAIN
CVS tags: HEAD
Toward bug 531.

Can address most recent version.
Can find out with lonnet::getversion what the most recent version is
Shows versions in lonmeta

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.21 2002/10/07 13:50:36 www Exp $
    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: # (TeX Content Handler
   29: #
   30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
   31: #
   32: # 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer
   33: 
   34: package Apache::lonmeta;
   35: 
   36: use strict;
   37: use Apache::Constants qw(:common);
   38: use Apache::lonnet();
   39: use Apache::loncommon();
   40: 
   41: # ----------------------------------------- Fetch and evaluate dynamic metadata
   42: 
   43: sub dynamicmeta {
   44:     my $url=&Apache::lonnet::declutter(shift);
   45:     $url=~s/\.meta$//;
   46:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
   47:     my $regexp=$url;
   48:     $regexp=~s/(\W)/\\$1/g;
   49:     $regexp='___'.$regexp.'___';
   50:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
   51: 				       $aauthor,$regexp);
   52:     my %sum;
   53:     my %cnt;
   54:     my %listitems=('count'        => 'add',
   55:                    'course'       => 'add',
   56:                    'avetries'     => 'avg',
   57:                    'stdno'        => 'add',
   58:                    'difficulty'   => 'avg',
   59:                    'clear'        => 'avg',
   60:                    'technical'    => 'avg',
   61:                    'helpful'      => 'avg',
   62:                    'correct'      => 'avg',
   63:                    'depth'        => 'avg',
   64:                    'comments'     => 'app',
   65:                    'usage'        => 'cnt'
   66:                    );
   67:     foreach (keys %evaldata) {
   68: 	$_=~/___(\w+)$/;
   69:         if (defined($cnt{$1})) { $cnt{$1}++; } else { $cnt{$1}=1; }
   70:         unless ($listitems{$1} eq 'app') {
   71:             if (defined($sum{$1})) {
   72:                $sum{$1}+=$evaldata{$_};
   73: 	    } else {
   74:                $sum{$1}=$evaldata{$_};
   75: 	    }
   76:         } else {
   77:             if (defined($sum{$1})) {
   78:                if ($evaldata{$_}) {
   79:                   $sum{$1}.='<hr>'.$evaldata{$_};
   80: 	       }
   81:  	    } else {
   82: 	       $sum{$1}=''.$evaldata{$_};
   83: 	    }
   84: 	}
   85:     }
   86:     my %returnhash=();
   87:     foreach (keys %cnt) {
   88:        if ($listitems{$_} eq 'avg') {
   89: 	   $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;
   90:        } elsif ($listitems{$_} eq 'cnt') {
   91:            $returnhash{$_}=$cnt{$_};
   92:        } else {
   93:            $returnhash{$_}=$sum{$_};
   94:        }
   95:     }
   96:     return %returnhash;
   97: }
   98: 
   99: # -------------------------------------------------------------- Pretty display
  100: 
  101: sub evalgraph {
  102:     my $value=shift;
  103:     unless ($value) { return ''; }
  104:     my $val=int($value*10.+0.5)-10;
  105:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
  106:     if ($val>=20) {
  107: 	$output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
  108:     } else {
  109:         $output.='<td width='.($val).' bgcolor="#555555">&nbsp;</td>'.
  110:                  '<td width='.(20-$val).' bgcolor="#FF3333">&nbsp;</td>';
  111:     }
  112:     $output.='<td bgcolor="#FFFF33">&nbsp;</td>';
  113:     if ($val>20) {
  114: 	$output.='<td width='.($val-20).' bgcolor="#33FF33">&nbsp;</td>'.
  115:                  '<td width='.(40-$val).' bgcolor="#555555">&nbsp;</td>';
  116:     } else {
  117:        $output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
  118:     }
  119:     $output.='<td> ('.$value.') </td></tr></table>';
  120:     return $output;
  121: }
  122: 
  123: sub diffgraph {
  124:     my $value=shift;
  125:     unless ($value) { return ''; }
  126:     my $val=int(40.0*$value+0.5);
  127:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
  128:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
  129:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
  130:     for (my $i=0;$i<8;$i++) {
  131: 	if ($val>$i*5) {
  132:             $output.='<td width=5 bgcolor="'.$colors[$i].'">&nbsp;</td>';
  133:         } else {
  134: 	    $output.='<td width=5 bgcolor="#555555">&nbsp;</td>';
  135: 	}
  136:     }
  137:     $output.='<td> ('.$value.') </td></tr></table>';
  138:     return $output;
  139: }
  140: 
  141: # ================================================================ Main Handler
  142: 
  143: sub handler {
  144:   my $r=shift;
  145: 
  146:     my $loaderror=&Apache::lonnet::overloaderror($r);
  147:     if ($loaderror) { return $loaderror; }
  148: 
  149: 
  150:     my $uri=$r->uri;
  151: 
  152:     my ($resdomain,$resuser)=
  153:            (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  154: 
  155:     $loaderror=
  156:        &Apache::lonnet::overloaderror($r,
  157:          &Apache::lonnet::homeserver($resuser,$resdomain));
  158:     if ($loaderror) { return $loaderror; }
  159: 
  160:   my %content=();
  161: 
  162: # ----------------------------------------------------------- Set document type
  163: 
  164:   $r->content_type('text/html');
  165:   $r->send_http_header;
  166: 
  167:   return OK if $r->header_only;
  168: 
  169: # ------------------------------------------------------------------- Read file
  170:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  171:       $content{$_}=&Apache::lonnet::metadata($uri,$_);
  172:   }
  173: # ------------------------------------------------------------------ Hide stuff
  174: 
  175:   unless ($ENV{'user.adv'}) {
  176:       foreach ('keywords','notes','abstract','subject') {
  177:           $content{$_}='<i>- not displayed -</i>';
  178:       }
  179:   }
  180: 
  181: # --------------------------------------------------------------- Render Output
  182:   my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta/);
  183: my $creationdate=localtime($content{'creationdate'});
  184: my $lastrevisiondate=localtime($content{'lastrevisiondate'});
  185: my $language=&Apache::loncommon::languagedescription($content{'language'});
  186: my $mime=&Apache::loncommon::filedescription($content{'mime'}); 
  187: my $disuri=&Apache::lonnet::declutter($uri);
  188:   $disuri=~s/\.meta$//;
  189: my $currentversion=&Apache::lonnet::getversion($disuri);
  190: my $versiondisplay='';
  191: if ($thisversion) {
  192:     $versiondisplay='Version: '.$thisversion.
  193:     ' (most recent version: '.$currentversion.')';
  194: } else {
  195:     $versiondisplay='Version: '.$currentversion;
  196: }
  197: my $bodytag=&Apache::loncommon::bodytag
  198:             ('Catalog Information','','','',$resdomain);
  199:   $r->print(<<ENDHEAD);
  200: <html><head><title>Catalog Information</title></head>
  201: $bodytag
  202: <h2>$content{'title'}</h2>
  203: <h3><tt>$disuri</tt></h3>
  204: $versiondisplay<br />
  205: <table cellspacing=2 border=0>
  206: <tr><td bgcolor='#AAAAAA'>Author(s)</td>
  207: <td bgcolor="#CCCCCC">$content{'author'}&nbsp;</td></tr>
  208: <tr><td bgcolor='#AAAAAA'>Subject</td>
  209: <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>
  210: <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>
  211: <td bgcolor="#CCCCCC">$content{'keywords'}&nbsp;</td></tr>
  212: <tr><td bgcolor='#AAAAAA'>Notes</td>
  213: <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>
  214: <tr><td bgcolor='#AAAAAA'>Abstract</td>
  215: <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>
  216: <tr><td bgcolor='#AAAAAA'>MIME Type</td>
  217: <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>
  218: <tr><td bgcolor='#AAAAAA'>Language</td>
  219: <td bgcolor="#CCCCCC">$language&nbsp;</td></tr>
  220: <tr><td bgcolor='#AAAAAA'>Creation Date</td>
  221: <td bgcolor="#CCCCCC">$creationdate&nbsp;</td></tr>
  222: <tr><td bgcolor='#AAAAAA'>
  223: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>
  224: <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>
  225: <td bgcolor="#CCCCCC">$content{'owner'}&nbsp;</td></tr>
  226: <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>
  227: <td bgcolor="#CCCCCC">$content{'copyright'}
  228: </table>
  229: ENDHEAD
  230:   delete($content{'title'});
  231:   delete($content{'author'});
  232:   delete($content{'subject'});
  233:   delete($content{'keywords'});
  234:   delete($content{'notes'});
  235:   delete($content{'abstract'});
  236:   delete($content{'mime'});
  237:   delete($content{'language'});
  238:   delete($content{'creationdate'});
  239:   delete($content{'lastrevisiondate'});
  240:   delete($content{'owner'});
  241:   delete($content{'copyright'});
  242:   if ($ENV{'user.adv'}) {
  243: # ------------------------------------------------------------ Dynamic Metadata
  244:    $r->print(
  245:    '<h3>Dynamic Metadata (updated periodically)</h3>Processing ...<br>');
  246:    $r->rflush();
  247:     my %items=(
  248:  'count'      => 'Network-wide number of accesses (hits)',
  249:  'course'     => 'Network-wide number of courses using resource',
  250:  'usage'      => 'Number of resources using or importing resource',
  251:  'clear'      => 'Material presented in clear way',
  252:  'depth'      => 'Material covered with sufficient depth',
  253:  'helpful'    => 'Material is helpful',
  254:  'correct'    => 'Material appears to be correct',
  255:  'technical'  => 'Resource is technically correct', 
  256:  'avetries'   => 'Average number of tries till solved',
  257:  'stdno'      => 'Total number of students who have worked on this problem',
  258:  'difficulty' => 'Degree of difficulty');
  259:    my %dynmeta=&dynamicmeta($uri);
  260:    $r->print(
  261: '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');
  262:    foreach ('count','usage','course') {
  263:        $r->print(
  264: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  265: $dynmeta{$_}."&nbsp;</td></tr>\n");
  266:    }
  267:        $r->print('</table>');
  268:    if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
  269:       $r->print(
  270: '<h4>Assessment Statistical Data</h4><table cellspacing=2 border=0>');
  271:       foreach ('stdno','avetries') {
  272:           $r->print(
  273: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  274: $dynmeta{$_}."&nbsp;</td></tr>\n");
  275:       }
  276:       foreach ('difficulty') {
  277:          $r->print(
  278: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  279: &diffgraph($dynmeta{$_})."</td></tr>\n");
  280:       }
  281:       $r->print('</table>');    
  282:    }
  283:    $r->print('<h4>Evaluation Data</h4><table cellspacing=2 border=0>');
  284:    foreach ('clear','depth','helpful','correct','technical') {
  285:        $r->print(
  286: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  287: &evalgraph($dynmeta{$_})."</td></tr>\n");
  288:    }    
  289:    $r->print('</table>');
  290:    $disuri=~/^(\w+)\/(\w+)\//;   
  291:    if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  292:        || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  293:       $r->print(
  294:   '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
  295:       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');      
  296:    }
  297: # ------------------------------------------------------------- All other stuff
  298:    $r->print(
  299:  '<h3>Additional Metadata (non-standard, parameters, exports)</h3>');
  300:    foreach (sort keys %content) {
  301:       my $name=$_;
  302:       my $display=&Apache::lonnet::metadata($uri,$name.'.display');
  303:       unless ($display) { $display=$name; };
  304:       my $otherinfo='';
  305:       foreach ('name','part','type','default') {
  306:           if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
  307:              $otherinfo.=' '.$_.'='.
  308: 		 &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
  309:           }
  310:       }
  311:       $r->print('<b>'.$display.':</b> '.$content{$name});
  312:       if ($otherinfo) {
  313:          $r->print(' ('.$otherinfo.')');
  314:       }
  315:       $r->print("<br>\n");
  316:    }
  317:   }
  318:   $r->print('</body></html>');
  319:   return OK;
  320: }
  321: 
  322: 1;
  323: __END__
  324: 
  325: 
  326: 
  327: 
  328: 
  329: 
  330: 

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