Diff for /loncom/metadata_database/searchcat.pl between versions 1.43 and 1.44

version 1.43, 2003/10/08 19:38:41 version 1.44, 2003/12/23 15:47:26
Line 124  sub escape { Line 124  sub escape {
 # ------------------------------------------- Code to evaluate dynamic metadata  # ------------------------------------------- Code to evaluate dynamic metadata
   
 sub dynamicmeta {  sub dynamicmeta {
   
     my $url=&declutter(shift);      my $url=&declutter(shift);
     $url=~s/\.meta$//;      $url=~s/\.meta$//;
     my %returnhash=();      my %returnhash=();
     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);      my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
     my $prodir=&propath($adomain,$aauthor);      my $prodir=&propath($adomain,$aauthor);
     if ((tie(%evaldata,'GDBM_File',  # Get metadata except counts
             $prodir.'/nohist_resevaldata.db',&GDBM_READER(),0640)) &&      if (tie(%evaldata,'GDBM_File',
         (tie(%newevaldata,'GDBM_File',              $prodir.'/nohist_resevaldata.db',&GDBM_READER(),0640)) {
             $prodir.'/nohist_new_resevaldata.db',&GDBM_WRCREAT(),0640))) {   my %sum=();
        my %sum=();   my %cnt=();
        my %cnt=();   my %concat=();
        my %listitems=('count'        => 'add',   my %listitems=(
                       'course'       => 'add',         'course'       => 'add',
       'goto'         => 'add',         'goto'         => 'add',
       'comefrom'     => 'add',         'comefrom'     => 'add',
                       'avetries'     => 'avg',         'avetries'     => 'avg',
                       'stdno'        => 'add',         'stdno'        => 'add',
                       'difficulty'   => 'avg',         'difficulty'   => 'avg',
                       'clear'        => 'avg',         'clear'        => 'avg',
                       'technical'    => 'avg',         'technical'    => 'avg',
                       'helpful'      => 'avg',         'helpful'      => 'avg',
                       'correct'      => 'avg',         'correct'      => 'avg',
                       'depth'        => 'avg',         'depth'        => 'avg',
                       'comments'     => 'app',         'comments'     => 'app',
                       'usage'        => 'cnt'         'usage'        => 'cnt'
                       );         );
        my $regexp=$url;  
        $regexp=~s/(\W)/\\$1/g;   my $regexp=$url;
        $regexp='___'.$regexp.'___([a-z]+)$';   $regexp=~s/(\W)/\\$1/g;
        while (my ($esckey,$value)=each %evaldata) {   $regexp='___'.$regexp.'___([a-z]+)$';
  $key=&unescape($esckey);   while (my ($esckey,$value)=each %evaldata) {
  if ($key=~/$regexp/) {      $key=&unescape($esckey);
     my $ctype=$1;      if ($key=~/$regexp/) {
             if (defined($cnt{$ctype})) {    my ($item,$purl,$cat)=split(/___/,$_);
                $cnt{$ctype}++;    if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; }
             } else {    unless ($listitems{$cat} eq 'app') {
                $cnt{$ctype}=1;       if (defined($sum{$cat})) {
             }   $sum{$cat}+=$evaldata{$_};
             unless ($listitems{$ctype} eq 'app') {   $concat{$cat}.=','.$item;
                if (defined($sum{$ctype})) {      } else {
                   $sum{$ctype}+=$value;   $sum{$cat}=$evaldata{$_};
           } else {   $concat{$cat}=$item;
                   $sum{$ctype}=$value;      }
        }   } else {
             } else {      if (defined($sum{$cat})) {
                if (defined($sum{$ctype})) {   if ($evaldata{$_}) {
                   if ($value) {      $sum{$cat}.='<hr>'.$evaldata{$_};
                      $sum{$ctype}.='<hr>'.$value;   }
           }      } else {
         } else {   $sum{$cat}=''.$evaldata{$_};
              $sum{$ctype}=''.$value;      }
        }   }
     }      }
     if ($ctype ne 'count') {   }
        $newevaldata{$esckey}=$value;   untie(%evaldata);
    }      }
  }  # construct the return hash for non-count data
       }      my %returnhash=();
       foreach (keys %cnt) {      while ($_=each(%cnt)) {
          if ($listitems{$_} eq 'avg') {   if ($listitems{$_} eq 'avg') {
      $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;      $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;
          } elsif ($listitems{$_} eq 'cnt') {   } elsif ($listitems{$_} eq 'cnt') {
              $returnhash{$_}=$cnt{$_};      $returnhash{$_}=$cnt{$_};
          } else {   } else {
              $returnhash{$_}=$sum{$_};      $returnhash{$_}=$sum{$_};
          }   }
      }   $returnhash{$_.'_list'}=$concat{$_};
      if ($returnhash{'count'}) {      }
          my $newkey=$$.'_'.time.'_searchcat___'.&escape($url).'___count';  # get count
          $newevaldata{$newkey}=$returnhash{'count'};      if (tie(%evaldata,'GDBM_File',
      }              $prodir.'/nohist_accesscount.db',&GDBM_READER(),0640)) {
      untie(%evaldata);   if (! exists($evaldata{$uri})) {
      untie(%newevaldata);      $returnhash{'count'}='Not Available';
    }   } else {
    return %returnhash;      $returnhash{'count'}=$evaldata{$uri};
    }
    untie %evaldata;
       }
       return %returnhash;
 }  }
       
 # ----------------- Code to enable 'find' subroutine listing of the .meta files  # ----------------- Code to enable 'find' subroutine listing of the .meta files
Line 296  my $insert_sth = $dbh->prepare Line 299  my $insert_sth = $dbh->prepare
   
 foreach my $user (@homeusers) {  foreach my $user (@homeusers) {
     print LOG "\n=== User: ".$user."\n\n";      print LOG "\n=== User: ".$user."\n\n";
     # Remove left-over db-files from potentially crashed searchcat run  
     my $prodir=&propath($perlvar{'lonDefDomain'},$user);      my $prodir=&propath($perlvar{'lonDefDomain'},$user);
     unlink($prodir.'/nohist_new_resevaldata.db');  
     # Use find.pl      # Use find.pl
     undef @metalist;      undef @metalist;
     @metalist=();      @metalist=();
Line 340  foreach my $user (@homeusers) { Line 342  foreach my $user (@homeusers) {
     # Need to, perhaps, remove stale SQL database records.      # Need to, perhaps, remove stale SQL database records.
     # ... not yet implemented      # ... not yet implemented
                   
     # ------------------------------------------- Copy over the new db-files  
     #  
   
     system('mv '.$prodir.'/nohist_new_resevaldata.db '.  
    $prodir.'/nohist_resevaldata.db');  
   
 }  }
 # --------------------------------------------------- Close database connection  # --------------------------------------------------- Close database connection
 $dbh->disconnect;  $dbh->disconnect;

Removed from v.1.43  
changed lines
  Added in v.1.44


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