[Refs #223] Refactoring for pull request

This commit is contained in:
Vladimir Sharshov 2012-04-13 17:24:43 +04:00
parent 8ffc6be347
commit 100a166699
7 changed files with 36 additions and 23 deletions

View File

@ -7,6 +7,15 @@ class BuildListObserver < ActiveRecord::Observer
if [BuildServer::BUILD_ERROR, BuildServer::SUCCESS].include? record.status
# stores time interval beetwin build start and finish in seconds
record.duration = record.current_duration
if record.status == BuildServer::SUCCESS
# Update project average build time
av_time = record.project.average_build_time
n = record.project.build_count
new_av_time = ( av_time * n + record.duration ) / ( n + 1 )
record.project.update_attribute(:average_build_time, new_av_time)
record.project.update_attribute(:build_count, n + 1 )
end
end
end
end

View File

@ -203,13 +203,9 @@ class Project < ActiveRecord::Base
recipients
end
def average_build_time
build_lists.where(:status => BuildServer::SUCCESS).average(:duration)
end
def human_average_build_time
time = average_build_time
I18n.t("layout.projects.human_average_build_time", :minutes => (time/60).to_i, :seconds => (time%60).to_i)
I18n.t("layout.projects.human_average_build_time", {:hours => (time/360).to_i, :minutes => (time/60).to_i})
end
protected

View File

@ -60,10 +60,8 @@
- if !@build_list.finished? && @build_list.started_at
%br
.leftside.width125
.leftside= @build_list.human_current_duration
.both
.leftside.width125
.leftside= @build_list.project.human_average_build_time
.leftside
= "#{@build_list.human_current_duration} / #{@build_list.project.human_average_build_time}"
.both
.hr

View File

@ -33,7 +33,7 @@ en:
sections: Sections
has_issue_description: Tracker adds a lightweight issue management system tightly integrated with your repository.
has_wiki_description: Wikis are the simplest way to allow other users to contribute content. Any user can create and edit pages for documentation, examples, support or anything you wish.
human_average_build_time: Average build time is %{minutes} minutes %{seconds} seconds
human_average_build_time: Expected time is %{hours} h. %{minutes} min.
git_help:
cloning: Cloning the repository

View File

@ -33,7 +33,7 @@ ru:
sections: Разделы
has_issue_description: Трэкер предоставляет лекговесный менеджер для задач по разработке Вашего проекта.
has_wiki_description: Wiki - это самый простой способ предоставить другим вносить свой вклад в развитие Вашего проекта. Каждый пользователь нашего сервиса может использовать Wiki для документирования, примеров, поддержки или всего другого, в чем у Вас появится необходимость.
human_average_build_time: Среднее время сборки %{minutes} минут %{seconds} секунд
human_average_build_time: 'Ожидаемое время: %{hours} ч. %{minutes} мин.'
diff_show_header: "%{files} с %{additions} и %{deletions}."
about_subheader: "О проекте"

View File

@ -0,0 +1,6 @@
class BuildAverageTime < ActiveRecord::Migration
def change
add_column :projects, :average_build_time, :integer, :null => false, :default => 0
add_column :projects, :build_count, :integer, :null => false, :default => 0
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120411142354) do
ActiveRecord::Schema.define(:version => 20120413102757) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -190,7 +190,7 @@ ActiveRecord::Schema.define(:version => 20120411142354) do
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type"
t.string "distrib_type", :null => false
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
@ -261,23 +261,27 @@ ActiveRecord::Schema.define(:version => 20120411142354) do
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_rpm", :default => true
t.integer "average_build_time", :default => 0, :null => false
t.integer "build_count", :default => 0, :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
create_table "register_requests", :force => true do |t|
t.string "name"
t.string "email"
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "interest"
t.text "more"
end
@ -339,9 +343,6 @@ ActiveRecord::Schema.define(:version => 20120411142354) do
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.text "professional_experience"
@ -355,6 +356,9 @@ ActiveRecord::Schema.define(:version => 20120411142354) do
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
end
add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true