[LON-CAPA-cvs] cvs: modules /gerd/harvesting recommender.pl

www www at source.lon-capa.org
Sun Oct 9 07:44:01 EDT 2011


www		Sun Oct  9 11:44:01 2011 EDT

  Modified files:              
    /modules/gerd/harvesting	recommender.pl 
  Log:
  Associations with current shopping basket
  
  
Index: modules/gerd/harvesting/recommender.pl
diff -u modules/gerd/harvesting/recommender.pl:1.3 modules/gerd/harvesting/recommender.pl:1.4
--- modules/gerd/harvesting/recommender.pl:1.3	Sat Oct  8 18:25:32 2011
+++ modules/gerd/harvesting/recommender.pl	Sun Oct  9 11:44:01 2011
@@ -31,7 +31,6 @@
 # Read current basket
 
 my %basket=();
-
 open(IN,$datapath.'mycart.data') || print("Could not find basket ...\n");
 while (my $line=<IN>) {
    chomp($line);
@@ -55,7 +54,6 @@
    close(OUT);
 }
 
-
 print("Resource data ...\n");
 my @url=();
 
@@ -93,14 +91,36 @@
 
 # Get combined problems
 print("Associations ...\n");
-my @seqs=();
-open(IN,$datapath.'probs_in_seq.dat') || print("Could not read associations ...\n");
+my %assoc=();
+open(IN,$datapath.'associations.dat') || print("Could not read associations ...\n");
 while (my $line=<IN>) {
+   chomp($line);
    my @entries=split(/\t/,$line);
-   push(@seqs,$entries[1]);
+   $assoc{$entries[0]}=$entries[1];
 }
 close(IN);
 
+my %basketassoc=();
+unless ($env{'form.focus'}) {
+   print("Basket Associations ...\n");
+   foreach my $content (keys(%basket)) {
+      for (my $i=0;$i<=$#url;$i++) {
+          if ($basket{$i}) { next; }
+          if ($i<$content) {
+             if ($assoc{$i.','.$content}) {
+                $basketassoc{$i}+=$assoc{$i.','.$content};
+                #print "<br />Forw: $i $content $assoc{$i.','.$content} for $i: $basketassoc{$i}";
+             }
+          } else {
+             if ($assoc{$content.','.$i}) {
+                $basketassoc{$i}+=$assoc{$content.','.$i};
+                #print "<br />Back: $content $i $assoc{$content.','.$i} for $i: $basketassoc{$i}";
+             }
+          }
+      }
+   }
+}
+
 # Get taxonomy
 
 print("Taxonomies ...\n");




More information about the LON-CAPA-cvs mailing list