<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[116891] branches/gsoc11-statistics/stats-server/app/controllers</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/116891">116891</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2014-02-09 08:56:48 -0800 (Sun, 09 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>macports stats: re-indent controllers, remove unneeded submissions actions</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollersapplication_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/application_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollerscategories_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/categories_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollerschart_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollershome_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollersinstalled_ports_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollersos_statistics_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollersports_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb</a></li>
<li><a href="#branchesgsoc11statisticsstatsserverappcontrollerssubmissions_controllerrb">branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesgsoc11statisticsstatsserverappcontrollersapplication_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/application_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,3 @@
</span><span class="cx"> class ApplicationController < ActionController::Base
</span><del>- protect_from_forgery
</del><ins>+        protect_from_forgery
</ins><span class="cx"> end
</span></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollerscategories_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/categories_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,8 +1,8 @@
</span><span class="cx"> class CategoriesController < ApplicationController
</span><del>- caches_page :index
- cache_sweeper :category_sweeper, :only => [:create, :update, :destroy]
</del><ins>+        caches_page :index
+        cache_sweeper :category_sweeper, :only => [:create, :update, :destroy]
</ins><span class="cx">
</span><del>- def index
- @categories = Category.all(:order => 'name ASC')
- end
</del><ins>+        def index
+                @categories = Category.all(:order => 'name ASC')
+        end
</ins><span class="cx"> end
</span></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollerschart_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -3,60 +3,60 @@
</span><span class="cx">
</span><span class="cx"> class ChartController < ApplicationController
</span><span class="cx">
</span><del>- # 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
</del><ins>+        # 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
</ins><span class="cx"> end
</span></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollershome_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/home_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,55 +1,55 @@
</span><span class="cx"> class HomeController < ChartController
</span><del>-
- # Populate the users chart
- def populate_users(chart_name, chart)
- chart.string "Month"
- chart.number "Number of users"
</del><span class="cx">
</span><del>- 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
-
</del><ins>+        # Populate the users chart
+        def populate_users(chart_name, chart)
+                chart.string "Month"
+                chart.number "Number of users"
</ins><span class="cx">
</span><ins>+                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
+
+
</ins><span class="cx"> end
</span></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollersinstalled_ports_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,118 +1,118 @@
</span><span class="cx"> class InstalledPortsController < ChartController
</span><del>-
- # Populate the users chart
- def populate_top25(chart_name, chart)
- chart.string "Port"
- chart.number "Number of installations"
</del><span class="cx">
</span><del>- 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
</del><ins>+        # Populate the users chart
+        def populate_top25(chart_name, chart)
+                chart.string "Port"
+                chart.number "Number of installations"
</ins><span class="cx">
</span><del>- # 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
-
</del><ins>+                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
+
</ins><span class="cx"> end
</span></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollersos_statistics_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,35 +1,35 @@
</span><span class="cx"> class OsStatisticsController < ChartController
</span><del>-
- # 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"
</del><span class="cx">
</span><del>- # 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
</del><span class="cx">\ No newline at end of file
</span><ins>+        # 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
</ins></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollersports_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,168 +1,168 @@
</span><span class="cx"> class PortsController < ChartController
</span><del>- 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"
</del><ins>+        caches_page :index, :show
+        cache_sweeper :port_sweeper, :only => [:create, :update, :destroy]
</ins><span class="cx">
</span><del>- 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
</del><ins>+        # Populate a simple two column chart
+        def populate_simple_chart(chart_name, chart)
+                chart.string "Item"
+                chart.number "Frequency"
</ins><span class="cx">
</span><del>- # 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
</del><ins>+                dataset = chart_dataset chart_name
</ins><span class="cx">
</span><del>- 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
</del><ins>+                dataset.each do |item, count|
+                        chart.add_row([item, count])
+                end
+        end
</ins><span class="cx">
</span><del>- gather_data
-
- respond_to do |format|
- format.html
- end
- end
</del><ins>+        # Populate the versions over time chart
+        def populate_monthly_versions(chart_name, chart)
+                chart.string "Month"
</ins><span class="cx">
</span><del>- def search
- @ports = Port.search(params[:criteria], params[:val], params[:page])
- @page = params[:page] || 1
</del><ins>+                # Add version columns
+                column_order = []
+                @top_versions.each do |version, count|
+                        chart.number version;
+                        column_order << version
+                end
</ins><span class="cx">
</span><del>- respond_to do |format|
- format.html { render :action => :index }
- end
- end
</del><ins>+                # 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
</ins><span class="cx">
</span><del>- def search_generate
- redirect_to "/ports/search/#{params[:criteria]}/#{params[:val]}"
- end
</del><ins>+        # 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
</ins><span class="cx"> end
</span></span></pre></div>
<a id="branchesgsoc11statisticsstatsserverappcontrollerssubmissions_controllerrb"></a>
<div class="modfile"><h4>Modified: branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb (116890 => 116891)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,58 +1,24 @@
</span><span class="cx"> class SubmissionsController < ApplicationController
</span><del>- # GET /submissions
- # GET /submissions.xml
- def index
- @submissions = Submission.all
</del><ins>+        cache_sweeper :installed_port_sweeper, :only => [:create, :update, :destroy]
</ins><span class="cx">
</span><del>- respond_to do |format|
- format.html # index.html.erb
- end
- end
</del><ins>+        # GET /submissions
+        # GET /submissions.xml
+        def index
+                @submissions = Submission.all
</ins><span class="cx">
</span><del>- # GET /submissions/1
- # GET /submissions/1.xml
- def show
- @submission = Submission.find(params[:id])
</del><ins>+                respond_to do |format|
+                        format.html # index.html.erb
+                end
+        end
</ins><span class="cx">
</span><del>- respond_to do |format|
- format.html # show.html.erb
- end
- end
</del><ins>+        # POST /submissions
+        def create
+                @submission = Submission.new(params[:submission])
</ins><span class="cx">
</span><del>- # 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
</del><ins>+                @submission.save_data
</ins><span class="cx">
</span><del>- # 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
-
</del><ins>+                respond_to do |format|
+                        format.html { redirect_to(@submission, :notice => 'Submission was successfully created.') }
+                end
+        end
</ins><span class="cx"> end
</span><del>-
-
-
</del></span></pre>
</div>
</div>
</body>
</html>