File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.10: download - view: text, annotated - select for diffs
Mon Dec 24 17:13:11 2001 UTC (22 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Display more dynamic metadata (not done yet)

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

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