--- loncom/metadata_database/searchcat.pl 2004/04/09 22:04:53 1.56 +++ loncom/metadata_database/searchcat.pl 2004/04/12 21:11:45 1.57 @@ -2,7 +2,7 @@ # The LearningOnline Network # searchcat.pl "Search Catalog" batch script # -# $Id: searchcat.pl,v 1.56 2004/04/09 22:04:53 matthew Exp $ +# $Id: searchcat.pl,v 1.57 2004/04/12 21:11:45 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -144,6 +144,8 @@ if ($wwwid!=$<) { # Let people know we are running open(LOG,'>'.$perlvar{'lonDaemons'}.'/logs/searchcat.log'); &log(0,'==== Searchcat Run '.localtime()."===="); + + if ($debug) { &log(0,'simulating') if ($simulate); &log(0,'only processing user '.$oneuser) if ($oneuser); @@ -305,7 +307,6 @@ sub log_metadata { $_=$file; } - ## ## process_meta_file ## Called by File::Find. @@ -358,11 +359,9 @@ sub process_meta_file { \%Data); if ($err) { &log(0,"MySQL Error Insert: ".$err); - die $err; } if ($count < 1) { &log(0,"Unable to insert record into MySQL database for $url"); - die "Unable to insert record into MySQl database for $url"; } } # @@ -491,33 +490,7 @@ sub process_dynamic_metadata { return 0; } # - # Process every stored element - while (my ($storedkey,$value) = each(%evaldata)) { - my ($source,$file,$type) = split('___',$storedkey); - $source = &unescape($source); - $file = &unescape($file); - $value = &unescape($value); - " got ".$file."\n ".$type." ".$source."\n"; - if ($type =~ /^(avetries|count|difficulty|stdno|timestamp)$/) { - # - # Statistics: $source is course id - $DynamicData{$file}->{'statistics'}->{$source}->{$type}=$value; - } elsif ($type =~ /^(clear|comments|depth|technical|helpful)$/){ - # - # Evaluation $source is username, check if they evaluated it - # more than once. If so, pad the entry with a space. - while(exists($DynamicData{$file}->{'evaluation'}->{$type}->{$source})) { - $source .= ' '; - } - $DynamicData{$file}->{'evaluation'}->{$type}->{$source}=$value; - } elsif ($type =~ /^(course|comefrom|goto|usage)$/) { - # - # Context $source is course id or resource - push(@{$DynamicData{$file}->{$type}},&unescape($source)); - } else { - &log(0," ".$user."@".$dom.":Process metadata: Unable to decode ".$type); - } - } + %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata); untie(%evaldata); # # Read in the access count data @@ -551,71 +524,17 @@ sub get_dynamic_metadata { &log(7,' No dynamic data for '.$url) if ($debug); return (); } - my %data; - my $resdata = $DynamicData{$url}; - # - # Get the statistical data - foreach my $type (qw/avetries difficulty stdno/) { - my $count; - my $sum; - my @Values; - foreach my $coursedata (values(%{$resdata->{'statistics'}})) { - if (ref($coursedata) eq 'HASH' && exists($coursedata->{$type})) { - $count++; - $sum += $coursedata->{$type}; - push(@Values,$coursedata->{$type}); - } - } - if ($count) { - $data{$type} = $sum/$count; - $data{$type.'_list'} = join(',',@Values); - } - } + my %data = &LONCAPA::lonmetadata::process_dynamic_metadata($url, + \%DynamicData); # find the count $data{'count'} = $Counts{$url}; # - # Get the context data - foreach my $type (qw/course goto comefrom/) { - if (defined($resdata->{$type}) && - ref($resdata->{$type}) eq 'ARRAY') { - $data{$type} = scalar(@{$resdata->{$type}}); - $data{$type.'_list'} = join(',',@{$resdata->{$type}}); - } - } - if (defined($resdata->{'usage'}) && - ref($resdata->{'usage'}) eq 'ARRAY') { - $data{'sequsage'} = scalar(@{$resdata->{'usage'}}); - $data{'sequsage_list'} = join(',',@{$resdata->{'usage'}}); - } - # - # Get the evaluation data - foreach my $type (qw/clear technical correct helpful depth/) { - my $count; - my $sum; - foreach my $evaluator (keys(%{$resdata->{'evaluation'}->{$type}})){ - $sum += $resdata->{'evaluation'}->{$type}->{$evaluator}; - $count++; - } - if ($count > 0) { - $data{$type}=$sum/$count; - } - } - # - # put together comments - my $comments = '
'; - } - $comments .= '