From 65f1cfc822dfa3e31f423c129163405331771425 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 12 Apr 2012 18:55:32 +0400 Subject: [PATCH] [refs #223] Add current duration and project average build time --- app/models/build_list.rb | 8 ++++++++ app/models/build_list_observer.rb | 2 +- app/models/project.rb | 9 +++++++++ app/views/build_lists/show.html.haml | 9 +++++++++ config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + config/locales/models/project.en.yml | 1 + config/locales/models/project.ru.yml | 1 + 8 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index b6b80c73e..a5e6ccff2 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -139,6 +139,14 @@ class BuildList < ActiveRecord::Base {:project => project.name, :version => project_version, :arch => arch.name}.inspect end + def current_duration + (Time.now - started_at).to_i + end + + def human_current_duration + I18n.t("layout.build_lists.human_current_duration", {:minutes => (current_duration/60).to_i, :seconds => (current_duration%60).to_i}) + end + def human_duration I18n.t("layout.build_lists.human_duration", {:minutes => (duration/60).to_i, :seconds => (duration%60).to_i}) end diff --git a/app/models/build_list_observer.rb b/app/models/build_list_observer.rb index 793ff8e48..f3763f205 100644 --- a/app/models/build_list_observer.rb +++ b/app/models/build_list_observer.rb @@ -6,7 +6,7 @@ class BuildListObserver < ActiveRecord::Observer record.started_at = Time.now if record.status == BuildServer::BUILD_STARTED if [BuildServer::BUILD_ERROR, BuildServer::SUCCESS].include? record.status # stores time interval beetwin build start and finish in seconds - record.duration = (Time.now - record.started_at).to_i + record.duration = record.current_duration end end end diff --git a/app/models/project.rb b/app/models/project.rb index 2e5f0f277..b82ddae9f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -203,6 +203,15 @@ 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) + end + protected def build_path(dir) diff --git a/app/views/build_lists/show.html.haml b/app/views/build_lists/show.html.haml index b41323e91..bbbcb3b28 100644 --- a/app/views/build_lists/show.html.haml +++ b/app/views/build_lists/show.html.haml @@ -57,6 +57,15 @@ .leftside.width125 .leftside= @build_list.human_duration .both +- 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 + .both + .hr %h3= t("layout.build_lists.items_header") - if @item_groups.blank? diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 2f2aaba8e..048334f06 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -61,6 +61,7 @@ en: new_header: New build main_data: Main data human_duration: Build lasted %{minutes} minutes %{seconds} seconds + human_current_duration: Build currently takes %{minutes} minutes %{seconds} seconds ownership: header: Build list ownership diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index a3baf1f95..9b0353f4f 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -60,6 +60,7 @@ ru: new_header: Новая сборка main_data: Основные данные human_duration: Сборка продлилась %{minutes} минут %{seconds} секунд + human_current_duration: Сборка длится уже %{minutes} минут %{seconds} секунд ownership: header: Принадлежность заданий diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index 1d38c6b45..610f701d2 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -33,6 +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 git_help: cloning: Cloning the repository diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index 219437767..a05c8cc21 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -33,6 +33,7 @@ ru: sections: Разделы has_issue_description: Трэкер предоставляет лекговесный менеджер для задач по разработке Вашего проекта. has_wiki_description: Wiki - это самый простой способ предоставить другим вносить свой вклад в развитие Вашего проекта. Каждый пользователь нашего сервиса может использовать Wiki для документирования, примеров, поддержки или всего другого, в чем у Вас появится необходимость. + human_average_build_time: Среднее время сборки %{minutes} минут %{seconds} секунд diff_show_header: "%{files} с %{additions} и %{deletions}." about_subheader: "О проекте"