myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [1927] trunk: Work on viewing / donwload counts.


From: noreply
Subject: [myexperiment-hackers] [1927] trunk: Work on viewing / donwload counts.
Date: Thu, 6 Nov 2008 11:54:06 -0500 (EST)

Revision
1927
Author
alekses6
Date
2008-11-06 11:54:04 -0500 (Thu, 06 Nov 2008)

Log Message

Work on viewing / donwload counts.

1) Re-styled statistics box for contributable "show" pages.
2) Updated table listings of contributables to show only internal viewing / download counts. Packs didn't have download counts at all - added.
3) Updated the way "most viewed" and "most downloaded" collections of contributables are generated for index pages - only internal usage is now taken into account.

Modified Paths

Diff

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


--- trunk/app/models/contribution.rb	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/models/contribution.rb	2008-11-06 16:54:04 UTC (rev 1927)
@@ -17,29 +17,29 @@
            :dependent => :destroy
            
   # returns the 'most downloaded' Contributions
+  # (only takes into account donwloads on myExperiment, that is internal usage)
   # the maximum number of results is set by #limit#
   def self.most_downloaded(limit=10, klass=nil)
-    conditions = "downloads_count != 0"
-    conditions = ["#{conditions} AND contributable_type = ?", klass] if klass
+    if klass
+      type_condition = "c.contributable_type = '#{klass}' AND"
+    else
+      type_condition = ""
+    end
     
-    self.find(:all, 
-              :conditions => conditions, 
-              :order => "contributions.downloads_count DESC", 
-              :limit => limit,
-              :include => [ { :policy => :permissions } ])
+    self.find_by_sql("SELECT c.* FROM contributions c LEFT JOIN downloads d ON c.id = d.contribution_id WHERE #{type_condition} d.accessed_from_site = 1 GROUP BY d.contribution_id ORDER BY COUNT(d.contribution_id) DESC LIMIT #{limit}")
   end
   
   # returns the 'most viewed' Contributions
+  # (only takes into account viewings on myExperiment, that is internal usage)
   # the maximum number of results is set by #limit#
   def self.most_viewed(limit=10, klass=nil)
-    conditions = "viewings_count != 0"
-    conditions = ["#{conditions} AND contributable_type = ?", klass] if klass
+    if klass
+      type_condition = "c.contributable_type = '#{klass}' AND"
+    else
+      type_condition = ""
+    end
     
-    self.find(:all, 
-              :conditions => conditions,
-              :order => "contributions.viewings_count DESC", 
-              :limit => limit,
-              :include => [ { :policy => :permissions } ])
+    self.find_by_sql("SELECT c.* FROM contributions c LEFT JOIN viewings v ON c.id = v.contribution_id WHERE #{type_condition} v.accessed_from_site = 1 GROUP BY v.contribution_id ORDER BY COUNT(v.contribution_id) DESC LIMIT #{limit}")
   end
   
   # returns the 'most recent' Contributions

Modified: trunk/app/models/download.rb (1926 => 1927)


--- trunk/app/models/download.rb	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/models/download.rb	2008-11-06 16:54:04 UTC (rev 1927)
@@ -48,4 +48,9 @@
   def self.anonymous_site_downloads_count_for_contribution(contribution_id)
     self.count(:all, :conditions => ["contribution_id = ? AND accessed_from_site = ? AND user_ID IS NULL", contribution_id, true])
   end
+  
+  # returns total number of downloads for the contribution from the website
+  def self.total_site_downloads_count_for_contribution(contribution_id)
+    self.count(:all, :conditions => ["contribution_id = ? AND accessed_from_site = ?", contribution_id, true])
+  end
 end

Modified: trunk/app/models/viewing.rb (1926 => 1927)


--- trunk/app/models/viewing.rb	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/models/viewing.rb	2008-11-06 16:54:04 UTC (rev 1927)
@@ -51,4 +51,9 @@
   def self.anonymous_site_viewings_count_for_contribution(contribution_id)
     self.count(:all, :conditions => ["contribution_id = ? AND accessed_from_site = ? AND user_ID IS NULL", contribution_id, true])
   end
+  
+  # returns total number of downloads for the contribution from the website
+  def self.total_site_viewings_count_for_contribution(contribution_id)
+    self.count(:all, :conditions => ["contribution_id = ? AND accessed_from_site = ?", contribution_id, true])
+  end
 end

Modified: trunk/app/views/blobs/_table.rhtml (1926 => 1927)


--- trunk/app/views/blobs/_table.rhtml	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/views/blobs/_table.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
@@ -77,8 +77,8 @@
 						<p style="font-size: 85%;">
 							<a href="" file_path(blob) + '#ratings' -%>"><b>Rating: </b><%= number_with_precision(blob.rating, 1) %> / 5 (<%= pluralize blob.ratings_count, 'rating' %>)</a> |
 							<a href="" file_path(blob) + '#comments' -%>"><b>Comments: </b><%= blob.comments_count %></a> |
-							<b>Viewed:</b> <%=pluralize blob.contribution.viewings_count, "time" %> |
-							<b>Downloaded:</b> <%=pluralize blob.contribution.downloads_count, "time" %>
+							<b>Viewed internally:</b> <%= pluralize Viewing.total_site_viewings_count_for_contribution(blob.contribution.id), "time" %> |
+							<b>Downloaded internally:</b> <%= pluralize Download.total_site_downloads_count_for_contribution(blob.contribution.id), "time" %>
 						</p>
 						
 						<% unless (tags = blob.tags).empty? %>

Modified: trunk/app/views/contributions/_statistics.rhtml (1926 => 1927)


--- trunk/app/views/contributions/_statistics.rhtml	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/views/contributions/_statistics.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
@@ -1,13 +1,13 @@
-<p>
-	<span style="float: right;"><small>[ <%= link_to "details", eval("statistics_#{controller_visible_name(type.to_s.pluralize).singularize.downcase}_path(#{contributable.id})") -%> ]</small></span>
-  <span style="float: right;"><%= pluralize statistics.viewings_count, "viewing" %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
-	<br/>
+<p style="font-size: 85%;">
+  <%= pluralize statistics.viewings_count, "viewing" %>
 </p>
 
 <% if downloadable? type -%>
-	<p>
-		<span style="float: right;"><small>[ <%= link_to "details", eval("statistics_#{controller_visible_name(type.to_s.pluralize).singularize.downcase}_path(#{contributable.id})") -%> ]</small></span>
-	  <span style="float: right;"><%= pluralize statistics.downloads_count, "download" %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
-		<br/>
+	<p style="font-size: 85%;">
+	  <%= pluralize statistics.downloads_count, "download" %>
 	</p>
-<% end -%>
\ No newline at end of file
+<% end -%>
+
+<p style="margin-top: 0.2em;">
+	<small>[ <%= link_to "see breakdown", eval("statistics_#{controller_visible_name(type.to_s.pluralize).singularize.downcase}_path(#{contributable.id})") -%> ]</small>
+</p>
\ No newline at end of file

Modified: trunk/app/views/contributions/_statistics_box.rhtml (1926 => 1927)


--- trunk/app/views/contributions/_statistics_box.rhtml	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/views/contributions/_statistics_box.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
@@ -1,61 +1,69 @@
+<% type = contributable.class.to_s -%>
+
 <div class="contribution_section_box">
 	<p class="heading" style="margin-bottom: 0.3em;">
+		<%= info_icon_with_tooltip("Viewing #{(downloadable?(type) ? '/ download' : '')} counts are grand totals for this #{ visible_name(contributable) }.<br/>Click 'see breakdown' to view details.") -%>
 		Statistics
 	</p>
 	
 	<div class="stats_box"> 
-	
-		<% type = contributable.class.to_s -%>
-		
 		<%= render :partial => "contributions/statistics", :object => contributable.contribution, :locals => { :contributable => contributable, :type => type } %>
 		
-		<% if allow_credits_and_attributions? type -%>
-			<p>
-				<a href="" pluralize contributable.creditors.length, "credit" -%></a> <!-- won't work for type=='group'; needs anchor called '#group_creditations' -->
-			</p>
-			
-			<p>
-				<a href="" pluralize contributable.attributors.length, "attribution" -%></a>
-			</p>
-		<% end -%>
+		<div class="fold" style="padding-top: 0.6em;">
+			<div class="foldTitle">More</div>
+			<div class="foldContent" style="display: none; text-align: left;">
+				<% if allow_credits_and_attributions? type -%>
+					<p>
+						<a href="" pluralize contributable.creditors.length, "credit" -%></a> <!-- won't work for type=='group'; needs anchor called '#group_creditations' -->
+					</p>
+					
+					<p>
+						<a href="" pluralize contributable.attributors.length, "attribution" -%></a>
+					</p>
+				<% end -%>
+				
+				<% if taggable? type -%>
+					<p>
+			      <a href="" pluralize contributable.tags.uniq.length, "tag" -%></a>
+			    </p>
+				<% end -%>
+				
+				<% if favouritable? type -%>
+					<p>
+			      <a href="" pluralize contributable.bookmarks_count, "favourite" -%></a>
+			    </p>
+				<% end -%>
+				
+				<% if rateable? type -%>
+					<p>
+			      <a href="" pluralize contributable.ratings_count, "rating" -%></a>
+			    </p>
+				<% end -%>
+				
+				<% if allow_citations? type %>
+					<p>
+			      <!-- for this to work properly, view for every resource that supports citations will need to have -->
+						<!-- tab system with 'tabsContainer' element + anchor called 'citations' -->
+						<a href=""  pluralize contributable.citations_count, "citation" %></a>
+			    </p>
+				<% end %>
+				
+				<% if reviewable? type %>
+					<p>
+			      <a href="" pluralize contributable.reviews_count, "review" -%></a>
+			    </p>
+				<% end %>
+				
+				<% if commentable? type -%>
+			    <p>
+			    	<a href="" pluralize contributable.comments_count, "comment" -%></a>
+			    </p>
+				<% end -%>
+			</div>
+		</div>
 		
-		<% if taggable? type -%>
-			<p>
-	      <a href="" pluralize contributable.tags.uniq.length, "tag" -%></a>
-	    </p>
-		<% end -%>
 		
-		<% if favouritable? type -%>
-			<p>
-	      <a href="" pluralize contributable.bookmarks_count, "favourite" -%></a>
-	    </p>
-		<% end -%>
 		
-		<% if rateable? type -%>
-			<p>
-	      <a href="" pluralize contributable.ratings_count, "rating" -%></a>
-	    </p>
-		<% end -%>
 		
-		<% if allow_citations? type %>
-			<p>
-	      <!-- for this to work properly, view for every resource that supports citations will need to have -->
-				<!-- tab system with 'tabsContainer' element + anchor called 'citations' -->
-				<a href=""  pluralize contributable.citations_count, "citation" %></a>
-	    </p>
-		<% end %>
-		
-		<% if reviewable? type %>
-			<p>
-	      <a href="" pluralize contributable.reviews_count, "review" -%></a>
-	    </p>
-		<% end %>
-		
-		<% if commentable? type -%>
-	    <p>
-	    	<a href="" pluralize contributable.comments_count, "comment" -%></a>
-	    </p>
-		<% end -%>
-		
 	</div>
 </div>
\ No newline at end of file

Modified: trunk/app/views/packs/_table.rhtml (1926 => 1927)


--- trunk/app/views/packs/_table.rhtml	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/views/packs/_table.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
@@ -47,7 +47,8 @@
 						
 						<p style="font-size: 85%;">
 							<a href="" pack_path(pack) + '#comments' -%>"><b>Comments: </b><%= pack.comments_count %></a> |
-							<b>Viewed:</b> <%=pluralize pack.contribution.viewings_count, "time" %> |
+							<b>Viewed internally:</b> <%= pluralize Viewing.total_site_viewings_count_for_contribution(pack.contribution.id), "time" %> |
+							<b>Downloaded internally:</b> <%= pluralize Download.total_site_downloads_count_for_contribution(pack.contribution.id), "time" %>
 						</p>
 						
 						<% unless (tags = pack.tags).empty? %>

Modified: trunk/app/views/workflows/_table.rhtml (1926 => 1927)


--- trunk/app/views/workflows/_table.rhtml	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/app/views/workflows/_table.rhtml	2008-11-06 16:54:04 UTC (rev 1927)
@@ -101,8 +101,8 @@
 					  </p>
 						
 						<p style="font-size: 85%;">
-							<b>Viewed:</b> <%=pluralize workflow.contribution.viewings_count, "time" %> |
-				      <b>Downloaded:</b> <%=pluralize workflow.contribution.downloads_count, "time" %>
+							<b>Viewed internally:</b> <%=pluralize Viewing.total_site_viewings_count_for_contribution(workflow.contribution.id), "time" %> |
+				      <b>Downloaded internally:</b> <%=pluralize Download.total_site_downloads_count_for_contribution(workflow.contribution.id), "time" %>
 						</p>
 					  
 					  <% unless (tags = workflow.tags).empty? %>

Modified: trunk/public/stylesheets/styles.css (1926 => 1927)


--- trunk/public/stylesheets/styles.css	2008-11-06 12:06:37 UTC (rev 1926)
+++ trunk/public/stylesheets/styles.css	2008-11-06 16:54:04 UTC (rev 1927)
@@ -1129,7 +1129,7 @@
 }
 
 .contribution_section_box .stats_box p {
-	font-size: 85%;
+	font-size: 93%;
 	text-align: centre;
 	line-height: 1.3;
 	padding: 0;

reply via email to

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