[82902] branches/gsoc11-statistics/stats-server/app

derek at macports.org derek at macports.org
Sun Aug 21 16:05:43 PDT 2011


Revision: 82902
          http://trac.macports.org/changeset/82902
Author:   derek at macports.org
Date:     2011-08-21 16:05:41 -0700 (Sun, 21 Aug 2011)
Log Message:
-----------
Home page now shows:

- Total number of participating users
- Number of participating users last month
- Line chart of number of participating users each month for the past 12 months

Modified Paths:
--------------
    branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb
    branches/gsoc11-statistics/stats-server/app/views/home/index.html.erb

Modified: branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb	2011-08-21 22:59:55 UTC (rev 82901)
+++ branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb	2011-08-21 23:05:41 UTC (rev 82902)
@@ -1,6 +1,55 @@
-class HomeController < ApplicationController
+class HomeController < ChartController
   
+  # Populate the users chart
+  def populate_users(chart_name, chart)
+    chart.string "Month"
+    chart.number "Number of users"
+
+    dataset = chart_dataset chart_name
+    
+    dataset.each do |item, count|
+      chart.add_row([item, count])
+    end
+  end
+  
+  # Gather number of participating users over past 12 months
+  def gather_users_over_time
+    monthly_users = Hash.new(0)
+    
+    now = Time.now
+    now_d = now.to_date
+    
+    # Iterate over months from 11 months ago to 0 months ago (current month)
+    11.downto(0) do |i|
+      month = now.months_ago(i).to_date
+      
+      
+      # Get the number of active (submitting) users for this month
+      entries = InstalledPort.where(:created_at => (month.at_beginning_of_month)..(month.at_end_of_month))
+      count = entries.select("DISTINCT(user_id)").count
+    
+      # Key is the abbreviated month name and the year (eg: Aug 2011)
+      key = month.to_time.strftime("%b %Y")
+      monthly_users[key] = count
+      
+      # Get users last month
+      if i == 1
+        @users_last_month = count
+        @last_month = month.to_time.strftime("%B")
+      end
+    end
+    
+    add_chart :participating_users, monthly_users, method(:populate_users)
+  end
+    
   def index
+    @charts = Hash.new
+    gather_users_over_time
+    
+    respond_to do |format|
+      format.html # index.html.erb
+    end
   end
+  
 
 end

Modified: branches/gsoc11-statistics/stats-server/app/views/home/index.html.erb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/views/home/index.html.erb	2011-08-21 22:59:55 UTC (rev 82901)
+++ branches/gsoc11-statistics/stats-server/app/views/home/index.html.erb	2011-08-21 23:05:41 UTC (rev 82902)
@@ -1,3 +1,5 @@
+<% controller.set_chart_title :participating_users, 'Number of Participating Users' %>
+<% controller.set_chart_type  :participating_users, "LineChart" %>
 <h1>MacPorts Statistics</h1>
 
 <ul>
@@ -5,6 +7,19 @@
 	<li> <%= link_to "User Installed Ports", installed_ports_path %> </li>
 </ul>
 
+Total number of participating users: <%= User.count %> <br />
+Number of users last month (<%= @last_month %>): <%= @users_last_month %> <br />
 
+
 <%= render :partial => '/partials/port_search' %>
 <%= link_to "Browse By Category", categories_path %> </li>
+
+<br />
+
+<%# Draw charts - no tables %>
+<%= render :partial => '/partials/chart_draw', 
+    :locals => {:charts => [:participating_users], :drawtables => false} 
+%>
+
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110821/e862c07f/attachment.html>


More information about the macports-changes mailing list