--- loncom/interface/lonmeta.pm 2004/04/15 18:06:29 1.72
+++ loncom/interface/lonmeta.pm 2004/06/17 15:05:59 1.81
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.72 2004/04/15 18:06:29 matthew Exp $
+# $Id: lonmeta.pm,v 1.81 2004/06/17 15:05:59 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,6 +41,86 @@ use Apache::lonmysql;
use Apache::lonmsg;
+############################################################
+############################################################
+##
+## &get_dynamic_metadata_from_sql($url)
+##
+## Queries sql database for dynamic metdata
+## Returns a hash of hashes, with keys of urls which match $url
+## Returned fields are given below.
+##
+## Examples:
+##
+## %DynamicMetadata = &Apache::lonmeta::get_dynmaic_metadata_from_sql
+## ('/res/msu/korte/');
+##
+## $DynamicMetadata{'/res/msu/korte/example.problem'}->{$field}
+##
+############################################################
+############################################################
+sub get_dynamic_metadata_from_sql {
+ my ($url) = shift();
+ my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
+ if (! defined($authordom)) {
+ $authordom = shift();
+ }
+ if (! defined($author)) {
+ $author = shift();
+ }
+ if (! defined($authordom) || ! defined($author)) {
+ return ();
+ }
+ my @Fields = ('url',
+ 'goto','goto_list',
+ 'comefrom','comefrom_list',
+ 'sequsage','sequsage_list',
+ 'stdno','stdno_list',
+ 'avetries','avetries_list',
+ 'difficulty','difficulty_list',
+ 'disc','disc_list',
+ 'clear','technical','correct',
+ 'helpful','depth');
+ #
+ my $query = 'SELECT '.join(',',@Fields).
+ ' FROM metadata WHERE url LIKE "'.$url.'%"';
+ my $server = &Apache::lonnet::homeserver($author,$authordom);
+ my $reply = &Apache::lonnet::metadata_query($query,undef,undef,
+ ,[$server]);
+ return () if (! defined($reply) || ref($reply) ne 'HASH');
+ my $filename = $reply->{$server};
+ if (! defined($filename) || $filename =~ /^error/) {
+ return ();
+ }
+ my $max_time = time + 10; # wait 10 seconds for results at most
+ my %ReturnHash;
+ #
+ # Look for results
+ my $finished = 0;
+ while (! $finished && time < $max_time) {
+ my $datafile=$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
+ if (! -e "$datafile.end") { next; }
+ my $fh;
+ if (!($fh=Apache::File->new($datafile))) { next; }
+ while (my $result = <$fh>) {
+ chomp($result);
+ next if (! $result);
+ my @Data =
+ map {
+ &Apache::lonnet::unescape($_);
+ } split(',',$result);
+ my $url = $Data[0];
+ for (my $i=0;$i<=$#Fields;$i++) {
+ $ReturnHash{$url}->{$Fields[$i]}=$Data[$i];
+ }
+ }
+ $finished = 1;
+ }
+ #
+ return %ReturnHash;
+}
+
+
# Fetch and evaluate dynamic metadata
sub dynamicmeta {
my $url=&Apache::lonnet::declutter(shift);
@@ -175,6 +255,8 @@ sub fieldnames {
'owner' => 'Publisher/Owner',
'copyright' => 'Copyright/Distribution',
'customdistributionfile' => 'Custom Distribution File',
+ 'sourceavail' => 'Source Availible',
+ 'sourcerights' => 'Source Custom Distribution File',
'obsolete' => 'Obsolete',
'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
'count' => 'Network-wide number of accesses (hits)',
@@ -193,7 +275,8 @@ sub fieldnames {
'technical' => 'Resource is technically correct',
'avetries' => 'Average number of tries till solved',
'stdno' => 'Total number of students who have worked on this problem',
- 'difficulty' => 'Degree of difficulty'
+ 'difficulty' => 'Degree of difficulty',
+ 'disc' => 'Degree of discrimination',
);
}
@@ -223,6 +306,10 @@ sub prettyprint {
if ($type eq 'copyright') {
return &Apache::loncommon::copyrightdescription($value);
}
+ # Copyright
+ if ($type eq 'sourceavail') {
+ return &Apache::loncommon::source_copyrightdescription($value);
+ }
# MIME
if ($type eq 'mime') {
return ' '.
@@ -283,7 +370,7 @@ sub prettyprint {
return &evalgraph($value);
}
# Difficulty
- if ($type eq 'difficulty') {
+ if ($type eq 'difficulty' || $type eq 'disc') {
return &diffgraph($value);
}
# List of courses
@@ -344,7 +431,10 @@ sub relatedfield {
sub prettyinput {
my ($type,$value,$fieldname,$formname,
- $relatedsearchflag,$relatedsep,$relatedvalue)=@_;
+ $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
+ if (! defined($size)) {
+ $size = 80;
+ }
# Language
if ($type eq 'language') {
return &selectbox($fieldname,
@@ -361,6 +451,14 @@ sub prettyinput {
(&Apache::loncommon::copyrightids)).
&relatedfield(0,$relatedsearchflag,$relatedsep);
}
+ # Source Copyright
+ if ($type eq 'sourceavail') {
+ return &selectbox($fieldname,
+ $value,
+ \&Apache::loncommon::source_copyrightdescription,
+ (&Apache::loncommon::source_copyrightids)).
+ &relatedfield(0,$relatedsearchflag,$relatedsep);
+ }
# Gradelevels
if (($type eq 'lowestgradelevel') ||
($type eq 'highestgradelevel')) {
@@ -389,6 +487,14 @@ sub prettyinput {
",'rights')\">".&mt('Select').''.
&relatedfield(0,$relatedsearchflag,$relatedsep);
}
+ # Source Customdistribution file
+ if ($type eq 'sourcerights') {
+ return '".&mt('Select').' '.
+ &relatedfield(0,$relatedsearchflag,$relatedsep);
+ }
# Dates
if (($type eq 'creationdate') ||
($type eq 'lastrevisiondate')) {
@@ -400,9 +506,9 @@ sub prettyinput {
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
- $value=~s/\"/\&quod\;/gs;
+ $value=~s/\"/\"\;/gs;
return
- ' '.
&relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
$relatedvalue);
@@ -414,26 +520,13 @@ sub handler {
#
my $uri=$r->uri;
#
- # Check to see if this server is overloaded
- my $loaderror=&Apache::lonnet::overloaderror($r);
- if ($loaderror) {
- return $loaderror;
- }
- #
- # Check to see if original resource server is overloaded
- my ($resdomain,$resuser)=
- (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
- $loaderror=&Apache::lonnet::overloaderror
- ($r,&Apache::lonnet::homeserver($resuser,$resdomain));
- if ($loaderror) {
- return $loaderror;
- }
- #
# Set document type
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
#
+ my ($resdomain,$resuser)=
+ (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
$r->print('
'.
'Catalog Information'.
' ');
@@ -551,7 +644,9 @@ sub present_uneditable_metadata {
'lastrevisiondate',
'owner',
'copyright',
- 'customdistributionfile',
+ 'customdistributionfile',
+ 'sourceavail',
+ 'sourcerights',
'obsolete',
'obsoletereplacement') {
$table.=''.$lt{$_}.
@@ -613,23 +708,88 @@ sub print_dynamic_metadata {
}
#
# Assessment statistics
- if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/ &&
- (exists($dynmeta{'stdno'}) ||
- exists($dynmeta{'avetries'}) ||
- exists($dynmeta{'difficulty'}))) {
- # This is an assessment, print assessment data
- $r->print(''.&mt('Assessment Statistical Data').' '.
- '');
- foreach ('stdno','avetries','difficulty') {
- $r->print(''.$lt{$_}.' '.
+ if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
+ if (exists($dynmeta{'stdno'}) ||
+ exists($dynmeta{'avetries'}) ||
+ exists($dynmeta{'difficulty'}) ||
+ exists($dynmeta{'disc'})) {
+ # This is an assessment, print assessment data
+ $r->print(''.
+ &mt('Overall Assessment Statistical Data').
+ ' '.
+ '');
+ $r->print(''.$lt{'stdno'}.' '.
''.
- &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).' '.
- " \n");
+ &prettyprint('stdno',$dynmeta{'stdno'}).
+ ''."\n");
+ foreach ('avetries','difficulty','disc') {
+ $r->print(''.$lt{$_}.' '.
+ ''.
+ &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
+ ' '." \n");
+ }
+ $r->print('
');
+ }
+ if (exists($dynmeta{'stats'})) {
+ #
+ # New assessment statistics
+ $r->print(''.
+ &mt('Detailed Assessment Statistical Data').
+ ' ');
+ my $table = ''.
+ ''.
+ 'Course '.
+ 'Section(s) '.
+ 'Num Students '.
+ 'Mean Tries '.
+ 'Degree of Difficulty '.
+ 'Degree of Discrimination '.
+ 'Time of computation '.
+ ' '.$/;
+ foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
+ my $data = $dynmeta{'stats'}->{$identifier};
+ my $course = $data->{'course'};
+ my %courseinfo = &Apache::lonnet::coursedescription($course);
+ if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
+ &Apache::lonnet::logthis('lookup for '.$course.' failed');
+ next;
+ }
+ $table .= '';
+ $table .=
+ ''.$courseinfo{'description'}.' ';
+ $table .=
+ ''.$data->{'sections'}.' ';
+ $table .=
+ ''.$data->{'stdno'}.' ';
+ foreach ('avetries','difficulty','disc') {
+ $table .= '';
+ if (exists($data->{$_})) {
+ $table .= sprintf('%.2f',$data->{$_}).' ';
+ } else {
+ $table .= '';
+ }
+ $table .= ' ';
+ }
+ $table .=
+ ''.
+ &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
+ ' ';
+ $table .=
+ ' '.$/;
+ }
+ $table .= '
'.$/;
+ $r->print($table);
+ } else {
+ $r->print('No new dynamic data found.');
}
- $r->print('
');
} else {
- $r->print(''.&mt('No Assessment Statistical Data is available for this resource').' ');
+ $r->print(''.
+ &mt('No Assessment Statistical Data is available for this resource').
+ ' ');
}
+
+ #
+ #
if (exists($dynmeta{'clear'}) ||
exists($dynmeta{'depth'}) ||
exists($dynmeta{'helpful'}) ||
@@ -670,7 +830,7 @@ sub print_dynamic_metadata {
# All other stuff
$r->print(''.
&mt('Additional Metadata (non-standard, parameters, exports)').
- ' ');
+ '');
foreach (sort(keys(%content))) {
my $name=$_;
if ($name!~/\.display$/) {
@@ -688,13 +848,14 @@ sub print_dynamic_metadata {
$name.'.'.$_).'; ';
}
}
- $r->print(''.$display.': '.$content{$name});
+ $r->print(''.$display.' '.$content{$name});
if ($otherinfo) {
$r->print(' ('.$otherinfo.')');
}
- $r->print(" \n");
+ $r->print(" \n");
}
}
+ $r->print("
");
return;
}
@@ -759,7 +920,7 @@ ENDEDIT
foreach ('author','title','subject','keywords','abstract','notes',
'copyright','customdistributionfile','language',
'standards',
- 'lowestgradelevel','highestgradelevel',
+ 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
'obsolete','obsoletereplacement') {
if (defined($ENV{'form.new_'.$_})) {
$Apache::lonpublisher::metadatafields{$_}=