diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-08-25 11:24:41 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-08-26 16:28:20 +0530 |
commit | 487906b3861068a8f81125814f919a07bfab8469 (patch) | |
tree | 13bb6d62ad6211c2f7075e0d1321f5405acbfeb0 /app/models/cycle_analytics.rb | |
parent | f932bb8e41852d7bdcd66fe15a56277074df3aa3 (diff) | |
download | gitlab-ce-487906b3861068a8f81125814f919a07bfab8469.tar.gz |
Add the "Code" Cycle Analytics section.
1. Record the `wip_flag_first_removed_at` and
`first_assigned_to_user_other_than_author` metrics for a merge
request. Use a `merge_request_metrics` table, similar to the one for
`issues`. Metrics are recorded `after_save`.
2. Move larger queries to a `CycleAnalytics::Queries` module.
Diffstat (limited to 'app/models/cycle_analytics.rb')
-rw-r--r-- | app/models/cycle_analytics.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index d037b1fef12..68efa826b5a 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -2,20 +2,22 @@ class CycleAnalytics def issue issues = Issue.includes(:metrics).where("issue_metrics.id IS NOT NULL").references(:issue_metrics).to_a start_time_fn = -> (issue) { issue.created_at } - end_time_fn = -> (issue) { issue.metrics.first_associated_with_milestone_at.presence || issue.metrics.first_added_to_board_at.presence } - - calculate_metric(issues, start_time_fn, end_time_fn) + calculate_metric(issues, start_time_fn, Queries::issue_first_associated_with_milestone_or_first_added_to_list_label_time) end def plan issues = Issue.includes(:metrics).where("issue_metrics.id IS NOT NULL").references(:issue_metrics).to_a - start_time_fn = -> (issue) { issue.metrics.first_associated_with_milestone_at.presence || issue.metrics.first_added_to_board_at.presence } - end_time_fn = lambda do |issue| - merge_requests = issue.closed_by_merge_requests - merge_requests.map(&:created_at).min if merge_requests.present? - end + calculate_metric(issues, + Queries::issue_first_associated_with_milestone_or_first_added_to_list_label_time, + Queries::issue_closing_merge_request_opened_time) + end - calculate_metric(issues, start_time_fn, end_time_fn) + def code + issues = Issue.all.to_a + start_time_fn = -> (merge_request) { merge_request.created_at } + calculate_metric(issues.map(&:closed_by_merge_requests).flatten, + start_time_fn, + Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time) end private @@ -34,6 +36,7 @@ class CycleAnalytics end def median(coll) + return if coll.empty? size = coll.length (coll[size / 2] + coll[(size - 1) / 2]) / 2.0 end |