changeset 1501:467282ce64a4 cannam

Add varied-mature-projects Featured box
author Chris Cannam
date Fri, 21 Mar 2014 13:03:27 +0000
parents cb53cb6eeaef
children cadec15c77d5
files app/helpers/projects_helper.rb app/models/project.rb app/views/activities/_busy.html.erb app/views/projects/_mature.html.erb app/views/projects/explore.html.erb config/locales/en.yml
diffstat 6 files changed, 45 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/app/helpers/projects_helper.rb	Mon Mar 17 08:56:24 2014 +0000
+++ b/app/helpers/projects_helper.rb	Fri Mar 21 13:03:27 2014 +0000
@@ -278,7 +278,7 @@
       Math.log(1 + nr_downloadables) +
       Math.log(1 + nr_downloads) +
       Math.sqrt(nr_members > 1 ? (nr_members - 1) : 0) +
-      Math.sqrt(nr_publications)
+      Math.sqrt(nr_publications * 2)
   end
 
   def all_maturity_scores()
@@ -290,6 +290,15 @@
     phash
   end
 
+  def top_level_maturity_scores()
+    phash = Hash.new
+    pp = Project.root_visible_by(User.anonymous)
+    pp.each do |p| 
+      phash[p] = score_maturity p
+    end
+    phash
+  end
+
   def mature_projects(count)
     phash = all_maturity_scores
     scores = phash.values.sort
@@ -297,4 +306,23 @@
     if threshold == 0 then threshold = 1 end
     phash.keys.select { |k| phash[k] > threshold }.sample(count)
   end
+
+  def varied_mature_projects(count)
+    phash = top_level_maturity_scores
+    scores = phash.values.sort
+    threshold = scores[scores.length / 2]
+    if threshold == 0 then threshold = 1 end
+    uhash = Hash.new
+    phash.keys.select do |k|
+      if phash[k] < threshold or k.description == "" then
+        false
+      else
+        uu = k.users
+        novel = (uhash.keys & uu).empty?
+        uu.each { |u| uhash[u] = 1 }
+        novel
+      end
+    end.sample(count)
+  end
+
 end
--- a/app/models/project.rb	Mon Mar 17 08:56:24 2014 +0000
+++ b/app/models/project.rb	Fri Mar 21 13:03:27 2014 +0000
@@ -89,7 +89,7 @@
   scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
   scope :all_public, { :conditions => { :is_public => true } }
   scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
-  scope :visible_roots, lambda { { :conditions => Project.root_visible_by(User.current) } }
+  scope :visible_roots, lambda {|*args| { :conditions => Project.root_visible_by(args.shift || User.current, *args) } }
   scope :allowed_to, lambda {|*args| 
     user = User.current
     permission = nil
@@ -157,8 +157,8 @@
     allowed_to_condition(user, :view_project, options)
   end
 
-  def self.root_visible_by(user=nil)
-    return "#{Project.table_name}.parent_id IS NULL AND " + visible_condition(user)
+  def self.root_visible_by(user, options={})
+    return "#{Project.table_name}.parent_id IS NULL AND " + visible_condition(user, options)
   end
   
   # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
--- a/app/views/activities/_busy.html.erb	Mon Mar 17 08:56:24 2014 +0000
+++ b/app/views/activities/_busy.html.erb	Fri Mar 21 13:03:27 2014 +0000
@@ -13,7 +13,7 @@
    <ul>
 
    <% 
-      for project in busy_projects(events, 7)
+      for project in busy_projects(events, 5)
    %>
 
    <li class="busy">
--- a/app/views/projects/_mature.html.erb	Mon Mar 17 08:56:24 2014 +0000
+++ b/app/views/projects/_mature.html.erb	Fri Mar 21 13:03:27 2014 +0000
@@ -2,7 +2,7 @@
    <ul>
 
    <% 
-      for project in mature_projects(5)
+      for project in varied_mature_projects(7)
    %>
 
    <li class="busy">
--- a/app/views/projects/explore.html.erb	Mon Mar 17 08:56:24 2014 +0000
+++ b/app/views/projects/explore.html.erb	Fri Mar 21 13:03:27 2014 +0000
@@ -38,6 +38,16 @@
 </div>
 
 <div class="threecolumnmid">
+  <% cache(:action => 'explore', :action_suffix => 'mature_projects') do %>
+  <div class="projects box">
+  <h3><%=l(:label_projects_mature)%></h3>
+    <%= render :partial => 'projects/mature' %>
+    <%= link_to l(:label_projects_more), { :controller => 'projects' }, :class => 'more' %>
+  </div>
+  <% end %>
+</div>
+
+<div class="threecolumnright">
   <% cache(:action => 'explore', :action_suffix => 'busy_projects') do %>
   <div class="projects box">
   <h3><%=l(:label_projects_busy)%></h3>
--- a/config/locales/en.yml	Mon Mar 17 08:56:24 2014 +0000
+++ b/config/locales/en.yml	Fri Mar 21 13:03:27 2014 +0000
@@ -524,7 +524,7 @@
   label_projects_more: More projects
   label_project_tags_all: Popular tags
   label_projects_busy: Busy projects
-  label_projects_mature: Mature projects
+  label_projects_mature: Featured
   label_search_projects: Search projects
   label_institutions_busy: Active institutions
   label_managers: Managed by