Annotation of loncom/interface/lonmeta.pm, revision 1.13

1.1       www         1: # The LearningOnline Network with CAPA
1.8       albertel    2: # Metadata display handler
                      3: #
1.9       www         4: # $Id: lonmeta.pm,v 1.8 2001/12/19 17:17:46 albertel Exp $
1.8       albertel    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.
1.1       www        14: #
1.8       albertel   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/
1.1       www        27: #
                     28: # (TeX Content Handler
                     29: #
                     30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     31: #
1.13    ! www        32: # 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer
1.1       www        33: 
                     34: package Apache::lonmeta;
                     35: 
                     36: use strict;
                     37: use Apache::Constants qw(:common);
1.3       www        38: use Apache::lonnet();
1.10      www        39: use Apache::loncommon();
1.1       www        40: 
1.9       www        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;
1.10      www        49:     $regexp='___'.$regexp.'___';
1.9       www        50:     my %evaldata=&Apache::lonnet::dump
                     51:                                      ('resevaldata',$adomain,$aauthor,$regexp);
1.10      www        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:     }
1.9       www        86:     my %returnhash=();
1.10      www        87:     foreach (keys %cnt) {
1.11      www        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:        }
1.9       www        95:     }
                     96:     return %returnhash;
                     97: }
1.1       www        98: 
1.12      www        99: # -------------------------------------------------------------- Pretty display
                    100: 
                    101: sub evalgraph {
                    102:     my $value=shift;
1.13    ! www       103:     unless ($value) { return ''; }
1.12      www       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;
1.13    ! www       125:     unless ($value) { return ''; }
1.12      www       126:     my $val=int(40.0*$value+0.5);
1.13    ! www       127:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
        !           128:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.12      www       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: 
1.1       www       141: # ================================================================ Main Handler
                    142: 
                    143: sub handler {
                    144:   my $r=shift;
1.3       www       145:   my %content=();
1.1       www       146: 
                    147: # ----------------------------------------------------------- Set document type
                    148: 
                    149:   $r->content_type('text/html');
                    150:   $r->send_http_header;
                    151: 
                    152:   return OK if $r->header_only;
                    153: 
                    154: # ------------------------------------------------------------------- Read file
                    155: 
1.3       www       156:   my $uri=$r->uri;
                    157:   map {
                    158:       $content{$_}=&Apache::lonnet::metadata($uri,$_);
                    159:   } split(/\,/,&Apache::lonnet::metadata($uri,'keys'));
1.1       www       160: 
1.6       albertel  161: # ------------------------------------------------------------------ Hide stuff
1.7       www       162: 
                    163:   unless ($ENV{'user.adv'}) {
                    164:       map {
                    165:           $content{$_}='<i>- not displayed -</i>';
                    166:       } ('keywords','notes','abstract','subject');
1.6       albertel  167:   }
                    168: 
1.1       www       169: # --------------------------------------------------------------- Render Output
1.2       www       170: 
                    171: my $creationdate=localtime($content{'creationdate'});
                    172: my $lastrevisiondate=localtime($content{'lastrevisiondate'});
1.10      www       173: my $language=&Apache::loncommon::languagedescription($content{'language'});
                    174: my $mime=&Apache::loncommon::filedescription($content{'mime'}); 
1.11      www       175: my $disuri=&Apache::lonnet::declutter($uri);
                    176:   $disuri=~s/\.meta$//;
1.1       www       177:   $r->print(<<ENDHEAD);
                    178: <html><head><title>Catalog Information</title></head>
                    179: <body bgcolor="#FFFFFF">
                    180: <h1>Catalog Information</h1>
                    181: <h2>$content{'title'}</h2>
1.11      www       182: <h3><tt>$disuri</tt></h3>
                    183: <table cellspacing=2 border=0>
                    184: <tr><td bgcolor='#AAAAAA'>Author(s)</td>
                    185: <td bgcolor="#CCCCCC">$content{'author'}&nbsp;</td></tr>
                    186: <tr><td bgcolor='#AAAAAA'>Subject</td>
                    187: <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>
                    188: <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>
                    189: <td bgcolor="#CCCCCC">$content{'keywords'}&nbsp;</td></tr>
                    190: <tr><td bgcolor='#AAAAAA'>Notes</td>
                    191: <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>
                    192: <tr><td bgcolor='#AAAAAA'>Abstract</td>
                    193: <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>
                    194: <tr><td bgcolor='#AAAAAA'>MIME Type</td>
                    195: <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>
                    196: <tr><td bgcolor='#AAAAAA'>Language</td>
                    197: <td bgcolor="#CCCCCC">$language&nbsp;</td></tr>
                    198: <tr><td bgcolor='#AAAAAA'>Creation Date</td>
                    199: <td bgcolor="#CCCCCC">$creationdate&nbsp;</td></tr>
                    200: <tr><td bgcolor='#AAAAAA'>
                    201: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>
                    202: <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>
                    203: <td bgcolor="#CCCCCC">$content{'owner'}&nbsp;</td></tr>
                    204: <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>
                    205: <td bgcolor="#CCCCCC">$content{'copyright'}
                    206: </table>
1.1       www       207: ENDHEAD
                    208:   delete($content{'title'});
                    209:   delete($content{'author'});
                    210:   delete($content{'subject'});
                    211:   delete($content{'keywords'});
                    212:   delete($content{'notes'});
                    213:   delete($content{'abstract'});
                    214:   delete($content{'mime'});
                    215:   delete($content{'language'});
                    216:   delete($content{'creationdate'});
                    217:   delete($content{'lastrevisiondate'});
                    218:   delete($content{'owner'});
                    219:   delete($content{'copyright'});
1.7       www       220:   if ($ENV{'user.adv'}) {
1.11      www       221: # ------------------------------------------------------------ Dynamic Metadata
1.10      www       222:    $r->print('<h3>Dynamic Metadata (updated periodically)</h3>');
                    223:     my %items=(
                    224:  'count'      => 'Network-wide number of accesses (hits)',
                    225:  'course'     => 'Network-wide number of courses using resource',
                    226:  'usage'      => 'Number of resources using or importing resource',
1.11      www       227:  'clear'      => 'Material presented in clear way',
                    228:  'depth'      => 'Material covered with sufficient depth',
                    229:  'helpful'    => 'Material is helpful',
                    230:  'correct'    => 'Material appears to be correct',
                    231:  'technical'  => 'Resource is technically correct', 
1.10      www       232:  'avetries'   => 'Average number of tries till solved',
                    233:  'stdno'      => 'Total number of students who have worked on this problem',
                    234:  'difficulty' => 'Degree of difficulty');
                    235:    my %dynmeta=&dynamicmeta($uri);
1.11      www       236:    $r->print(
                    237: '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');
1.10      www       238:    foreach ('count','usage','course') {
1.11      www       239:        $r->print(
                    240: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
                    241: $dynmeta{$_}."&nbsp;</td></tr>\n");
                    242:    }
                    243:        $r->print('</table>');
1.10      www       244:    if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
1.11      www       245:       $r->print(
                    246: '<h4>Assessment Statistical Data</h4><table cellspacing=2 border=0>');
1.12      www       247:       foreach ('stdno','avetries') {
1.11      www       248:           $r->print(
                    249: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
                    250: $dynmeta{$_}."&nbsp;</td></tr>\n");
                    251:       }
1.12      www       252:       foreach ('difficulty') {
                    253:          $r->print(
                    254: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
                    255: &diffgraph($dynmeta{$_})."</td></tr>\n");
                    256:       }
1.11      www       257:       $r->print('</table>');    
1.10      www       258:    }
1.11      www       259:    $r->print('<h4>Evaluation Data</h4><table cellspacing=2 border=0>');
1.10      www       260:    foreach ('clear','depth','helpful','correct','technical') {
1.11      www       261:        $r->print(
                    262: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
1.12      www       263: &evalgraph($dynmeta{$_})."</td></tr>\n");
1.10      www       264:    }    
1.11      www       265:    $r->print('</table>');
                    266:    $disuri=~/^(\w+)\/(\w+)\//;   
1.10      www       267:    if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
                    268:        || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
                    269:       $r->print(
                    270:   '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
1.11      www       271:       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');      
1.10      www       272:    }
1.11      www       273: # ------------------------------------------------------------- All other stuff
1.10      www       274:    $r->print(
                    275:  '<h3>Additional Metadata (non-standard, parameters, exports)</h3>');
                    276:    foreach (sort keys %content) {
1.3       www       277:       my $name=$_;
                    278:       my $display=&Apache::lonnet::metadata($uri,$name.'.display');
1.5       www       279:       unless ($display) { $display=$name; };
                    280:       my $otherinfo='';
                    281:       map {
                    282:           if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
                    283:              $otherinfo.=' '.$_.'='.
                    284: 		 &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
                    285:           }
                    286:       } ('name','part','type','default'); 
                    287:       $r->print('<b>'.$display.':</b> '.$content{$name});
                    288:       if ($otherinfo) {
                    289:          $r->print(' ('.$otherinfo.')');
                    290:       }
                    291:       $r->print("<br>\n");
1.10      www       292:    }
1.7       www       293:   }
1.1       www       294:   $r->print('</body></html>');
                    295:   return OK;
                    296: }
                    297: 
                    298: 1;
                    299: __END__
                    300: 
                    301: 
                    302: 
                    303: 
                    304: 
                    305: 
                    306: 

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