myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [1928] trunk: New tabs added to index pages:


From: noreply
Subject: [myexperiment-hackers] [1928] trunk: New tabs added to index pages:
Date: Fri, 7 Nov 2008 09:51:45 -0500 (EST)

Revision
1928
Author
alekses6
Date
2008-11-07 09:51:44 -0500 (Fri, 07 Nov 2008)

Log Message

New tabs added to index pages:
- Users: "Most Friends", "Highest Rated", "Most Credited"
- Groups: "Most Members", "Most Shared Items", "Most Credited"
- Packs: "Most Items", "Most Favourited"
- Workflows: "Most Favourited"
- Files: "Most Favourited"

Improved the way average rating is calculated for users.

Modified Paths

Diff

Modified: trunk/app/models/contribution.rb (1927 => 1928)


--- trunk/app/models/contribution.rb	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/models/contribution.rb	2008-11-07 14:51:44 UTC (rev 1928)
@@ -64,6 +64,18 @@
               :include => [ { :policy => :permissions } ])
   end
   
+  # returns the 'most favourited' Contributions
+  # the maximum number of results is set by #limit#
+  def self.most_favourited(limit=10, klass=nil)
+    if klass
+      type_condition = "WHERE c.contributable_type = '#{klass}'"
+    else
+      type_condition = ""
+    end
+    
+    self.find_by_sql("SELECT c.*, COUNT(b.bookmarkable_id) AS cnt FROM contributions c JOIN bookmarks b ON c.contributable_type = b.bookmarkable_type AND c.contributable_id = b.bookmarkable_id #{type_condition} GROUP BY b.bookmarkable_id ORDER BY cnt DESC LIMIT #{limit}")
+  end
+  
   # is c_utor authorized to edit the policy for this contribution
   def admin?(c_utor)
     #policy.contributor_id.to_i == c_utor.id.to_i and policy.contributor_type.to_s == c_utor.class.to_s

Modified: trunk/app/models/network.rb (1927 => 1928)


--- trunk/app/models/network.rb	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/models/network.rb	2008-11-07 14:51:44 UTC (rev 1928)
@@ -26,6 +26,18 @@
     self.find(:all, :order => "created_at DESC", :limit => limit)
   end
   
+  # returns groups with most members
+  # the maximum number of results is set by #limit#
+  def self.most_members(limit=10)
+    self.find_by_sql("SELECT n.* FROM networks n JOIN memberships m ON n.id = m.network_id WHERE m.user_established_at IS NOT NULL AND m.network_established_at IS NOT NULL GROUP BY m.network_id ORDER BY COUNT(m.network_id) DESC, n.title LIMIT #{limit}")
+  end
+  
+  # returns groups with most shared items
+  # the maximum number of results is set by #limit#
+  def self.most_shared_items(limit=10)
+    self.find_by_sql("SELECT n.* FROM networks n JOIN permissions perm ON n.id = perm.contributor_id AND perm.contributor_type = 'Network' JOIN policies p ON perm.policy_id = p.id JOIN contributions c ON p.id = c.policy_id GROUP BY perm.contributor_id ORDER BY COUNT(perm.contributor_id) DESC, n.title LIMIT #{limit}")
+  end
+  
   # protected? asks the question "is other protected by me?"
   def protected?(other)
     if other.kind_of? User        # if other is a User...
@@ -262,7 +274,7 @@
     list = []
     self.permissions.each do |p|
       p.policy.contributions.each do |c|
-        list << c
+        list << c unless c.nil? || c.contributable.nil?
       end
     end
     list

Modified: trunk/app/models/pack.rb (1927 => 1928)


--- trunk/app/models/pack.rb	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/models/pack.rb	2008-11-07 14:51:44 UTC (rev 1928)
@@ -36,7 +36,13 @@
     return contributable_entries_count + remote_entries_count
   end
   
+  # returns packs that have largest total number of items
+  # the maximum number of results is set by #limit#
+  def self.most_items(limit=10)
+    self.find_by_sql("SELECT * FROM ((SELECT p.*, contrib.pack_id FROM packs p JOIN pack_contributable_entries contrib ON contrib.pack_id = p.id) UNION ALL (SELECT p.*, remote.pack_id FROM packs p JOIN pack_remote_entries remote ON remote.pack_id = p.id)) AS pack_items GROUP BY pack_id ORDER BY COUNT(pack_id) DESC, title LIMIT #{limit}")
+  end
   
+  
   def self.archive_folder
     # single declaration point of where the zip archives for downloadable packs would live
     return "tmp/packs"

Modified: trunk/app/models/user.rb (1927 => 1928)


--- trunk/app/models/user.rb	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/models/user.rb	2008-11-07 14:51:44 UTC (rev 1928)
@@ -46,6 +46,18 @@
             
   end
   
+  # returns packs that have largest number of friends
+  # the maximum number of results is set by #limit#
+  def self.most_friends(limit=10)
+    self.find_by_sql("SELECT u.* FROM users u JOIN friendships f ON (u.id = f.user_id OR u.id = f.friend_id) AND f.accepted_at IS NOT NULL GROUP BY u.id ORDER BY COUNT(u.id) DESC, u.name LIMIT #{limit}")
+  end
+  
+  # returns packs that have largest number of friends
+  # the maximum number of results is set by #limit#
+  def self.highest_rated(limit=10)
+    self.find_by_sql("SELECT u.* FROM ratings r JOIN contributions c ON r.rateable_type = c.contributable_type AND r.rateable_id = c.contributable_id JOIN users u ON c.contributor_type = 'User' AND c.contributor_id = u.id GROUP BY u.id ORDER BY AVG(r.rating) DESC, u.name LIMIT #{limit}")
+  end
+  
   acts_as_tagger
   
   has_many :ratings,
@@ -599,6 +611,13 @@
     return ratings
   end
   
+  # user's average rating for all contributions
+  def average_rating_and_count
+    result_set = User.find_by_sql("SELECT AVG(r.rating) AS avg_rating, COUNT(r.rating) as rating_count FROM ratings r JOIN contributions c ON r.rateable_type = c.contributable_type AND r.rateable_id = c.contributable_id JOIN users u ON c.contributor_type = 'User' AND c.contributor_id = u.id WHERE u.id = #{self.id.to_s} GROUP BY u.id")
+    return [0,0] if result_set.empty?
+    return [result_set[0]["avg_rating"], result_set[0]["rating_count"]]
+  end
+  
 protected
 
   # clean up emails and username before validation

Modified: trunk/app/views/contributions/_most_tabs.rhtml (1927 => 1928)


--- trunk/app/views/contributions/_most_tabs.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/views/contributions/_most_tabs.rhtml	2008-11-07 14:51:44 UTC (rev 1928)
@@ -41,4 +41,13 @@
 	  	</div>
 	  </div> 
 	<% end %>
-<% end -%>
\ No newline at end of file
+<% end -%>
+
+<% unless (most_f = Contribution.most_favourited(10, type)).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most Favourited</div>
+  	<div class="tabContent">
+	    <%= render :partial => "contributions/list", :locals => { :collection => most_f, :table => true } %>
+  	</div>
+  </div> 
+<% end %>
\ No newline at end of file

Modified: trunk/app/views/networks/index.rhtml (1927 => 1928)


--- trunk/app/views/networks/index.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/views/networks/index.rhtml	2008-11-07 14:51:44 UTC (rev 1928)
@@ -28,3 +28,30 @@
   	</div>
   </div>
 <% end %>
+
+<% unless (largest = Network.most_members).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most Members</div>
+  	<div class="tabContent">
+	    <%= render :partial => "networks/table", :locals => { :collection => largest } %>
+  	</div>
+  </div>
+<% end %>
+
+<% unless (rich = Network.most_shared_items).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most Shared Items</div>
+  	<div class="tabContent">
+	    <%= render :partial => "networks/table", :locals => { :collection => rich } %>
+  	</div>
+  </div>
+<% end %>
+
+<% unless (credited = Network.most_credited).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most Credited</div>
+  	<div class="tabContent">
+	    <%= render :partial => "networks/table", :locals => { :collection => credited } %>
+  	</div>
+  </div>
+<% end %>

Modified: trunk/app/views/packs/index.rhtml (1927 => 1928)


--- trunk/app/views/packs/index.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/views/packs/index.rhtml	2008-11-07 14:51:44 UTC (rev 1928)
@@ -35,3 +35,12 @@
 <% end -%>
 
 <%= render :partial => "contributions/most_tabs", :locals => { :type => "Pack" } %>
+
+<% unless (largest = Pack.most_items).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most items</div>
+  	<div class="tabContent">
+	    <%= render :partial => "packs/table", :locals => { :collection => largest } %>
+  	</div>
+  </div>
+<% end %>

Modified: trunk/app/views/users/index.rhtml (1927 => 1928)


--- trunk/app/views/users/index.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/views/users/index.rhtml	2008-11-07 14:51:44 UTC (rev 1928)
@@ -4,7 +4,7 @@
 	<li><%= icon "timeline", url_for(:action ="" 'timeline'), nil, nil, "View Timeline of Users" %></li>
 </ul>
 
-<div id="tabsContainer" class="tabsContainer"></div>
+<div id="tabsContainer" class="tabsContainer" style="margin-top: 2.5em;"></div>
 
 <% unless (recent = User.most_recent(6)).empty? %>
   <div class="tabContainer">
@@ -33,4 +33,31 @@
 	    <%= render :partial => "users/table", :locals => { :collection => active } %>
   	</div>
   </div>
+<% end %>
+
+<% unless (friendliest = User.most_friends).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most Friends</div>
+  	<div class="tabContent">
+	    <%= render :partial => "users/table", :locals => { :collection => friendliest } %>
+  	</div>
+  </div>
+<% end %>
+
+<% unless (credited = User.most_credited).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Most Credited</div>
+  	<div class="tabContent">
+	    <%= render :partial => "users/table", :locals => { :collection => credited } %>
+  	</div>
+  </div>
+<% end %>
+
+<% unless (top_rated = User.highest_rated).empty? %>
+  <div class="tabContainer">
+  	<div class="tabTitle">Highest Rated</div>
+  	<div class="tabContent">
+	    <%= render :partial => "users/table", :locals => { :collection => top_rated } %>
+  	</div>
+  </div>
 <% end %>
\ No newline at end of file

Modified: trunk/app/views/users/show.rhtml (1927 => 1928)


--- trunk/app/views/users/show.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/app/views/users/show.rhtml	2008-11-07 14:51:44 UTC (rev 1928)
@@ -248,21 +248,23 @@
 				</p>
 			</div>
 			
-			<% ratings = @user.ratings_for_contributions %>
-			<div class="contribution_section_box" style="width: 130px; padding: 0.4em 0.8em;">
-				<p style="font-size: 93%; font-weight: bold;">
-					<b><%= h @user.name -%> has an average rating of:</b>
-				</p>
-				<p style="font-size: 123.1%; font-weight: bold; padding-bottom: 0.2em; line-height: 1;">
-					<%= number_with_precision(mean(ratings.collect {|r| r.rating}).to_f, 1) -%> / 5
-				</p>
-				<p style="font-size: 77%; padding-top: 0.2em; line-height: 1;">
-					(<%= pluralize ratings.length, "rating" -%> in total)
-				</p>
-				<p style="font-size: 93%; font-weight: bold;">
-					<b>for their items</b>
-				</p>
-			</div>
+			<% benchmark "user rating box" do %>
+				<% avg_rating, rating_count = @user.average_rating_and_count %>
+				<div class="contribution_section_box" style="width: 130px; padding: 0.4em 0.8em;">
+					<p style="font-size: 93%; font-weight: bold;">
+						<b><%= h @user.name -%> has an average rating of:</b>
+					</p>
+					<p style="font-size: 123.1%; font-weight: bold; padding-bottom: 0.2em; line-height: 1;">
+						<%= number_with_precision(avg_rating, 1) -%> / 5
+					</p>
+					<p style="font-size: 77%; padding-top: 0.2em; line-height: 1;">
+						(<%= pluralize rating_count, "rating" -%> in total)
+					</p>
+					<p style="font-size: 93%; font-weight: bold;">
+						<b>for their items</b>
+					</p>
+				</div>
+			<% end %>
 			
 		</td>
 	</tr>

Modified: trunk/lib/acts_as_contributor.rb (1927 => 1928)


--- trunk/lib/acts_as_contributor.rb	2008-11-06 16:54:04 UTC (rev 1927)
+++ trunk/lib/acts_as_contributor.rb	2008-11-07 14:51:44 UTC (rev 1928)
@@ -39,6 +39,14 @@
           end
           include Mib::Acts::Contributor::InstanceMethods
         end
+        
+        # returns groups that are most credited
+        # the maximum number of results is set by #limit#
+        def most_credited(limit=10)
+          type = self.to_s
+          title_or_name = (type.downcase == "user" ? "name" : "title")
+          self.find_by_sql("SELECT n.* FROM #{type.downcase.pluralize} n JOIN creditations c ON c.creditor_id = n.id AND c.creditor_type = '#{type}' GROUP BY n.id ORDER BY COUNT(n.id) DESC, n.#{title_or_name} LIMIT #{limit}")
+        end
       end
 
       module SingletonMethods

reply via email to

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