myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2584] branches/topics: code provided by UPenn, w


From: noreply
Subject: [myexperiment-hackers] [2584] branches/topics: code provided by UPenn, with minor integration changes
Date: Mon, 11 Apr 2011 09:33:17 -0400 (EDT)

Revision
2584
Author
dgc
Date
2011-04-11 09:33:17 -0400 (Mon, 11 Apr 2011)

Log Message

code provided by UPenn, with minor integration changes

Modified Paths

Added Paths

Diff

Modified: branches/topics/app/controllers/application.rb (2583 => 2584)


--- branches/topics/app/controllers/application.rb	2011-04-11 09:45:26 UTC (rev 2583)
+++ branches/topics/app/controllers/application.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -445,6 +445,13 @@
           :label  => 'Licence',
           :joins  => [ :licences ],
           :order  => 'licenses.title, rank DESC'
+        },
+
+        {
+          :option => 'topic',
+          :label  => 'Topic',
+          :joins  => [ :topic_workflow_map ],
+          :order  => 'topic_workflow_map.probability, rank DESC'
         }
       ],
 
@@ -532,7 +539,8 @@
         :credits             => "INNER JOIN creditations ON creditations.creditable_type = contributions.contributable_type AND creditations.creditable_id = contributions.contributable_id",
         :curation_events     => "INNER JOIN curation_events ON curation_events.object_type = contributions.contributable_type AND curation_events.object_id = contributions.contributable_id",
         :workflow_processors => "INNER JOIN workflow_processors ON contributions.contributable_type = 'Workflow' AND workflow_processors.workflow_id = contributions.contributable_id",
-        :search              => "RIGHT OUTER JOIN search_results ON search_results.result_type = contributions.contributable_type AND search_results.result_id = contributions.contributable_id"
+        :search              => "RIGHT OUTER JOIN search_results ON search_results.result_type = contributions.contributable_type AND search_results.result_id = contributions.contributable_id",
+        :topic_workflow_map  => "INNER JOIN topic_workflow_map ON contributions.id = topic_workflow_map.workflow_id"
       }
     }
   end

Added: branches/topics/app/controllers/topics_controller.rb (0 => 2584)


--- branches/topics/app/controllers/topics_controller.rb	                        (rev 0)
+++ branches/topics/app/controllers/topics_controller.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,133 @@
+# -*- coding: undecided -*-
+# myExperiment: app/controllers/topics_controller.rb
+#
+# Copyright (c) 2007 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class TopicsController < ApplicationController
+  before_filter :login_required, :except => [:index, :show]
+  
+
+  # declare sweepers and which actions should invoke them
+  cache_sweeper :workflow_sweeper, : [ :create, :create_version, :launch, :update, :update_version, :destroy_version, :destroy ]
+  cache_sweeper :download_viewing_sweeper, : [ :show, :download, :named_download, :launch ]
+  cache_sweeper :permission_sweeper, : [ :create, :update, :destroy ]
+  cache_sweeper :bookmark_sweeper, : [ :destroy, :favourite, :favourite_delete ]
+  cache_sweeper :tag_sweeper, : [ :create, :update, :tag, :destroy ]
+  cache_sweeper :comment_sweeper, : [ :comment, :comment_delete ]
+  cache_sweeper :rating_sweeper, : [ :rate ]
+  
+  # These are provided by the Taverna gem
+  require 'scufl/model'
+  require 'scufl/parser'
+  require 'scufl/dot'
+ 
+  # GET /topics
+  def index
+    respond_to do |format|
+      format.html do
+		@curr_run = TopicRun.most_recent
+      end
+    end
+  end
+  
+  def show
+	respond_to do |format|
+	  format.html do
+	    @currtopic = Topic.find(params[:id])
+	  end
+	end  
+  end
+  
+  def tag_feedback
+    # Ensure that all the needed information was provided
+    if params[:topic_id].blank? || params[:user_id].blank? || params[:tag_id].blank? || params[:score].blank?
+      error("Malformed feedback information.", "")
+    else
+      this_topic = Topic.find(params[:topic_id]) rescue error("Invalid topic specified.")	
+      #Ensure the feedback is for the current user
+      if params[:user_id].to_i != current_user.id
+        error("You may only post feedback as yourself.", "")
+        return
+      end
+      # Not allowed to create duplicate feedback
+      if this_topic.topic_tag_feedback.exists?( :user_id => params[:user_id], :tag_id => params[:tag_id] )
+        error( "You may provide feedback only once per topic, tag pair.", "")
+        return
+      end
+      #Create the feedback
+      feedback = this_topic.topic_tag_feedback.build( :score => params[:score], :submit_dt => Time.new.utc )
+      feedback.user = User.find(params[:user_id])
+      feedback.tag = Tag.find(params[:tag_id])
+      feedback.save
+      #topic_id => params[:topic_id], :user_id => params[:user_id], :tag_id => params[:tag_id], 
+         
+      # What if the tag doesn't exist?
+      
+      respond_to do |response|
+        # page.html {redirect_to topics_path }
+        response.html {
+          render :update  do |page|
+            page.replace_html "tag_feedback_div_#{params[:topic_id]}_#{params[:tag_id]}", "Thanks!"
+          end
+        }
+      end
+    end
+  end
+  
+  def topic_feedback
+  	# Ensure that all the needed information was provided
+    if params[:topic_id].blank? || params[:user_id].blank? || params[:score].blank?
+      error("Malformed feedback information.", "")
+    else
+      this_topic = Topic.find(params[:topic_id]) rescue error("Invalid topic specified.")	
+      #Ensure the feedback is for the current user
+      if params[:user_id].to_i != current_user.id
+        error("You may only post feedback as yourself.", "")
+        return
+      end
+      # Not allowed to create duplicate feedback
+      if this_topic.topic_feedback.exists?( :user_id => params[:user_id] )
+        error( "You may provide feedback only once per topic.", "")
+        return
+      end
+      #Create the feedback
+      feedback = this_topic.topic_feedback.build( :score => params[:score], :submit_dt => Time.new.utc )
+      feedback.user = User.find(params[:user_id])
+      feedback.save
+      
+      respond_to do |response|
+        # page.html {redirect_to topics_path }
+        response.html {
+          render :update  do |page|
+
+            if
+              this_topic.name.blank? 
+            then
+              topicName = "Topic #{this_topic.id}" 
+            else
+              topicName = this_topic.name 
+            end
+
+            topicLink = "<a href=""
+
+            page.replace_html "topic_feedback_#{params[:topic_id]}", "#{topicLink} &nbsp;&nbsp;&nbsp;Thanks for your feedback!"
+          end
+        }
+      end
+    end
+  end
+
+private
+
+  def error(notice, message, attr=:id)
+    flash[:error] = notice
+    (err = Workflow.new.errors).add(attr, message)
+    
+    respond_to do |format|
+      format.html { redirect_to topics_url }
+    end
+  end
+  
+end
+

Added: branches/topics/app/models/topic.rb (0 => 2584)


--- branches/topics/app/models/topic.rb	                        (rev 0)
+++ branches/topics/app/models/topic.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,32 @@
+# myExperiment: app/models/topic.rb
+#
+
+class Topic < ActiveRecord::Base
+  
+  belongs_to :run, :class_name => "TopicRun", :foreign_key => "run_id"
+  
+  has_many :topic_tag_map,
+           :class_name => "TopicTagMap",
+		   :foreign_key => :topic_id,
+		   :dependent => :destroy
+		   
+  has_many :topic_workflow_map,
+           :class_name => "TopicWorkflowMap",
+		   :foreign_key => :topic_id,
+		   :dependent => :destroy		   
+
+  has_many :topic_tag_feedback,
+           :class_name => "TopicTagFeedback",
+           :foreign_key => :topic_id,
+           :dependent => :destroy
+		   
+  has_many :topic_feedback,
+           :class_name => "TopicFeedback",
+           :foreign_key => :topic_id,
+           :dependent => :destroy
+		   
+  def name
+    self.attributes["name"]
+  end
+		   
+end
\ No newline at end of file

Added: branches/topics/app/models/topic_run.rb (0 => 2584)


--- branches/topics/app/models/topic_run.rb	                        (rev 0)
+++ branches/topics/app/models/topic_run.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,31 @@
+# myExperiment: app/models/topic_run.rb
+#
+
+require 'acts_as_site_entity'
+require 'acts_as_contributable'
+require 'acts_as_creditable'
+require 'acts_as_attributor'
+require 'acts_as_attributable'
+require 'explicit_versioning'
+require 'acts_as_reviewable'
+require 'acts_as_runnable'
+
+require 'scufl/model'
+require 'scufl/parser'
+
+class TopicRun < ActiveRecord::Base
+
+  attr_accessor :desc, :runtime
+
+  has_many :topics,
+           :class_name => "Topic",
+           :foreign_key => :run_id,
+           :dependent => :destroy
+		   
+  def self.most_recent
+    self.find(
+	  :first,
+	  :order => 'topic_runs.id DESC')
+  end
+		   
+end

Added: branches/topics/app/models/topic_tag_map.rb (0 => 2584)


--- branches/topics/app/models/topic_tag_map.rb	                        (rev 0)
+++ branches/topics/app/models/topic_tag_map.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,29 @@
+require 'acts_as_site_entity'
+require 'acts_as_contributable'
+require 'acts_as_creditable'
+require 'acts_as_attributor'
+require 'acts_as_attributable'
+require 'explicit_versioning'
+require 'acts_as_reviewable'
+require 'acts_as_runnable'
+
+require 'scufl/model'
+require 'scufl/parser'
+
+class TopicTagMap < ActiveRecord::Base
+  set_table_name "topic_tag_map"
+  
+  attr_accessible :probability
+
+  belongs_to :topic
+  validates_presence_of :topic
+  
+  belongs_to :tag
+  validates_presence_of :tag
+  
+  def self.probability_ordered_tags
+	self.find(
+	  :all,
+	  :order => 'topic_tag_map.probability DESC')
+  end
+end
\ No newline at end of file

Added: branches/topics/app/models/topic_workflow_map.rb (0 => 2584)


--- branches/topics/app/models/topic_workflow_map.rb	                        (rev 0)
+++ branches/topics/app/models/topic_workflow_map.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,21 @@
+require 'acts_as_site_entity'
+require 'acts_as_contributable'
+require 'acts_as_creditable'
+require 'acts_as_attributor'
+require 'acts_as_attributable'
+require 'explicit_versioning'
+require 'acts_as_reviewable'
+require 'acts_as_runnable'
+
+require 'scufl/model'
+require 'scufl/parser'
+
+class TopicWorkflowMap < ActiveRecord::Base
+  set_table_name "topic_workflow_map"  
+  
+  belongs_to :topic
+  validates_presence_of :topic
+  
+  belongs_to :workflow
+  validates_presence_of :workflow
+end
\ No newline at end of file

Added: branches/topics/app/views/topics/_breadcrumbs.rhtml (0 => 2584)


--- branches/topics/app/views/topics/_breadcrumbs.rhtml	                        (rev 0)
+++ branches/topics/app/views/topics/_breadcrumbs.rhtml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,11 @@
+<li><%= link_to 'Topics', workflows_path %></li>
+
+<% if ["show", "new", "edit", "search", "all", "new_version", "edit_version", "comments_timeline"].include? controller.action_name.to_s %>
+  <li><b>&#187;</b></li>
+  
+  <% case controller.action_name.to_s; when "show" %>
+    <li><%=  %></li>
+  <% else %>
+    <!-- no breadcrumb -->
+  <% end %>
+<% end %>

Added: branches/topics/app/views/topics/_subnav.rhtml ( => )


Added: branches/topics/app/views/topics/_topic_feedback.rhtml
===================================================================
--- branches/topics/app/views/topics/_topic_feedback.rhtml	                        (rev 0)
+++ branches/topics/app/views/topics/_topic_feedback.rhtml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,10 @@
+<%= "<div id=\"topic_feedback_#{topic.id}\" class=\"topic_feedback\">" %>
+
+<% if topic.topic_feedback.exists?( :user_id => current_user ) %>
+        Thanks for your feedback!
+<% else %>
+        Please rate this topic&nbsp;&nbsp;
+        <%= link_to_remote( "<img src="" {:url ="" { :controller => "topics", :action ="" "topic_feedback", :topic_id => topic.id, :user_id => current_user.id, :score => 1 } } ) %>
+        <%= link_to_remote( "<img src="" {:url ="" { :controller => "topics", :action ="" "topic_feedback", :topic_id => topic.id, :user_id => current_user.id, :score => -1 } } ) %>
+<% end %>
+</div>

Added: branches/topics/app/views/topics/_topic_tag_cloud.rhtml (0 => 2584)


--- branches/topics/app/views/topics/_topic_tag_cloud.rhtml	                        (rev 0)
+++ branches/topics/app/views/topics/_topic_tag_cloud.rhtml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,18 @@
+<% unless tags.empty? %>
+	<!-- <h2>Top <%= tags.length %> tags for Topic <%= topicname %>&nbsp;&nbsp;&nbsp;</h2> -->
+	<% tag_cloud = tags.map { |gmap| item = gmap.tag; 
+		def item.probability
+			@probability
+		end;
+		def item.probability=(p)
+			@probability = p
+		end;
+		item.probability= gmap.probability;
+		def item.taggings_count
+			self.probability
+		end; 
+		item } %>
+	<br/>
+	<%= tag_cloud_from_collection(tag_cloud, false, "topics") %>
+	<br/>	
+ <% end %>

Added: branches/topics/app/views/topics/index.rhtml (0 => 2584)


--- branches/topics/app/views/topics/index.rhtml	                        (rev 0)
+++ branches/topics/app/views/topics/index.rhtml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,32 @@
+<h1><%= feed_icon_tag "Latest Topics", formatted_workflows_path(:rss), "margin-right: 0.3em;" -%> Topics</h1>
+
+<div id="topic container">
+	<% @curr_run.topics.each do |topic| -%>
+           <% topicName = (if topic.name.blank? then "Topic #{topic.id}" else "#{topic.name}" end) -%>
+	   <h2>
+		<% if logged_in? %>
+
+			<%= "<div id=\"topic_feedback_#{topic.id}\" class=\"topic_feedback\">" %>
+				<!-- <%= "<a href="" %> -->
+				<%= "<a href="" this topic</a>" %> 
+
+				<% if topic.topic_feedback.exists?( :user_id => current_user ) %>
+        				&nbsp;&nbsp;&nbsp;Thanks for your feedback!
+				<% else %>
+        				&nbsp;&nbsp;&nbsp;Please rate this topic&nbsp;&nbsp;
+        				<%= link_to_remote( "<img src="" {:url ="" { :controller => "topics", :action ="" "topic_feedback", :topic_id => topic.id, :user_id => current_user.id, :score => 1 } } ) %>
+        				<%= link_to_remote( "<img src="" {:url ="" { :controller => "topics", :action ="" "topic_feedback", :topic_id => topic.id, :user_id => current_user.id, :score => -1 } } ) %>
+				<% end %>
+			</div>
+		<% else %>
+			<!-- <%= "<a href="" %> -->
+			<%= "<a href="" this topic</a>" %>
+		<% end %>
+	   </h2>
+
+	   <%= "<div id=\"tag_cloud_container_#{topic.id}\">" %>
+ 			<%= render :partial => "topics/topic_tag_cloud", :locals => {:tags => topic.topic_tag_map, :topicname => topicName } %>
+     </div> 
+	<% end -%>
+</div>
+

Added: branches/topics/app/views/topics/show.rhtml (0 => 2584)


--- branches/topics/app/views/topics/show.rhtml	                        (rev 0)
+++ branches/topics/app/views/topics/show.rhtml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,11 @@
+<% topicName = (if @currtopic.name.blank? then "Topic address@hidden" else " address@hidden" end) -%>
+<!-- <%= "<h1>Workflows for #{topicName}</h1>" %> -->
+<%= "<h1>Workflows in This Topic</h1>" %> 
+
+<% cache(:controller => 'workflows', :action ="" 'all_tags') do -%>
+	<%= render :partial => "topics/topic_tag_cloud", :locals => {:tags => @currtopic.topic_tag_map, :topicname => topicName } %>
+<% end -%>
+
+<% workflow_collection = @currtopic.topic_workflow_map.map { |tmap| tmap.workflow } %>
+<%= render :partial => "workflows/table", :locals => {:collection => workflow_collection} %>
+

Added: branches/topics/bin/TopicsGenerator.jar


(Binary files differ)
Property changes on: branches/topics/bin/TopicsGenerator.jar ___________________________________________________________________

Added: svn:mime-type

Added: branches/topics/bin/mySQLConnectBundle.properties (0 => 2584)


--- branches/topics/bin/mySQLConnectBundle.properties	                        (rev 0)
+++ branches/topics/bin/mySQLConnectBundle.properties	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,5 @@
+user=root
+pass=
+host=localhost
+port=3306
+schema=topics

Added: branches/topics/bin/topicsGen.sh (0 => 2584)


--- branches/topics/bin/topicsGen.sh	                        (rev 0)
+++ branches/topics/bin/topicsGen.sh	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# place the file mySQLConnectBundle.properties
+# into the current directory
+
+jar uf TopicsGenerator.jar mySQLConnectBundle.properties
+java -jar TopicsGenerator.jar --num-topics 20 --optimize-interval 10 --num-top-words 20 >> topicsExplorer.log 2>&1
Property changes on: branches/topics/bin/topicsGen.sh
___________________________________________________________________

Added: svn:executable

Modified: branches/topics/config/default_settings.yml (2583 => 2584)


--- branches/topics/config/default_settings.yml	2011-04-11 09:45:26 UTC (rev 2583)
+++ branches/topics/config/default_settings.yml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -160,6 +160,10 @@
     link:       /packs
     controller: packs
 
+  - label:      Topics
+    link:       /topics
+    controller: topics
+	
 # new_menu - Set "new_menu" with the details of each kind of thing to appear in
 #            the New/Upload gadget.
 #

Modified: branches/topics/config/routes.rb (2583 => 2584)


--- branches/topics/config/routes.rb	2011-04-11 09:45:26 UTC (rev 2583)
+++ branches/topics/config/routes.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -252,6 +252,12 @@
   
   map.connect 'files/:id/download/:name', :controller => 'blobs', :action ="" 'named_download', :requirements => { :name => /.*/ }
 
+  # map.connect 'topics', :controller => 'topics', :action ="" 'index'
+  map.connect 'topics/tag_feedback', :controller => 'topics', :action ="" 'tag_feedback'
+  map.connect 'topics/topic_feedback', :controller => 'topics', :action ="" 'topic_feedback'
+  map.resources :topics
+
+  # map.connect 'topics/:id', :controller => 'topics', :action ="" 'show'
   # (general) announcements
   # NB! this is moved to the bottom of the file for it to be discovered
   # before 'announcements' resource within 'groups'

Added: branches/topics/config/schema.d/topics.xml (0 => 2584)


--- branches/topics/config/schema.d/topics.xml	                        (rev 0)
+++ branches/topics/config/schema.d/topics.xml	2011-04-11 13:33:17 UTC (rev 2584)
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<schema>
+
+  <table name="topics">
+
+    <column type="string"   name="name"/>
+    <column type="integer"  name="run_id"/>
+    <column type="integer"  name="orig_run_id"/>
+
+  </table>
+
+  <table name="topic_runs">
+
+    <column type="string"   name="description"/>
+    <column type="datetime" name="runtime"/>
+
+  </table>
+
+  <table name="topic_tag_map">
+
+    <column type="integer"  name="topic_id"/>
+    <column type="integer"  name="tag_id"/>
+    <column type="float"    name="probability"/>
+    <column type="boolean"  name="display_flag"/>
+
+  </table>
+
+  <table name="topic_workflow_map">
+
+    <column type="integer"  name="topic_id"/>
+    <column type="integer"  name="workflow_id"/>
+    <column type="float"    name="probability"/>
+    <column type="boolean"  name="display_flag"/>
+
+  </table>
+
+  <table name="topic_feedback">
+
+    <column type="integer"  name="user_id"/>
+    <column type="integer"  name="topic_id"/>
+    <column type="integer"  name="score"/>
+    <column type="datetime" name="submit_dt"/>
+
+  </table>
+
+</schema>
+

Added: branches/topics/public/images/thumbsdown.png


(Binary files differ)
Property changes on: branches/topics/public/images/thumbsdown.png ___________________________________________________________________

Added: svn:mime-type

Added: branches/topics/public/images/thumbsup.png


(Binary files differ)
Property changes on: branches/topics/public/images/thumbsup.png ___________________________________________________________________

Added: svn:mime-type

Modified: branches/topics/public/stylesheets/styles.css (2583 => 2584)


--- branches/topics/public/stylesheets/styles.css	2011-04-11 09:45:26 UTC (rev 2583)
+++ branches/topics/public/stylesheets/styles.css	2011-04-11 13:33:17 UTC (rev 2584)
@@ -2033,6 +2033,42 @@
   padding-top: 1em;
 }
 
+/* Styles Related to topics */
+
+table.topic {
+  border-collapse:collapse;
+  border: 1px solid black;
+  width: 40%;
+}
+
+table.topic th{
+  border: 1px solid black;
+  text-align:center;
+  width: 100%;
+  background-color: #FFFFCC; 
+}
+
+table.topic div.topic_feedback{
+  text-align:center;
+  margin-top:7px;
+}
+
+table.topic td.tag{
+  text-align:left;
+  width: 60%;
+}
+
+table.topic div.topic_feedback a:link{
+  text-decoration:underline;
+}
+
+table.topic td.tag_vote{
+  text-align:center;
+  width: 40%;
+}
+
+/* End syles related to topics */
+
 /* pivot */
 
 .pivot {

Modified: branches/topics/vendor/plugins/acts_as_taggable_redux/lib/tag.rb (2583 => 2584)


--- branches/topics/vendor/plugins/acts_as_taggable_redux/lib/tag.rb	2011-04-11 09:45:26 UTC (rev 2583)
+++ branches/topics/vendor/plugins/acts_as_taggable_redux/lib/tag.rb	2011-04-11 13:33:17 UTC (rev 2584)
@@ -1,5 +1,6 @@
 class Tag < ActiveRecord::Base
   has_many :taggings
+  has_many :topic_tag_map
   belongs_to :vocabulary
 
   # Parse a text string into an array of tokens for use as tags

reply via email to

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