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

www www at source.lon-capa.org
Mon Oct 10 09:27:24 EDT 2011


www		Mon Oct 10 13:27:24 2011 EDT

  Modified files:              
    /modules/gerd/harvesting	recommender.pl 
  Log:
  Toy recommender - seems to work now.
  
  
Index: modules/gerd/harvesting/recommender.pl
diff -u modules/gerd/harvesting/recommender.pl:1.5 modules/gerd/harvesting/recommender.pl:1.6
--- modules/gerd/harvesting/recommender.pl:1.5	Sun Oct  9 12:15:48 2011
+++ modules/gerd/harvesting/recommender.pl	Mon Oct 10 13:27:23 2011
@@ -17,9 +17,10 @@
 }
 
 if ($env{'form.preview'}) {
+   my ($id,$path)=($env{'form.preview'}=~/^(\d+)\:(.+)$/);
    print("<html><frameset rows='50%,50%'>\n");
-   print("<frame src='$datahost$env{'form.preview'}' />\n");
-   print("<frame src='/cgi-bin/recommender.pl?focus=".&escape($env{'form.preview'})."' />\n");
+   print("<frame src='$datahost$path' />\n");
+   print("<frame src='/cgi-bin/recommender.pl?focus=".$id."' />\n");
    print("</frameset></html>\n");
    exit;
 }
@@ -56,6 +57,8 @@
 
 print("Resource data ...\n");
 my @url=();
+my @count=();
+my $maxcount=0;
 
 # Get resource URL, etc
 
@@ -63,6 +66,7 @@
 while (my $line=<IN>) {
    my @entries=split(/\t/,$line);
    $url[$entries[0]]=$entries[4];
+   $count[$entries[0]]=$entries[17];
 }
 close(IN);
 
@@ -92,17 +96,38 @@
 # Get combined problems
 print("Associations ...\n");
 my %assoc=();
+my $maxassoc=0;
 open(IN,$datapath.'associations.dat') || print("Could not read associations ...\n");
 while (my $line=<IN>) {
    chomp($line);
    my @entries=split(/\t/,$line);
    $assoc{$entries[0]}=$entries[1];
+   if ($entries[1]>$maxassoc) { $maxassoc=$entries[1]; }
+   if ($count[$entries[0]]>$maxcount) { $maxcount=$count[$entries[0]]; }
 }
 close(IN);
 
 my %basketassoc=();
 my @basketresults=();
-unless ($env{'form.focus'}) {
+my $maxbasketassoc=0;
+if ($env{'form.focus'}) {
+   print("Resource Associations ...\n");
+   my $content=$env{'form.focus'};
+   for (my $i=0;$i<=$#url;$i++) {
+       if ($basket{$i}) { next; }
+       if ($i<$content) {
+          if ($assoc{$i.','.$content}) {
+             $basketassoc{$i}+=$assoc{$i.','.$content};
+          }
+       } else {
+          if ($assoc{$content.','.$i}) {
+             $basketassoc{$i}+=$assoc{$content.','.$i};
+          }
+       }
+       if ($basketassoc{$i}>$maxbasketassoc) { $maxbasketassoc=$basketassoc{$i}; }
+   }
+   @basketresults=sort{$basketassoc{$b}<=>$basketassoc{$a}}(keys(%basketassoc));
+} else {
    print("Basket Associations ...\n");
    foreach my $content (keys(%basket)) {
       for (my $i=0;$i<=$#url;$i++) {
@@ -116,6 +141,7 @@
                 $basketassoc{$i}+=$assoc{$content.','.$i};
              }
           }
+          if ($basketassoc{$i}>$maxbasketassoc) { $maxbasketassoc=$basketassoc{$i}; }
       }
    }
    @basketresults=sort{$basketassoc{$b}<=>$basketassoc{$a}}(keys(%basketassoc));
@@ -151,8 +177,16 @@
 #
 # This is the focus on one resource
 #
-  print "<h3>Focus: <tt>$env{'form.focus'}</tt></h3>\n";
-  print "<a href='/cgi-bin/recommender.pl' target='_top'>Back to Basket</a>";
+  print "<h3>Focus</h3>\n";
+  &outputlink($url[$env{'form.focus'}],'view',$env{'form.focus'});
+  print "<br /><a href='/cgi-bin/recommender.pl' target='_top'>Back to Basket</a>";
+  print("<h3>Resource Recommendations</h3>"); 
+  for (my $i=0;$i<=15; $i++) {
+      if ($basketresults[$i]) {
+         &outputlink($url[$basketresults[$i]],'view',$basketresults[$i]);
+      }
+  }
+
 } else {
   print "\n<hr />\n";
   foreach my $thissub (sort(keys(%subs))) {
@@ -208,7 +242,7 @@
 
 # Search results
    if (($env{'form.search'}) || ($env{'form.taxsearch'})) {
-      print("<h3>Search Results</h3>");
+      print("<h3>".($env{'form.search'}?'Search':'Taxonomy')." Results</h3>");
       my @results=();
       if ($env{'form.search'}) {
           for (my $i=0; $i<=$#keywords; $i++) {
@@ -228,6 +262,12 @@
               }
           }
       }
+      my $ba=1.;
+      if ($maxbasketassoc) { $ba=1./$maxbasketassoc; }
+      my $ma=1.;
+      if ($maxcount) { $ma=1./$maxcount; }
+      @results=sort{$count[$b]*$ma+$basketassoc{$b}*$ba<=>$count[$a]*$ma+$basketassoc{$a}*$ba}(@results);
+
       for (my $i=0; $i<=20; $i++) {
          if ($results[$i]) {
             &outputlink($url[$results[$i]],'view',$i);
@@ -263,7 +303,7 @@
    }
    print("</tt>");
    unless ($dirflag) {
-      print("/<a href='/cgi-bin/recommender.pl?preview=".&escape($path)."' target='_top'>$parts[-1]</a>");
+      print("/<a href='/cgi-bin/recommender.pl?preview=".$i.':'.&escape($path)."' target='_top'>$parts[-1]</a>");
       if ($mode eq 'view') {
          print("&nbsp<a href='/cgi-bin/recommender.pl?add=$i'>Add</a>");
       }




More information about the LON-CAPA-cvs mailing list