[116892] branches/gsoc11-statistics/stats-server/app
cal at macports.org
cal at macports.org
Sun Feb 9 08:57:56 PST 2014
Revision: 116892
https://trac.macports.org/changeset/116892
Author: cal at macports.org
Date: 2014-02-09 08:57:56 -0800 (Sun, 09 Feb 2014)
Log Message:
-----------
macports stats: re-indent helpers, models, sweepers
Modified Paths:
--------------
branches/gsoc11-statistics/stats-server/app/helpers/application_helper.rb
branches/gsoc11-statistics/stats-server/app/helpers/ports_helper.rb
branches/gsoc11-statistics/stats-server/app/models/category.rb
branches/gsoc11-statistics/stats-server/app/models/installed_port.rb
branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb
branches/gsoc11-statistics/stats-server/app/models/port.rb
branches/gsoc11-statistics/stats-server/app/models/submission.rb
branches/gsoc11-statistics/stats-server/app/models/user.rb
branches/gsoc11-statistics/stats-server/app/sweepers/category_sweeper.rb
branches/gsoc11-statistics/stats-server/app/sweepers/port_sweeper.rb
Modified: branches/gsoc11-statistics/stats-server/app/helpers/application_helper.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/helpers/application_helper.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/helpers/application_helper.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,3 +1,3 @@
module ApplicationHelper
- include GoogleVisualization
+ include GoogleVisualization
end
Modified: branches/gsoc11-statistics/stats-server/app/helpers/ports_helper.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/helpers/ports_helper.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/helpers/ports_helper.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,14 +1,14 @@
module PortsHelper
- def print_search_links(port, member)
- links = String.new
- vals = port[member.to_sym]
- unless vals.nil?
- vals.split(" ").each do |val|
- links += "#{link_to val, search_path(member, val)} "
- end
- return raw(links)
- else
- return nil
- end
- end
+ def print_search_links(port, member)
+ links = String.new
+ vals = port[member.to_sym]
+ unless vals.nil?
+ vals.split(" ").each do |val|
+ links += "#{link_to val, search_path(member, val)} "
+ end
+ return raw(links)
+ else
+ return nil
+ end
+ end
end
Modified: branches/gsoc11-statistics/stats-server/app/models/category.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/category.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/models/category.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,5 +1,5 @@
class Category < ActiveRecord::Base
- has_many :ports
-
- validates_presence_of :name
+ has_many :ports
+
+ validates_presence_of :name
end
Modified: branches/gsoc11-statistics/stats-server/app/models/installed_port.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/installed_port.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/models/installed_port.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,55 +1,55 @@
class InstalledPort < ActiveRecord::Base
- belongs_to :port
- has_one :user
-
- validates_presence_of :user_id, :port_id, :version
-
- # Populate InstalledPort rows based on submitted JSON data
- def self.add_installed_ports(uuid, installed_ports)
- logger.debug "In add_installed_ports"
-
- if installed_ports.nil?
- return
- end
-
- current_time = Time.now
- month = current_time.month
- year = current_time.year
-
- installed_ports.each do |installed_port|
- # Find the reported port in the MacPorts repository
- macports_port = Port.find_by_name(installed_port['name'])
+ belongs_to :port
+ has_one :user
- if macports_port.nil?
- logger.debug {"Skipping unknown port #{installed_port['name']} - Not in MacPorts repository"}
- next
- end
-
- # Update installed port information
- InstalledPort.add_port(uuid, macports_port, installed_port, month, year)
- end
- end
-
- def self.add_port(user, macports_port, installed_port, month, year)
- logger.debug {"Adding installed port #{installed_port['name']}"}
-
- # Update any ports found for this user if they have already been submitted this month
- port_entrys = user.installed_ports.where(:created_at => (Date.today.at_beginning_of_month)..(Date.today.at_end_of_month))
- port_entry = port_entrys.find_by_port_id(macports_port.id)
+ validates_presence_of :user_id, :port_id, :version
- # No existing entry was found - create a new one
- if port_entry.nil?
- port_entry = InstalledPort.new
- end
-
- port_entry[:user_id] = user.id
- port_entry[:port_id] = macports_port.id
- port_entry[:version] = installed_port['version']
- port_entry[:variants] = installed_port['variants']
-
- if not port_entry.save
- logger.debug "Unable to save port #{installed_port['name']}"
- logger.debug "Reason: #{port_entry.errors.full_messages}"
- end
- end
+ # Populate InstalledPort rows based on submitted JSON data
+ def self.add_installed_ports(uuid, installed_ports)
+ logger.debug "In add_installed_ports"
+
+ if installed_ports.nil?
+ return
+ end
+
+ current_time = Time.now
+ month = current_time.month
+ year = current_time.year
+
+ installed_ports.each do |installed_port|
+ # Find the reported port in the MacPorts repository
+ macports_port = Port.find_by_name(installed_port['name'])
+
+ if macports_port.nil?
+ logger.debug {"Skipping unknown port #{installed_port['name']} - Not in MacPorts repository"}
+ next
+ end
+
+ # Update installed port information
+ InstalledPort.add_port(uuid, macports_port, installed_port, month, year)
+ end
+ end
+
+ def self.add_port(user, macports_port, installed_port, month, year)
+ logger.debug {"Adding installed port #{installed_port['name']}"}
+
+ # Update any ports found for this user if they have already been submitted this month
+ port_entrys = user.installed_ports.where(:created_at => (Date.today.at_beginning_of_month)..(Date.today.at_end_of_month))
+ port_entry = port_entrys.find_by_port_id(macports_port.id)
+
+ # No existing entry was found - create a new one
+ if port_entry.nil?
+ port_entry = InstalledPort.new
+ end
+
+ port_entry[:user_id] = user.id
+ port_entry[:port_id] = macports_port.id
+ port_entry[:version] = installed_port['version']
+ port_entry[:variants] = installed_port['variants']
+
+ if not port_entry.save
+ logger.debug "Unable to save port #{installed_port['name']}"
+ logger.debug "Reason: #{port_entry.errors.full_messages}"
+ end
+ end
end
Modified: branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,83 +1,83 @@
class OsStatistic < ActiveRecord::Base
- belongs_to :user, :validate => true
+ belongs_to :user, :validate => true
- attr_accessible :macports_version
- attr_accessible :osx_version
- attr_accessible :os_arch
- attr_accessible :os_platform
- attr_accessible :build_arch
- attr_accessible :gcc_version
- attr_accessible :xcode_version
+ attr_accessible :macports_version
+ attr_accessible :osx_version
+ attr_accessible :os_arch
+ attr_accessible :os_platform
+ attr_accessible :build_arch
+ attr_accessible :gcc_version
+ attr_accessible :xcode_version
- validates :macports_version, :presence => true
- validates :osx_version, :presence => true
- validates :os_arch, :presence => true
- validates :os_platform, :presence => true
- validates :build_arch, :presence => true
- validates :gcc_version, :presence => true
- validates :xcode_version, :presence => true
+ validates :macports_version, :presence => true
+ validates :osx_version, :presence => true
+ validates :os_arch, :presence => true
+ validates :os_platform, :presence => true
+ validates :build_arch, :presence => true
+ validates :gcc_version, :presence => true
+ validates :xcode_version, :presence => true
- # Populate an OsStatistics row with data
- def self.add_os_data(user, os)
- # os and user must not be nil
- # Also, user must not be a new record (i.e. it should be in the database)
- if os.nil? || user.nil? || user.new_record?
- return false
- end
-
- macports_version = os['macports_version']
- osx_version = os['osx_version']
- os_arch = os['os_arch']
- os_platform = os['os_platform']
- build_arch = os['build_arch']
- gcc_version = os['gcc_version']
- xcode_version = os['xcode_version']
-
- # Try to find an existing entry
- os_stats = user.os_statistic
-
- if os_stats.nil?
- # No entry for this user - create a new one
- os_stats = OsStatistic.new()
- end
-
- os_stats[:user_id] = user.id
- os_stats[:macports_version] = macports_version
- os_stats[:osx_version] = osx_version
- os_stats[:os_arch] = os_arch
- os_stats[:os_platform] = os_platform
- os_stats[:build_arch] = build_arch
- os_stats[:gcc_version] = gcc_version
- os_stats[:xcode_version] = xcode_version
-
- return os_stats.save
- end
+ # Populate an OsStatistics row with data
+ def self.add_os_data(user, os)
+ # os and user must not be nil
+ # Also, user must not be a new record (i.e. it should be in the database)
+ if os.nil? || user.nil? || user.new_record?
+ return false
+ end
- # Returns a hash of frequency hashes with a key for each column
- # The frequency hash contains counts of the number of times a value has
- # appeared in its column.
- # e.g. If "2.0.0" appears 8 times in the "macports_version" column then
- # frequencies["macports_version"]["2.0.0"] == 8
- def self.frequencies
-
- columns = { "macports_version" => Hash.new(0),
- "osx_version" => Hash.new(0),
- "os_arch" => Hash.new(0),
- "os_platform" => Hash.new(0),
- "build_arch" => Hash.new(0),
- "gcc_version" => Hash.new(0),
- "xcode_version" => Hash.new(0)
- }
-
- OsStatistic.find_each do |os_stat|
- # For each column in OsStatistics count the number of occurrences of a particular value
- columns.each do |column, hash|
- value = os_stat.attributes[column]
- hash[value] = hash[value] + 1
- end
- end
-
- return columns
- end
+ macports_version = os['macports_version']
+ osx_version = os['osx_version']
+ os_arch = os['os_arch']
+ os_platform = os['os_platform']
+ build_arch = os['build_arch']
+ gcc_version = os['gcc_version']
+ xcode_version = os['xcode_version']
+ # Try to find an existing entry
+ os_stats = user.os_statistic
+
+ if os_stats.nil?
+ # No entry for this user - create a new one
+ os_stats = OsStatistic.new()
+ end
+
+ os_stats[:user_id] = user.id
+ os_stats[:macports_version] = macports_version
+ os_stats[:osx_version] = osx_version
+ os_stats[:os_arch] = os_arch
+ os_stats[:os_platform] = os_platform
+ os_stats[:build_arch] = build_arch
+ os_stats[:gcc_version] = gcc_version
+ os_stats[:xcode_version] = xcode_version
+
+ return os_stats.save
+ end
+
+ # Returns a hash of frequency hashes with a key for each column
+ # The frequency hash contains counts of the number of times a value has
+ # appeared in its column.
+ # e.g. If "2.0.0" appears 8 times in the "macports_version" column then
+ # frequencies["macports_version"]["2.0.0"] == 8
+ def self.frequencies
+
+ columns = { "macports_version" => Hash.new(0),
+ "osx_version" => Hash.new(0),
+ "os_arch" => Hash.new(0),
+ "os_platform" => Hash.new(0),
+ "build_arch" => Hash.new(0),
+ "gcc_version" => Hash.new(0),
+ "xcode_version" => Hash.new(0)
+ }
+
+ OsStatistic.find_each do |os_stat|
+ # For each column in OsStatistics count the number of occurrences of a particular value
+ columns.each do |column, hash|
+ value = os_stat.attributes[column]
+ hash[value] = hash[value] + 1
+ end
+ end
+
+ return columns
+ end
+
end
Modified: branches/gsoc11-statistics/stats-server/app/models/port.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/port.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/models/port.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,10 +1,10 @@
class Port < ActiveRecord::Base
- belongs_to :category
- has_many :installed_ports
+ belongs_to :category
+ has_many :installed_ports
- validates_presence_of :name, :version
+ validates_presence_of :name, :version
- def self.search(criteria, val, page)
- paginate :per_page => 50, :page => page, :conditions => ["#{self.columns_hash[criteria].name} like ?", "%#{val}%"], :order => 'name ASC'
- end
+ def self.search(criteria, val, page)
+ paginate :per_page => 50, :page => page, :conditions => ["#{self.columns_hash[criteria].name} like ?", "%#{val}%"], :order => 'name ASC'
+ end
end
Modified: branches/gsoc11-statistics/stats-server/app/models/submission.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/submission.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/models/submission.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,15 +1,15 @@
class Submission < ActiveRecord::Base
-
- def save_data
- json = ActiveSupport::JSON.decode(data)
- os = json['os']
- active_ports = json['active_ports']
- #inactive_ports = json['inactive_ports']
-
- user = User.find_or_create_by_uuid(json['id'])
-
- OsStatistic.add_os_data(user, os)
- InstalledPort.add_installed_ports(user, active_ports)
- end
-
+
+ def save_data
+ json = ActiveSupport::JSON.decode(data)
+ os = json['os']
+ active_ports = json['active_ports']
+ #inactive_ports = json['inactive_ports']
+
+ user = User.find_or_create_by_uuid(json['id'])
+
+ OsStatistic.add_os_data(user, os)
+ InstalledPort.add_installed_ports(user, active_ports)
+ end
+
end
Modified: branches/gsoc11-statistics/stats-server/app/models/user.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/user.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/models/user.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,13 +1,13 @@
class User < ActiveRecord::Base
- has_one :os_statistic
- has_many :installed_ports
-
- validates_presence_of :uuid
- validate :uuid_cannot_be_invalid
-
- def uuid_cannot_be_invalid
- if !UUID.validate(uuid)
- errors.add(:uuid, "uuid must be a valid universally unique identifier")
- end
- end
+ has_one :os_statistic
+ has_many :installed_ports
+
+ validates_presence_of :uuid
+ validate :uuid_cannot_be_invalid
+
+ def uuid_cannot_be_invalid
+ if !UUID.validate(uuid)
+ errors.add(:uuid, "uuid must be a valid universally unique identifier")
+ end
+ end
end
Modified: branches/gsoc11-statistics/stats-server/app/sweepers/category_sweeper.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/sweepers/category_sweeper.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/sweepers/category_sweeper.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,21 +1,21 @@
class CategorySweeper < ActionController::Caching::Sweeper
- observe Category
+ observe Category
- def after_create(category)
- expire_cache_for category
- end
+ def after_create(category)
+ expire_cache_for category
+ end
- def after_update(category)
- expire_cache_for category
- end
+ def after_update(category)
+ expire_cache_for category
+ end
- def after_destroy(category)
- expire_cache_for category
- end
+ def after_destroy(category)
+ expire_cache_for category
+ end
-private
- def expire_cache_for(category)
- expire_page categories_path
- expire_page category_path(category)
- end
-end
\ No newline at end of file
+ private
+ def expire_cache_for(category)
+ expire_page categories_path
+ expire_page category_path(category)
+ end
+end
Modified: branches/gsoc11-statistics/stats-server/app/sweepers/port_sweeper.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/sweepers/port_sweeper.rb 2014-02-09 16:56:48 UTC (rev 116891)
+++ branches/gsoc11-statistics/stats-server/app/sweepers/port_sweeper.rb 2014-02-09 16:57:56 UTC (rev 116892)
@@ -1,21 +1,21 @@
class PortSweeper < ActionController::Caching::Sweeper
- observe Port
+ observe Port
- def after_create(port)
- expire_cache_for port
- end
+ def after_create(port)
+ expire_cache_for port
+ end
- def after_update(port)
- expire_cache_for port
- end
+ def after_update(port)
+ expire_cache_for port
+ end
- def after_destroy(port)
- expire_cache_for port
- end
+ def after_destroy(port)
+ expire_cache_for port
+ end
-private
- def expire_cache_for(port)
- expire_page category_ports_path(port.category)
- expire_page category_port_path(port.category, port)
- end
-end
\ No newline at end of file
+ private
+ def expire_cache_for(port)
+ expire_page category_ports_path(port.category)
+ expire_page category_port_path(port.category, port)
+ end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140209/98e51af5/attachment.html>
More information about the macports-changes
mailing list