File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.11: download - view: text, annotated - select for diffs
Mon Dec 24 21:09:08 2001 UTC (22 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Works now

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.11 2001/12/24 21:09:08 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 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=&Apache::lonnet::escape($url);
   48:     $regexp=~s/(\W)/\\$1/g;
   49:     $regexp='___'.$regexp.'___';
   50:     my %evaldata=&Apache::lonnet::dump
   51:                                      ('resevaldata',$adomain,$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: # ================================================================ Main Handler
  100: 
  101: sub handler {
  102:   my $r=shift;
  103:   my %content=();
  104: 
  105: # ----------------------------------------------------------- Set document type
  106: 
  107:   $r->content_type('text/html');
  108:   $r->send_http_header;
  109: 
  110:   return OK if $r->header_only;
  111: 
  112: # ------------------------------------------------------------------- Read file
  113: 
  114:   my $uri=$r->uri;
  115:   map {
  116:       $content{$_}=&Apache::lonnet::metadata($uri,$_);
  117:   } split(/\,/,&Apache::lonnet::metadata($uri,'keys'));
  118: 
  119: # ------------------------------------------------------------------ Hide stuff
  120: 
  121:   unless ($ENV{'user.adv'}) {
  122:       map {
  123:           $content{$_}='<i>- not displayed -</i>';
  124:       } ('keywords','notes','abstract','subject');
  125:   }
  126: 
  127: # --------------------------------------------------------------- Render Output
  128: 
  129: my $creationdate=localtime($content{'creationdate'});
  130: my $lastrevisiondate=localtime($content{'lastrevisiondate'});
  131: my $language=&Apache::loncommon::languagedescription($content{'language'});
  132: my $mime=&Apache::loncommon::filedescription($content{'mime'}); 
  133: my $disuri=&Apache::lonnet::declutter($uri);
  134:   $disuri=~s/\.meta$//;
  135:   $r->print(<<ENDHEAD);
  136: <html><head><title>Catalog Information</title></head>
  137: <body bgcolor="#FFFFFF">
  138: <h1>Catalog Information</h1>
  139: <h2>$content{'title'}</h2>
  140: <h3><tt>$disuri</tt></h3>
  141: <table cellspacing=2 border=0>
  142: <tr><td bgcolor='#AAAAAA'>Author(s)</td>
  143: <td bgcolor="#CCCCCC">$content{'author'}&nbsp;</td></tr>
  144: <tr><td bgcolor='#AAAAAA'>Subject</td>
  145: <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>
  146: <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>
  147: <td bgcolor="#CCCCCC">$content{'keywords'}&nbsp;</td></tr>
  148: <tr><td bgcolor='#AAAAAA'>Notes</td>
  149: <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>
  150: <tr><td bgcolor='#AAAAAA'>Abstract</td>
  151: <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>
  152: <tr><td bgcolor='#AAAAAA'>MIME Type</td>
  153: <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>
  154: <tr><td bgcolor='#AAAAAA'>Language</td>
  155: <td bgcolor="#CCCCCC">$language&nbsp;</td></tr>
  156: <tr><td bgcolor='#AAAAAA'>Creation Date</td>
  157: <td bgcolor="#CCCCCC">$creationdate&nbsp;</td></tr>
  158: <tr><td bgcolor='#AAAAAA'>
  159: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>
  160: <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>
  161: <td bgcolor="#CCCCCC">$content{'owner'}&nbsp;</td></tr>
  162: <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>
  163: <td bgcolor="#CCCCCC">$content{'copyright'}
  164: </table>
  165: ENDHEAD
  166:   delete($content{'title'});
  167:   delete($content{'author'});
  168:   delete($content{'subject'});
  169:   delete($content{'keywords'});
  170:   delete($content{'notes'});
  171:   delete($content{'abstract'});
  172:   delete($content{'mime'});
  173:   delete($content{'language'});
  174:   delete($content{'creationdate'});
  175:   delete($content{'lastrevisiondate'});
  176:   delete($content{'owner'});
  177:   delete($content{'copyright'});
  178:   if ($ENV{'user.adv'}) {
  179: # ------------------------------------------------------------ Dynamic Metadata
  180:    $r->print('<h3>Dynamic Metadata (updated periodically)</h3>');
  181:     my %items=(
  182:  'count'      => 'Network-wide number of accesses (hits)',
  183:  'course'     => 'Network-wide number of courses using resource',
  184:  'usage'      => 'Number of resources using or importing resource',
  185:  'clear'      => 'Material presented in clear way',
  186:  'depth'      => 'Material covered with sufficient depth',
  187:  'helpful'    => 'Material is helpful',
  188:  'correct'    => 'Material appears to be correct',
  189:  'technical'  => 'Resource is technically correct', 
  190:  'avetries'   => 'Average number of tries till solved',
  191:  'stdno'      => 'Total number of students who have worked on this problem',
  192:  'difficulty' => 'Degree of difficulty');
  193:    my %dynmeta=&dynamicmeta($uri);
  194:    $r->print(
  195: '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');
  196:    foreach ('count','usage','course') {
  197:        $r->print(
  198: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  199: $dynmeta{$_}."&nbsp;</td></tr>\n");
  200:    }
  201:        $r->print('</table>');
  202:    if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
  203:       $r->print(
  204: '<h4>Assessment Statistical Data</h4><table cellspacing=2 border=0>');
  205:       foreach ('stdno','avetries','difficulty') {
  206:           $r->print(
  207: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  208: $dynmeta{$_}."&nbsp;</td></tr>\n");
  209:       }
  210:       $r->print('</table>');    
  211:    }
  212:    $r->print('<h4>Evaluation Data</h4><table cellspacing=2 border=0>');
  213:    foreach ('clear','depth','helpful','correct','technical') {
  214:        $r->print(
  215: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  216: $dynmeta{$_}."&nbsp;</td></tr>\n");
  217:    }    
  218:    $r->print('</table>');
  219:    $disuri=~/^(\w+)\/(\w+)\//;   
  220:    if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  221:        || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  222:       $r->print(
  223:   '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
  224:       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');      
  225:    }
  226: # ------------------------------------------------------------- All other stuff
  227:    $r->print(
  228:  '<h3>Additional Metadata (non-standard, parameters, exports)</h3>');
  229:    foreach (sort keys %content) {
  230:       my $name=$_;
  231:       my $display=&Apache::lonnet::metadata($uri,$name.'.display');
  232:       unless ($display) { $display=$name; };
  233:       my $otherinfo='';
  234:       map {
  235:           if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
  236:              $otherinfo.=' '.$_.'='.
  237: 		 &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
  238:           }
  239:       } ('name','part','type','default'); 
  240:       $r->print('<b>'.$display.':</b> '.$content{$name});
  241:       if ($otherinfo) {
  242:          $r->print(' ('.$otherinfo.')');
  243:       }
  244:       $r->print("<br>\n");
  245:    }
  246:   }
  247:   $r->print('</body></html>');
  248:   return OK;
  249: }
  250: 
  251: 1;
  252: __END__
  253: 
  254: 
  255: 
  256: 
  257: 
  258: 
  259: 

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