1: # The LearningOnline Network with CAPA
2: # Metadata display handler
3: #
4: # $Id: lonmeta.pm,v 1.12 2001/12/24 23:01:31 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: # -------------------------------------------------------------- Pretty display
100:
101: sub evalgraph {
102: my $value=shift;
103: my $val=int($value*10.+0.5)-10;
104: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
105: if ($val>=20) {
106: $output.='<td width=20 bgcolor="#555555">  </td>';
107: } else {
108: $output.='<td width='.($val).' bgcolor="#555555"> </td>'.
109: '<td width='.(20-$val).' bgcolor="#FF3333"> </td>';
110: }
111: $output.='<td bgcolor="#FFFF33"> </td>';
112: if ($val>20) {
113: $output.='<td width='.($val-20).' bgcolor="#33FF33"> </td>'.
114: '<td width='.(40-$val).' bgcolor="#555555"> </td>';
115: } else {
116: $output.='<td width=20 bgcolor="#555555">  </td>';
117: }
118: $output.='<td> ('.$value.') </td></tr></table>';
119: return $output;
120: }
121:
122: sub diffgraph {
123: my $value=shift;
124: my $val=int(40.0*$value+0.5);
125: my @colors=('#FF3333','#EEBB33','#BBEE33','#33FF33',
126: '#33FF33','#BBEE33','#EEBB33','#FF3333');
127: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
128: for (my $i=0;$i<8;$i++) {
129: if ($val>$i*5) {
130: $output.='<td width=5 bgcolor="'.$colors[$i].'"> </td>';
131: } else {
132: $output.='<td width=5 bgcolor="#555555"> </td>';
133: }
134: }
135: $output.='<td> ('.$value.') </td></tr></table>';
136: return $output;
137: }
138:
139: # ================================================================ Main Handler
140:
141: sub handler {
142: my $r=shift;
143: my %content=();
144:
145: # ----------------------------------------------------------- Set document type
146:
147: $r->content_type('text/html');
148: $r->send_http_header;
149:
150: return OK if $r->header_only;
151:
152: # ------------------------------------------------------------------- Read file
153:
154: my $uri=$r->uri;
155: map {
156: $content{$_}=&Apache::lonnet::metadata($uri,$_);
157: } split(/\,/,&Apache::lonnet::metadata($uri,'keys'));
158:
159: # ------------------------------------------------------------------ Hide stuff
160:
161: unless ($ENV{'user.adv'}) {
162: map {
163: $content{$_}='<i>- not displayed -</i>';
164: } ('keywords','notes','abstract','subject');
165: }
166:
167: # --------------------------------------------------------------- Render Output
168:
169: my $creationdate=localtime($content{'creationdate'});
170: my $lastrevisiondate=localtime($content{'lastrevisiondate'});
171: my $language=&Apache::loncommon::languagedescription($content{'language'});
172: my $mime=&Apache::loncommon::filedescription($content{'mime'});
173: my $disuri=&Apache::lonnet::declutter($uri);
174: $disuri=~s/\.meta$//;
175: $r->print(<<ENDHEAD);
176: <html><head><title>Catalog Information</title></head>
177: <body bgcolor="#FFFFFF">
178: <h1>Catalog Information</h1>
179: <h2>$content{'title'}</h2>
180: <h3><tt>$disuri</tt></h3>
181: <table cellspacing=2 border=0>
182: <tr><td bgcolor='#AAAAAA'>Author(s)</td>
183: <td bgcolor="#CCCCCC">$content{'author'} </td></tr>
184: <tr><td bgcolor='#AAAAAA'>Subject</td>
185: <td bgcolor="#CCCCCC">$content{'subject'} </td></tr>
186: <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>
187: <td bgcolor="#CCCCCC">$content{'keywords'} </td></tr>
188: <tr><td bgcolor='#AAAAAA'>Notes</td>
189: <td bgcolor="#CCCCCC">$content{'notes'} </td></tr>
190: <tr><td bgcolor='#AAAAAA'>Abstract</td>
191: <td bgcolor="#CCCCCC">$content{'abstract'} </td></tr>
192: <tr><td bgcolor='#AAAAAA'>MIME Type</td>
193: <td bgcolor="#CCCCCC">$mime ($content{'mime'}) </td></tr>
194: <tr><td bgcolor='#AAAAAA'>Language</td>
195: <td bgcolor="#CCCCCC">$language </td></tr>
196: <tr><td bgcolor='#AAAAAA'>Creation Date</td>
197: <td bgcolor="#CCCCCC">$creationdate </td></tr>
198: <tr><td bgcolor='#AAAAAA'>
199: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate </td></tr>
200: <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>
201: <td bgcolor="#CCCCCC">$content{'owner'} </td></tr>
202: <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>
203: <td bgcolor="#CCCCCC">$content{'copyright'}
204: </table>
205: ENDHEAD
206: delete($content{'title'});
207: delete($content{'author'});
208: delete($content{'subject'});
209: delete($content{'keywords'});
210: delete($content{'notes'});
211: delete($content{'abstract'});
212: delete($content{'mime'});
213: delete($content{'language'});
214: delete($content{'creationdate'});
215: delete($content{'lastrevisiondate'});
216: delete($content{'owner'});
217: delete($content{'copyright'});
218: if ($ENV{'user.adv'}) {
219: # ------------------------------------------------------------ Dynamic Metadata
220: $r->print('<h3>Dynamic Metadata (updated periodically)</h3>');
221: my %items=(
222: 'count' => 'Network-wide number of accesses (hits)',
223: 'course' => 'Network-wide number of courses using resource',
224: 'usage' => 'Number of resources using or importing resource',
225: 'clear' => 'Material presented in clear way',
226: 'depth' => 'Material covered with sufficient depth',
227: 'helpful' => 'Material is helpful',
228: 'correct' => 'Material appears to be correct',
229: 'technical' => 'Resource is technically correct',
230: 'avetries' => 'Average number of tries till solved',
231: 'stdno' => 'Total number of students who have worked on this problem',
232: 'difficulty' => 'Degree of difficulty');
233: my %dynmeta=&dynamicmeta($uri);
234: $r->print(
235: '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');
236: foreach ('count','usage','course') {
237: $r->print(
238: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
239: $dynmeta{$_}." </td></tr>\n");
240: }
241: $r->print('</table>');
242: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
243: $r->print(
244: '<h4>Assessment Statistical Data</h4><table cellspacing=2 border=0>');
245: foreach ('stdno','avetries') {
246: $r->print(
247: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
248: $dynmeta{$_}." </td></tr>\n");
249: }
250: foreach ('difficulty') {
251: $r->print(
252: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
253: &diffgraph($dynmeta{$_})."</td></tr>\n");
254: }
255: $r->print('</table>');
256: }
257: $r->print('<h4>Evaluation Data</h4><table cellspacing=2 border=0>');
258: foreach ('clear','depth','helpful','correct','technical') {
259: $r->print(
260: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
261: &evalgraph($dynmeta{$_})."</td></tr>\n");
262: }
263: $r->print('</table>');
264: $disuri=~/^(\w+)\/(\w+)\//;
265: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
266: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
267: $r->print(
268: '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
269: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
270: }
271: # ------------------------------------------------------------- All other stuff
272: $r->print(
273: '<h3>Additional Metadata (non-standard, parameters, exports)</h3>');
274: foreach (sort keys %content) {
275: my $name=$_;
276: my $display=&Apache::lonnet::metadata($uri,$name.'.display');
277: unless ($display) { $display=$name; };
278: my $otherinfo='';
279: map {
280: if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
281: $otherinfo.=' '.$_.'='.
282: &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
283: }
284: } ('name','part','type','default');
285: $r->print('<b>'.$display.':</b> '.$content{$name});
286: if ($otherinfo) {
287: $r->print(' ('.$otherinfo.')');
288: }
289: $r->print("<br>\n");
290: }
291: }
292: $r->print('</body></html>');
293: return OK;
294: }
295:
296: 1;
297: __END__
298:
299:
300:
301:
302:
303:
304:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>