#245: added ProjectStatistic model
This commit is contained in:
parent
719d3a5eb2
commit
e38bfa797f
|
@ -14,9 +14,10 @@ class BuildListObserver < ActiveRecord::Observer
|
|||
|
||||
if record.status == BuildList::SUCCESS
|
||||
# Update project average build time
|
||||
build_count = record.project.build_count
|
||||
new_av_time = ( record.project.average_build_time * build_count + record.duration ) / ( build_count + 1 )
|
||||
record.project.update_attributes({ :average_build_time => new_av_time, :build_count => build_count + 1 }, :without_protection => true)
|
||||
statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id)
|
||||
build_count = statistic.build_count
|
||||
new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 )
|
||||
statistic.update_attributes(:average_build_time => new_av_time, :build_count => build_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,7 @@ class Project < ActiveRecord::Base
|
|||
has_many :project_to_repositories, :dependent => :destroy
|
||||
has_many :repositories, :through => :project_to_repositories
|
||||
has_many :project_tags, :dependent => :destroy
|
||||
has_many :project_statistics, :dependent => :destroy
|
||||
|
||||
has_many :build_lists, :dependent => :destroy
|
||||
has_many :hooks, :dependent => :destroy
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class ProjectStatistic < ActiveRecord::Base
|
||||
|
||||
belongs_to :arch
|
||||
belongs_to :project
|
||||
|
||||
validates :arch_id, :project_id, :average_build_time, :build_count, :presence => true
|
||||
validates :project_id, :uniqueness => {:scope => :arch_id}
|
||||
|
||||
attr_accessible :arch_id, :average_build_time, :build_count, :project_id
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
class CreateProjectStatistics < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :project_statistics do |t|
|
||||
t.integer :average_build_time, :null => false, :default => 0
|
||||
t.integer :build_count, :null => false, :default => 0
|
||||
t.integer :arch_id, :null => false
|
||||
t.integer :project_id, :null => false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :project_statistics, [:project_id, :arch_id], :unique => true
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130724105821) do
|
||||
ActiveRecord::Schema.define(:version => 20130731120901) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
@ -376,6 +376,17 @@ ActiveRecord::Schema.define(:version => 20130724105821) do
|
|||
|
||||
add_index "project_imports", ["platform_id", "name"], :name => "index_project_imports_on_name_and_platform_id", :unique => true, :case_sensitive => false
|
||||
|
||||
create_table "project_statistics", :force => true do |t|
|
||||
t.integer "average_build_time", :default => 0, :null => false
|
||||
t.integer "build_count", :default => 0, :null => false
|
||||
t.integer "arch_id", :null => false
|
||||
t.integer "project_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "project_statistics", ["project_id", "arch_id"], :name => "index_project_statistics_on_project_id_and_arch_id", :unique => true
|
||||
|
||||
create_table "project_tags", :force => true do |t|
|
||||
t.integer "project_id"
|
||||
t.string "commit_id"
|
||||
|
|
Loading…
Reference in New Issue