[116891] branches/gsoc11-statistics/stats-server/app/controllers

cal at macports.org cal at macports.org
Sun Feb 9 08:56:48 PST 2014


Revision: 116891
          https://trac.macports.org/changeset/116891
Author:   cal at macports.org
Date:     2014-02-09 08:56:48 -0800 (Sun, 09 Feb 2014)
Log Message:
-----------
macports stats: re-indent controllers, remove unneeded submissions actions

Modified Paths:
--------------
    branches/gsoc11-statistics/stats-server/app/controllers/application_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/categories_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb
    branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb

Modified: branches/gsoc11-statistics/stats-server/app/controllers/application_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/application_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/application_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,3 +1,3 @@
 class ApplicationController < ActionController::Base
-  protect_from_forgery
+	protect_from_forgery
 end

Modified: branches/gsoc11-statistics/stats-server/app/controllers/categories_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/categories_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/categories_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,8 +1,8 @@
 class CategoriesController < ApplicationController
-  caches_page :index
-  cache_sweeper :category_sweeper, :only => [:create, :update, :destroy]
+	caches_page :index
+	cache_sweeper :category_sweeper, :only => [:create, :update, :destroy]
 
-  def index
-    @categories = Category.all(:order => 'name ASC')
-  end
+	def index
+		@categories = Category.all(:order => 'name ASC')
+	end
 end

Modified: branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -3,60 +3,60 @@
 
 class ChartController < ApplicationController
 
-  # Associate chart name with a data set
-  def add_chart(chart_name, dataset, populate_code)
-    set_chart_attribute chart_name, :data, dataset
-    set_chart_attribute chart_name, :populate, populate_code
-  end
-    
-  # Set the chart's title
-  def set_chart_title(chart, title)
-    set_chart_attribute chart, :title, title
-  end
-  
-  # Set the chart's type
-  def set_chart_type(chart, type)
-    set_chart_attribute chart, :type, type
-  end
-    
-  # Call a chart's populate_code to populate it with its associated dataset
-  def populate_chart(chart_name, chart)
-    populate = @charts[chart_name][:populate]
-    populate.call(chart_name, chart)
-  end
-  
-  # Get the dataset associate with this chart
-  def chart_dataset(chart_name)
-    @charts[chart_name][:data]
-  end
-  
-  # Check if the chart's dataset is empty
-  def dataset_empty?(chart_name)
-    dataset = chart_dataset(chart_name)
-    return dataset.empty?
-  end
-  
-  # Get the title associate with this chart
-  def chart_title(chart_name)
-    @charts[chart_name][:title]
-  end
-  
-  # Get the type of this chart (eg: PieChart, LineChart, etc...)
-  def chart_type(chart_name)
-    @charts[chart_name][:type]
-  end
-  
-  private 
-  
-  # Associate an attribute with the given chart
-  def set_chart_attribute(chart, attribute, value)
-    attrs = @charts[chart]
-    
-    if attrs.nil?
-      attrs = Hash.new
-    end
-    
-    attrs[attribute] = value
-    @charts[chart] = attrs
-  end
+	# Associate chart name with a data set
+	def add_chart(chart_name, dataset, populate_code)
+		set_chart_attribute chart_name, :data, dataset
+		set_chart_attribute chart_name, :populate, populate_code
+	end
+
+	# Set the chart's title
+	def set_chart_title(chart, title)
+		set_chart_attribute chart, :title, title
+	end
+
+	# Set the chart's type
+	def set_chart_type(chart, type)
+		set_chart_attribute chart, :type, type
+	end
+
+	# Call a chart's populate_code to populate it with its associated dataset
+	def populate_chart(chart_name, chart)
+		populate = @charts[chart_name][:populate]
+		populate.call(chart_name, chart)
+	end
+
+	# Get the dataset associate with this chart
+	def chart_dataset(chart_name)
+		@charts[chart_name][:data]
+	end
+
+	# Check if the chart's dataset is empty
+	def dataset_empty?(chart_name)
+		dataset = chart_dataset(chart_name)
+		return dataset.empty?
+	end
+
+	# Get the title associate with this chart
+	def chart_title(chart_name)
+		@charts[chart_name][:title]
+	end
+
+	# Get the type of this chart (eg: PieChart, LineChart, etc...)
+	def chart_type(chart_name)
+		@charts[chart_name][:type]
+	end
+
+	private
+
+	# Associate an attribute with the given chart
+	def set_chart_attribute(chart, attribute, value)
+		attrs = @charts[chart]
+
+		if attrs.nil?
+			attrs = Hash.new
+		end
+
+		attrs[attribute] = value
+		@charts[chart] = attrs
+	end
 end

Modified: branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,55 +1,55 @@
 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
-  
+	# 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/controllers/installed_ports_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,118 +1,118 @@
 class InstalledPortsController < ChartController
-  
-  # Populate the users chart
-  def populate_top25(chart_name, chart)
-    chart.string "Port"
-    chart.number "Number of installations"
 
-    dataset = chart_dataset chart_name
-    
-    dataset.each do |item, count|
-      chart.add_row([item, count])
-    end
-  end
-  
-  # Return the average number of ports each user has installed
-  def average_ports_per_user
-    users = User.all
-    sum = 0
-    
-    users.each do |user|
-      sum = sum + user.installed_ports.count
-    end
-    
-    return 0 unless users.count > 0
-    average = sum / users.count unless users.count == 0
-  end
-  
-  # Find the port that has been installed most this year
-  def most_installed_port_this_year
-    now = Time.now.to_date
+	# Populate the users chart
+	def populate_top25(chart_name, chart)
+		chart.string "Port"
+		chart.number "Number of installations"
 
-    # Find InstalledPort entries for this month
-    current = InstalledPort.where(:created_at => (now.at_beginning_of_year)..(now.at_end_of_year))
-    
-    
-    top = current.count(:port_id,
-                               :group => :port_id,
-                               :order => 'count_port_id DESC',
-                               :limit => 1)
-                               
-   # most populator port this year
-   popular_port_year = top.first
-   @popular_port_year = nil
-   @popular_port_year_count = 0
-   unless popular_port_year == nil
-     @popular_port_year = Port.find(popular_port_year[0])
-     @popular_port_year_count = popular_port_year[1]
-   end
-  end
-  
-  # Most popular port this month
-  def popular_port_this_month(port_id, count)
-    @popular_port_month = Port.find(port_id)
-    @popular_port_month_count = count
-  end
-  
-  def gather_top25
-    
-    top25 = Hash.new(0)
-    now = Time.now.to_date
-    
-    # Full month name
-    @month = Time.now.strftime("%B")
-    # This year
-    @year = Time.now.strftime("%Y")
-    
-    # Find InstalledPort entries for this month
-    current = InstalledPort.where(:created_at => (now.at_beginning_of_month)..(now.at_end_of_month))
-    
-    @top = current.count(:port_id,
-                               :group => :port_id,
-                               :order => 'count_port_id DESC',
-                               :limit => 25)    
-    
-    @top.each do |port_id, count|
-      port = Port.find(port_id)
-      if not port.nil?
-        top25[port.name] = count
-      end
-    end
-    
-    # Sort the table by count
-    sorted = top25.sort_by { |k, v| v }
-    top25 = sorted.reverse # Descending order
-        
-    add_chart :top25, top25, method(:populate_top25)
-  end
-  
-  def gather_data
-    
-    # Get the top 25 most installed ports for this month
-    gather_top25
-    
-    # Average number of ports per user                        
-    @average_ports = average_ports_per_user
-    
-    # most populator port this month
-    pop = @top.first
-    if not pop.nil?
-      popular_port_this_month(pop[0],pop[1])
-    end
-    
-    # most popular port this year
-    most_installed_port_this_year
-  end
-  
-  def index   
-    
-    @charts = Hash.new
-    
-    gather_data
-    
-    respond_to do |format|
-      format.html # index.html.erb
-    end
-  end
-  
+		dataset = chart_dataset chart_name
+
+		dataset.each do |item, count|
+			chart.add_row([item, count])
+		end
+	end
+
+	# Return the average number of ports each user has installed
+	def average_ports_per_user
+		users = User.all
+		sum = 0
+
+		users.each do |user|
+			sum = sum + user.installed_ports.count
+		end
+
+		return 0 unless users.count > 0
+		average = sum / users.count unless users.count == 0
+	end
+
+	# Find the port that has been installed most this year
+	def most_installed_port_this_year
+		now = Time.now.to_date
+
+		# Find InstalledPort entries for this month
+		current = InstalledPort.where(:created_at => (now.at_beginning_of_year)..(now.at_end_of_year))
+
+
+		top = current.count(:port_id,
+							:group => :port_id,
+							:order => 'count_port_id DESC',
+							:limit => 1)
+
+		# most populator port this year
+		popular_port_year = top.first
+		@popular_port_year = nil
+		@popular_port_year_count = 0
+		unless popular_port_year == nil
+			@popular_port_year = Port.find(popular_port_year[0])
+			@popular_port_year_count = popular_port_year[1]
+		end
+	end
+
+	# Most popular port this month
+	def popular_port_this_month(port_id, count)
+		@popular_port_month = Port.find(port_id)
+		@popular_port_month_count = count
+	end
+
+	def gather_top25
+
+		top25 = Hash.new(0)
+		now = Time.now.to_date
+
+		# Full month name
+		@month = Time.now.strftime("%B")
+		# This year
+		@year = Time.now.strftime("%Y")
+
+		# Find InstalledPort entries for this month
+		current = InstalledPort.where(:created_at => (now.at_beginning_of_month)..(now.at_end_of_month))
+
+		@top = current.count(:port_id,
+							 :group => :port_id,
+							 :order => 'count_port_id DESC',
+							 :limit => 25)
+
+		@top.each do |port_id, count|
+			port = Port.find(port_id)
+			if not port.nil?
+				top25[port.name] = count
+			end
+		end
+
+		# Sort the table by count
+		sorted = top25.sort_by { |k, v| v }
+		top25 = sorted.reverse # Descending order
+
+		add_chart :top25, top25, method(:populate_top25)
+	end
+
+	def gather_data
+
+		# Get the top 25 most installed ports for this month
+		gather_top25
+
+		# Average number of ports per user
+		@average_ports = average_ports_per_user
+
+		# most populator port this month
+		pop = @top.first
+		if not pop.nil?
+			popular_port_this_month(pop[0],pop[1])
+		end
+
+		# most popular port this year
+		most_installed_port_this_year
+	end
+
+	def index
+
+		@charts = Hash.new
+
+		gather_data
+
+		respond_to do |format|
+			format.html # index.html.erb
+		end
+	end
+
 end

Modified: branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,35 +1,35 @@
 class OsStatisticsController < ChartController
-  
-  # Populate charts with data
-  def populate(chart_name, chart)
-    # This is the column's label
-    chart.string "Item"
-    
-    # This is the numerical value associated with the label
-    chart.number "Frequency"
 
-    # Add rows of data
-    dataset = chart_dataset chart_name
-    dataset.each do |item, count|
-      chart.add_row([item, count])
-    end
-  end
-  
-  def index
-    @charts = Hash.new
-    frequencies = OsStatistic.frequencies
-    
-    # Add charts for each type of data
-    frequencies.each do |column, data_hash|
-      add_chart column.to_sym, data_hash, method(:populate)
-    end
-    
-    respond_to do |format|
-      format.html # index.html.erb
-    end
-  end
-  
-  def show
-    @os_stats = OsStatistic.find(params[:id])
-  end
-end
\ No newline at end of file
+	# Populate charts with data
+	def populate(chart_name, chart)
+		# This is the column's label
+		chart.string "Item"
+
+		# This is the numerical value associated with the label
+		chart.number "Frequency"
+
+		# Add rows of data
+		dataset = chart_dataset chart_name
+		dataset.each do |item, count|
+			chart.add_row([item, count])
+		end
+	end
+
+	def index
+		@charts = Hash.new
+		frequencies = OsStatistic.frequencies
+
+		# Add charts for each type of data
+		frequencies.each do |column, data_hash|
+			add_chart column.to_sym, data_hash, method(:populate)
+		end
+
+		respond_to do |format|
+			format.html # index.html.erb
+		end
+	end
+
+	def show
+		@os_stats = OsStatistic.find(params[:id])
+	end
+end

Modified: branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,168 +1,168 @@
 class PortsController < ChartController
-  caches_page :index, :show
-  cache_sweeper :port_sweeper, :only => [:create, :update, :destroy]
-  
-  # Populate a simple two column chart
-  def populate_simple_chart(chart_name, chart)
-    chart.string "Item"
-    chart.number "Frequency"
+	caches_page :index, :show
+	cache_sweeper :port_sweeper, :only => [:create, :update, :destroy]
 
-    dataset = chart_dataset chart_name
-    
-    dataset.each do |item, count|
-      chart.add_row([item, count])
-    end
-  end
-  
-  # Populate the versions over time chart
-  def populate_monthly_versions(chart_name, chart)
-    chart.string "Month"
-      
-    # Add version columns
-    column_order = []
-    @top_versions.each do |version, count|
-      chart.number version;
-      column_order << version
-    end
+	# Populate a simple two column chart
+	def populate_simple_chart(chart_name, chart)
+		chart.string "Item"
+		chart.number "Frequency"
 
-    # Add the data
-    dataset = chart_dataset chart_name
-    dataset.each do |month, version_counts|
-      row = [month]
-      column_order.each do |version|
-        row << version_counts[version]
-      end
-      chart.add_row(row)
-    end
-  end
-  
-  # Gather all chart datasets
-  def gather_data
-    gather_frequencies
-    gather_data_over_months
-  end
-  
-  # Frequency tallys
-  def gather_frequencies()
-    variant_count = Hash.new(0)
-    version_count = Hash.new(0)
-      
-    @installed.each do |row|
-      if not row.variants.nil?
-        # row.variants is a space delimited string of varients
-        variants = row.variants.split
-        
-        # If no variant is present increment a dummy variant 'None'
-        if variants.empty?
-          variant_count['None'] = variant_count['None'] + 1
-        end
-        
-        # Count
-        variants.each do |variant|
-          key = variant.to_sym  
-          variant_count[key] = variant_count[key] + 1
-        end
-      end
-      
-      # Count versions
-      key = row.version.to_sym  
-      version_count[key] = version_count[key] + 1
-    end
-    
-    populate = method(:populate_simple_chart)
-    add_chart :variant_count, variant_count, populate
-    add_chart :version_count, version_count, populate
-  end
-  
-  # Gather month by month tallys
-  def gather_data_over_months()
-    monthly_installs = Hash.new(0)
-    monthly_versions = Hash.new
-    
-    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
-      
-      # Find InstalledPort entries for month
-      entries = @installed.where(:created_at => (month.at_beginning_of_month)..(month.at_end_of_month))
-      
-      count_monthly_installs monthly_installs, month, entries
-      count_monthly_versions monthly_versions, month, entries
-    end
-    
-    add_chart :versions_over_time, monthly_versions, method(:populate_monthly_versions)
-    add_chart :installs_over_time, monthly_installs, method(:populate_simple_chart)
-  end
-  
-  # Count the number of installs of this port for the given month
-  def count_monthly_installs(monthly_installs, month, entries)
-    if entries.size == 0
-      return
-    end
-    
-    # Key is the abbreviated month name and the year (eg: Aug 2011)
-    key = month.to_time.strftime("%b %Y")
-    monthly_installs[key] = entries.size
-  end
-    
-  # Count the number of times each version of this port was installed for
-  # the given month
-  def count_monthly_versions(monthly_versions, month, entries)
-    @top_versions.each do |version, count|
-      version_entries = entries.where("version = ?", version)
-      
-      # Key is the abbreviated month name and the year (eg: Aug 2011)
-      key = month.to_time.strftime("%b %Y")
-      
-      if monthly_versions[key].nil?
-        monthly_versions[key] = Hash.new
-      end
-      
-      counts_for_month = monthly_versions[key]
-      counts_for_month[version] = version_entries.size      
-      monthly_versions[key] = counts_for_month
-    end  
-  end
-  
-  def index
-    unless params[:category_id].nil?
-      @ports = Category.find(params[:category_id]).ports.paginate :page => params[:page], :order => 'name ASC', :per_page => 50
-    else
-      @ports = Port.paginate :page => params[:page], :order => 'name ASC', :per_page => 50
-    end
-    @page = params[:page] || 1
+		dataset = chart_dataset chart_name
 
-    respond_to do |format|
-      format.html
-    end
-  end
- 
-  def show
-    @port = Category.find(params[:category_id]).ports.find(params[:id])
-    @installed = InstalledPort.where("port_id = ?", @port.id)
-    @top_versions = @installed.group(:version).order("count_all DESC").limit(5).size
-    @charts = Hash.new
+		dataset.each do |item, count|
+			chart.add_row([item, count])
+		end
+	end
 
-    gather_data
-      
-    respond_to do |format|
-      format.html
-    end
-  end
+	# Populate the versions over time chart
+	def populate_monthly_versions(chart_name, chart)
+		chart.string "Month"
 
-  def search
-    @ports = Port.search(params[:criteria], params[:val], params[:page])
-    @page = params[:page] || 1
+		# Add version columns
+		column_order = []
+		@top_versions.each do |version, count|
+			chart.number version;
+			column_order << version
+		end
 
-    respond_to do |format|
-      format.html { render :action => :index }
-    end
-  end
+		# Add the data
+		dataset = chart_dataset chart_name
+		dataset.each do |month, version_counts|
+			row = [month]
+			column_order.each do |version|
+				row << version_counts[version]
+			end
+			chart.add_row(row)
+		end
+	end
 
-  def search_generate
-    redirect_to "/ports/search/#{params[:criteria]}/#{params[:val]}"
-  end
+	# Gather all chart datasets
+	def gather_data
+		gather_frequencies
+		gather_data_over_months
+	end
+
+	# Frequency tallys
+	def gather_frequencies()
+		variant_count = Hash.new(0)
+		version_count = Hash.new(0)
+
+		@installed.each do |row|
+			if not row.variants.nil?
+				# row.variants is a space delimited string of varients
+				variants = row.variants.split
+
+				# If no variant is present increment a dummy variant 'None'
+				if variants.empty?
+					variant_count['None'] = variant_count['None'] + 1
+				end
+
+				# Count
+				variants.each do |variant|
+					key = variant.to_sym
+					variant_count[key] = variant_count[key] + 1
+				end
+			end
+
+			# Count versions
+			key = row.version.to_sym
+			version_count[key] = version_count[key] + 1
+		end
+
+		populate = method(:populate_simple_chart)
+		add_chart :variant_count, variant_count, populate
+		add_chart :version_count, version_count, populate
+	end
+
+	# Gather month by month tallys
+	def gather_data_over_months()
+		monthly_installs = Hash.new(0)
+		monthly_versions = Hash.new
+
+		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
+
+			# Find InstalledPort entries for month
+			entries = @installed.where(:created_at => (month.at_beginning_of_month)..(month.at_end_of_month))
+
+			count_monthly_installs monthly_installs, month, entries
+			count_monthly_versions monthly_versions, month, entries
+		end
+
+		add_chart :versions_over_time, monthly_versions, method(:populate_monthly_versions)
+		add_chart :installs_over_time, monthly_installs, method(:populate_simple_chart)
+	end
+
+	# Count the number of installs of this port for the given month
+	def count_monthly_installs(monthly_installs, month, entries)
+		if entries.size == 0
+			return
+		end
+
+		# Key is the abbreviated month name and the year (eg: Aug 2011)
+		key = month.to_time.strftime("%b %Y")
+		monthly_installs[key] = entries.size
+	end
+
+	# Count the number of times each version of this port was installed for
+	# the given month
+	def count_monthly_versions(monthly_versions, month, entries)
+		@top_versions.each do |version, count|
+			version_entries = entries.where("version = ?", version)
+
+			# Key is the abbreviated month name and the year (eg: Aug 2011)
+			key = month.to_time.strftime("%b %Y")
+
+			if monthly_versions[key].nil?
+				monthly_versions[key] = Hash.new
+			end
+
+			counts_for_month = monthly_versions[key]
+			counts_for_month[version] = version_entries.size
+			monthly_versions[key] = counts_for_month
+		end
+	end
+
+	def index
+		unless params[:category_id].nil?
+			@ports = Category.find(params[:category_id]).ports.paginate :page => params[:page], :order => 'name ASC', :per_page => 50
+		else
+			@ports = Port.paginate :page => params[:page], :order => 'name ASC', :per_page => 50
+		end
+		@page = params[:page] || 1
+
+		respond_to do |format|
+			format.html
+		end
+	end
+
+	def show
+		@port = Category.find(params[:category_id]).ports.find(params[:id])
+		@installed = InstalledPort.where("port_id = ?", @port.id)
+		@top_versions = @installed.group(:version).order("count_all DESC").limit(5).size
+		@charts = Hash.new
+
+		gather_data
+
+		respond_to do |format|
+			format.html
+		end
+	end
+
+	def search
+		@ports = Port.search(params[:criteria], params[:val], params[:page])
+		@page = params[:page] || 1
+
+		respond_to do |format|
+			format.html { render :action => :index }
+		end
+	end
+
+	def search_generate
+		redirect_to "/ports/search/#{params[:criteria]}/#{params[:val]}"
+	end
 end

Modified: branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb	2014-02-09 16:18:46 UTC (rev 116890)
+++ branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb	2014-02-09 16:56:48 UTC (rev 116891)
@@ -1,58 +1,24 @@
 class SubmissionsController < ApplicationController
-  # GET /submissions
-  # GET /submissions.xml
-  def index
-    @submissions = Submission.all
+	cache_sweeper :installed_port_sweeper, :only => [:create, :update, :destroy]
 
-    respond_to do |format|
-      format.html # index.html.erb
-    end
-  end
+	# GET /submissions
+	# GET /submissions.xml
+	def index
+		@submissions = Submission.all
 
-  # GET /submissions/1
-  # GET /submissions/1.xml
-  def show
-    @submission = Submission.find(params[:id])
+		respond_to do |format|
+			format.html # index.html.erb
+		end
+	end
 
-    respond_to do |format|
-      format.html # show.html.erb
-    end
-  end
+	# POST /submissions
+	def create
+		@submission = Submission.new(params[:submission])
 
-  # POST /submissions
-  def create
-    @submission = Submission.new(params[:submission])
-    
-    @submission.save_data
-  
-    respond_to do |format|
-      format.html { redirect_to(@submission, :notice => 'Submission was successfully created.') }
-    end
-  end
+		@submission.save_data
 
-  # GET /submits/new
-  # GET /submits/new.xml
-  def new
-    @submit = Submission.new
-
-    respond_to do |format|
-      format.html # new.html.erb
-      format.xml  { render :xml => @submit }
-    end
-  end
-
-
-  def destroy
-    @submit = Submission.find(params[:id])
-    @submit.destroy
-
-    respond_to do |format|
-      format.html { redirect_to(submissions_url) }
-      format.xml  { head :ok }
-    end
-  end
-
+		respond_to do |format|
+			format.html { redirect_to(@submission, :notice => 'Submission was successfully created.') }
+		end
+	end
 end
-
-
-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140209/e63a7bc7/attachment-0001.html>


More information about the macports-changes mailing list