myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2690] trunk: added task to update topic titles


From: noreply
Subject: [myexperiment-hackers] [2690] trunk: added task to update topic titles
Date: Tue, 6 Sep 2011 11:55:11 -0400 (EDT)

Revision
2690
Author
dgc
Date
2011-09-06 11:55:11 -0400 (Tue, 06 Sep 2011)

Log Message

added task to update topic titles

Modified Paths

Diff

Modified: trunk/Rakefile (2689 => 2690)


--- trunk/Rakefile	2011-09-06 15:04:05 UTC (rev 2689)
+++ trunk/Rakefile	2011-09-06 15:55:11 UTC (rev 2690)
@@ -126,3 +126,12 @@
   end
 end
 
+desc 'Update topic titles'
+task "myexp:topic:update_titles" do
+  require File.dirname(__FILE__) + '/config/environment'
+
+  Topic.find(:all).each do |topic|
+    topic.update_title
+  end
+end
+

Modified: trunk/app/models/topic.rb (2689 => 2690)


--- trunk/app/models/topic.rb	2011-09-06 15:04:05 UTC (rev 2689)
+++ trunk/app/models/topic.rb	2011-09-06 15:55:11 UTC (rev 2690)
@@ -29,4 +29,14 @@
     self.attributes["name"]
   end
 		   
-end
\ No newline at end of file
+  def update_title
+
+    # get tags and ensure they are sorted with the most probability first
+    tags = topic_tag_map.sort do |a, b| b.probability <=> a.probability end
+
+    # title is the first three (most probable) tags
+    title = tags[0..2].map do |ttm| ttm.tag.name end.join(" - ")
+
+    update_attribute(:name, title)
+  end
+end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]