--- loncom/metadata_database/searchcat.pl 2003/12/25 04:06:52 1.47 +++ loncom/metadata_database/searchcat.pl 2003/12/26 15:13:48 1.50 @@ -2,7 +2,7 @@ # The LearningOnline Network # searchcat.pl "Search Catalog" batch script # -# $Id: searchcat.pl,v 1.47 2003/12/25 04:06:52 www Exp $ +# $Id: searchcat.pl,v 1.50 2003/12/26 15:13:48 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -56,8 +56,7 @@ This script also does general database m the C table if it is deprecated. This script evaluates dynamic metadata from the authors' -F database file in order to store it in MySQL, as -well as to compress the filesize (add up all "count"-type metadata). +F database file in order to store it in MySQL. This script is playing an increasingly important role for a loncapa library server. The proper operation of this script is critical for a smooth @@ -131,7 +130,29 @@ sub escape { sub dynamicmeta { my $url=&declutter(shift); $url=~s/\.meta$//; - my %returnhash=(); + my %returnhash=( + 'count' => 0, + 'course' => 0, + 'course_list' => '', + 'avetries' => 'NULL', + 'avetries_list' => '', + 'stdno' => 0, + 'stdno_list' => '', + 'usage' => 0, + 'usage_list' => '', + 'goto' => 0, + 'goto_list' => '', + 'comefrom' => 0, + 'comefrom_list' => '', + 'difficulty' => 'NULL', + 'difficulty_list' => '', + 'clear' => 'NULL', + 'technical' => 'NULL', + 'correct' => 'NULL', + 'helpful' => 'NULL', + 'depth' => 'NULL', + 'comments' => '' + ); my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//); my $prodir=&propath($adomain,$aauthor); @@ -167,19 +188,19 @@ sub dynamicmeta { if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; } unless ($listitems{$cat} eq 'app') { if (defined($sum{$cat})) { - $sum{$cat}+=$evaldata{$esckey}; + $sum{$cat}+=&unescape($evaldata{$esckey}); $concat{$cat}.=','.$item; } else { - $sum{$cat}=$evaldata{$esckey}; + $sum{$cat}=&unescape($evaldata{$esckey}); $concat{$cat}=$item; } } else { if (defined($sum{$cat})) { if ($evaldata{$esckey}=~/\w/) { - $sum{$cat}.='
'.$evaldata{$esckey}; + $sum{$cat}.='
'.&unescape($evaldata{$esckey}); } } else { - $sum{$cat}=''.$evaldata{$esckey}; + $sum{$cat}=''.&unescape($evaldata{$esckey}); } } } @@ -187,8 +208,14 @@ sub dynamicmeta { untie(%evaldata); # transfer gathered data to returnhash, calculate averages where applicable while (my $cat=each(%cnt)) { + if ($cnt{$cat} eq 'nan') { next; } + if ($sum{$cat} eq 'nan') { next; } if ($listitems{$cat} eq 'avg') { - $returnhash{$cat}=int(($sum{$cat}/$cnt{$cat})*100.0+0.5)/100.0; + if ($cnt{$cat}) { + $returnhash{$cat}=int(($sum{$cat}/$cnt{$cat})*100.0+0.5)/100.0; + } else { + $returnhash{$cat}='NULL'; + } } elsif ($listitems{$cat} eq 'cnt') { $returnhash{$cat}=$cnt{$cat}; } else { @@ -214,7 +241,7 @@ sub dynamicmeta { # --------------- Read loncapa_apache.conf and loncapa.conf and get variables my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf'); my %perlvar=%{$perlvarref}; -undef $perlvarref; # remove since sensitive and not needed +undef $perlvarref; delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed # ------------------------------------- Only run if machine is a library server @@ -255,15 +282,17 @@ my $dbh; "title TEXT, author TEXT, subject TEXT, url TEXT, keywords TEXT, ". "version TEXT, notes TEXT, abstract TEXT, mime TEXT, language TEXT, ". "creationdate DATETIME, lastrevisiondate DATETIME, owner TEXT, ". - "copyright TEXT, ". + "copyright TEXT, dependencies TEXT, ". "count INTEGER UNSIGNED, ". "course INTEGER UNSIGNED, course_list TEXT, ". "goto INTEGER UNSIGNED, goto_list TEXT, ". "comefrom INTEGER UNSIGNED, comefrom_list TEXT, ". - "fusage INTEGER UNSIGNED, fusage_list TEXT, ". + "sequsage INTEGER UNSIGNED, sequsage_list TEXT, ". "stdno INTEGER UNSIGNED, stdno_list TEXT, ". "avetries FLOAT, avetries_list TEXT, ". "difficulty FLOAT, difficulty_list TEXT, ". + "clear FLOAT, technical FLOAT, correct FLOAT, helpful FLOAT, depth FLOAT, ". + "comments TEXT, ". "FULLTEXT idx_title (title), ". "FULLTEXT idx_author (author), FULLTEXT idx_subject (subject), ". "FULLTEXT idx_url (url), FULLTEXT idx_keywords (keywords), ". @@ -305,6 +334,7 @@ my $insert_sth = $dbh->prepare "?,". # revisiondate "?,". # owner "?,". # copyright + "?,". # dependencies "?,". # count "?,". # course "?,". # course_list @@ -319,7 +349,14 @@ my $insert_sth = $dbh->prepare "?,". # avetries "?,". # avetries_list "?,". # difficulty - "?," # difficulty_list + "?,". # difficulty_list + "?,". # clear + "?,". # technical + "?,". # correct + "?,". # helpful + "?,". # depth + "?". # comments + ")" ); foreach my $user (@homeusers) { @@ -357,6 +394,7 @@ foreach my $user (@homeusers) { sqltime($ref->{'lastrevisiondate'}), $ref->{'owner'}, $ref->{'copyright'}, + $ref->{'dependencies'}, $dyn{'count'}, $dyn{'course'}, $dyn{'course_list'}, @@ -371,7 +409,13 @@ foreach my $user (@homeusers) { $dyn{'avetries'}, $dyn{'avetries_list'}, $dyn{'difficulty'}, - $dyn{'difficulty_list'} + $dyn{'difficulty_list'}, + $dyn{'clear'}, + $dyn{'technical'}, + $dyn{'correct'}, + $dyn{'helpful'}, + $dyn{'depth'}, + $dyn{'comments'} )) { print LOG "\nMySQL Error Insert: ".$dbh->errstr."\n"; die $dbh->errstr;