[LON-CAPA-cvs] cvs: modules /gerd/harvesting lonrecommender.pm

www www at source.lon-capa.org
Thu Jul 12 17:12:17 EDT 2012


www		Thu Jul 12 21:12:17 2012 EDT

  Modified files:              
    /modules/gerd/harvesting	lonrecommender.pm 
  Log:
  Additional routines: read in taxonomy scheme
  
  
Index: modules/gerd/harvesting/lonrecommender.pm
diff -u modules/gerd/harvesting/lonrecommender.pm:1.2 modules/gerd/harvesting/lonrecommender.pm:1.3
--- modules/gerd/harvesting/lonrecommender.pm:1.2	Thu Jul 12 01:22:30 2012
+++ modules/gerd/harvesting/lonrecommender.pm	Thu Jul 12 21:12:17 2012
@@ -5,7 +5,7 @@
 #
 # MODIFY $datapath VARIABLE FOR LOCATION OF DATA FILES
 #
-# $Id: lonrecommender.pm,v 1.2 2012/07/12 01:22:30 www Exp $
+# $Id: lonrecommender.pm,v 1.3 2012/07/12 21:12:17 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -107,6 +107,38 @@
    return %output;
 }
 
+
+# =================================================================================
+#
+#  Return the taxonomy categories and approximate counts, as well as reverse lookup
+#
+
+sub taxonomy_categories {
+   my %output=();
+   my %taxcut=();
+   tie(%taxcut, 'GDBM_File', $datapath.'dbfiles/taxo_categories.db',&GDBM_READER(),0640);
+   foreach my $twhich (keys(%taxcut)) {
+      if ($twhich=~/^\d/) { next; }
+      $output{'cleartext_'.$taxcut{$twhich}}=$twhich;
+      $output{'id_'.$twhich}=$taxcut{$twhich};
+      my $tcat=$taxcut{$taxcut{$twhich}};
+      if ($tcat>100000) {
+         $tcat=int($tcat/10000.+.5)*10000.;
+      } elsif ($tcat>10000) {
+         $tcat=int($tcat/1000.+.5)*1000.;
+      } elsif ($tcat>1000) {
+         $tcat=int($tcat/100.+.5)*100.;
+      } elsif ($tcat>100) {
+         $tcat=int($tcat/10.+.5)*10.;
+      }
+      $tcat=~s/(\d)(\d\d\d)$/$1,$2/;
+      $tcat=~s/(\d)(\d\d\d)\,/$1,$2,/;
+      $output{'count_'.$twhich}=$tcat;
+   }
+   untie(%taxcut);
+   return %output;
+}
+
 # =================================================================================
 #
 #  Return the resource keys that are catalogued with a set of taxonomies
@@ -227,6 +259,24 @@
 
 # =================================================================================
 #
+#  Return the taxonomy associated with a list of resource keys
+#
+
+sub taxoids {
+   my (@which)=@_;
+   my %hash=();
+   my %output=();
+   tie(%hash, 'GDBM_File', $datapath.'dbfiles/taxonomy.db',&GDBM_READER(),0640);
+   foreach my $res (@which) {
+      $output{$res}=$hash{$res};
+      $output{$res}=~s/^\,//;
+   }
+   untie(%hash);
+   return %output;
+}
+
+# =================================================================================
+#
 #  Return the resource keys that match the keywords
 #
 
@@ -291,30 +341,45 @@
 
 sub handle_request {
     my ($r,$c)=@_;
-#
+# ------
 # Get the existing basket
+# This is what the user already has in his or her folder
 #
-    my ($cnum,$cdom,$folder)=split(/\,/,$env{'form.basket'});
-    my %existingres=();
-    if ($folder) {
-       %existingres=&urlres(&mapread($cnum,$cdom,$folder));
-    }
+    my $basket=$env{'form.basket'};
     my @existingbasket=();
-    foreach my $importbasket (values(%existingres)) {
-       if ($importbasket) {
-          push(@existingbasket,$importbasket);
+    if ($basket eq 'cached') {
+# We have been here before
+       @existingbasket=split(/\,/,$env{'form.cachedbasket'});
+    } else {
+# Read the basket and evaluate
+       my ($cnum,$cdom,$folder)=split(/\,/,$basket);
+       my %existingres=();
+       if ($folder) {
+          %existingres=&urlres(&mapread($cnum,$cdom,$folder));
+       }
+       foreach my $importbasket (values(%existingres)) {
+          if ($importbasket) {
+             push(@existingbasket,$importbasket);
+          }
        }
     }
+    my $basketcache=join(',', at existingbasket);
+# ------ Now have array @existingbasket and string $basketcache
+# ------ Read in the taxonomy lookup table
+    my %taxonomy_categories=&taxonomy_categories();
+
+
     $r->print(&Apache::loncommon::start_page("Recommender"));
     $r->print("<h1>Hello World!</h1>");
-    $r->print(join("<br />\n", at existingbasket));
-    &write_groupimportfile(
-         '/res/msu/kortemey/physicsprecourse/functions/chain.problem',
-         '/res/msu/kortemey/physicsprecourse/functions/decay.problem',
-         '/res/msu/kortemey/physicsprecourse/functions/decibels.problem');
-    $r->print("<form method='post' action='/adm/groupsort'>");
-    $r->print("<input type='submit'>");
-    $r->print("</form>");
+
+    my %taxos=&taxoids(3,5,8,90,900,1450,13624,31415);
+    my %urls=&urlres(3,5,8,90,900,1450,13624,31415);
+
+    foreach my $key (keys(%taxos)) {
+       $r->print($key.' '.$urls{$key}.' => '.$taxos{$key}.' '.$taxonomy_categories{'cleartext_'.$taxos{$key}}."<br />\n");
+    }
+
+    
     $r->print(&Apache::loncommon::end_page());
     return 1;
 }




More information about the LON-CAPA-cvs mailing list