Changeset 82902
- Timestamp:
- 08/21/11 16:05:41 (4 years ago)
- Location:
- branches/gsoc11-statistics/stats-server/app
- Files:
-
- 2 edited
-
controllers/home_controller.rb (modified) (1 diff)
-
views/home/index.html.erb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb
r80511 r82902 1 class HomeController < ApplicationController1 class HomeController < ChartController 2 2 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 3 45 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 4 52 end 53 5 54 6 55 end -
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" %> 1 3 <h1>MacPorts Statistics</h1> 2 4 … … 6 8 </ul> 7 9 10 Total number of participating users: <%= User.count %> <br /> 11 Number of users last month (<%= @last_month %>): <%= @users_last_month %> <br /> 12 8 13 9 14 <%= render :partial => '/partials/port_search' %> 10 15 <%= 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.

