New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 82902


Ignore:
Timestamp:
08/21/11 16:05:41 (4 years ago)
Author:
derek@…
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
Location:
branches/gsoc11-statistics/stats-server/app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb

    r80511 r82902  
    1 class HomeController < ApplicationController 
     1class HomeController < ChartController 
    22   
     3  # Populate the users chart 
     4  def populate_users(chart_name, chart) 
     5    chart.string "Month" 
     6    chart.number "Number of users" 
     7 
     8    dataset = chart_dataset chart_name 
     9     
     10    dataset.each do |item, count| 
     11      chart.add_row([item, count]) 
     12    end 
     13  end 
     14   
     15  # Gather number of participating users over past 12 months 
     16  def gather_users_over_time 
     17    monthly_users = Hash.new(0) 
     18     
     19    now = Time.now 
     20    now_d = now.to_date 
     21     
     22    # Iterate over months from 11 months ago to 0 months ago (current month) 
     23    11.downto(0) do |i| 
     24      month = now.months_ago(i).to_date 
     25       
     26       
     27      # Get the number of active (submitting) users for this month 
     28      entries = InstalledPort.where(:created_at => (month.at_beginning_of_month)..(month.at_end_of_month)) 
     29      count = entries.select("DISTINCT(user_id)").count 
     30     
     31      # Key is the abbreviated month name and the year (eg: Aug 2011) 
     32      key = month.to_time.strftime("%b %Y") 
     33      monthly_users[key] = count 
     34       
     35      # Get users last month 
     36      if i == 1 
     37        @users_last_month = count 
     38        @last_month = month.to_time.strftime("%B") 
     39      end 
     40    end 
     41     
     42    add_chart :participating_users, monthly_users, method(:populate_users) 
     43  end 
     44     
    345  def index 
     46    @charts = Hash.new 
     47    gather_users_over_time 
     48     
     49    respond_to do |format| 
     50      format.html # index.html.erb 
     51    end 
    452  end 
     53   
    554 
    655end 
  • branches/gsoc11-statistics/stats-server/app/views/home/index.html.erb

    r80511 r82902  
     1<% controller.set_chart_title :participating_users, 'Number of Participating Users' %> 
     2<% controller.set_chart_type  :participating_users, "LineChart" %> 
    13<h1>MacPorts Statistics</h1> 
    24 
     
    68</ul> 
    79 
     10Total number of participating users: <%= User.count %> <br /> 
     11Number of users last month (<%= @last_month %>): <%= @users_last_month %> <br /> 
     12 
    813 
    914<%= render :partial => '/partials/port_search' %> 
    1015<%= link_to "Browse By Category", categories_path %> </li> 
     16 
     17<br /> 
     18 
     19<%# Draw charts - no tables %> 
     20<%= render :partial => '/partials/chart_draw',  
     21    :locals => {:charts => [:participating_users], :drawtables => false}  
     22%> 
     23 
     24 
     25 
Note: See TracChangeset for help on using the changeset viewer.