diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-08-25 08:02:27 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-08-26 13:57:37 +0300 |
commit | f932bb8e41852d7bdcd66fe15a56277074df3aa3 (patch) | |
tree | 1fbdd0aad33f095b543ece238eac5b3f71d311b7 /app/controllers/projects/cycle_analytics_controller.rb | |
parent | 8ccea81cba048021ed9eded83db15b383ecd4a32 (diff) |
Add the "Plan" Cycle Analytics query.
1. Move from raw SQL to ActiveRecord.
2. Add a non-persisted `CycleAnalytics` model to store all the queries.
Diffstat (limited to 'app/controllers/projects/cycle_analytics_controller.rb')
-rw-r--r-- | app/controllers/projects/cycle_analytics_controller.rb | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb index ed885729fbb..9dab7bfa380 100644 --- a/app/controllers/projects/cycle_analytics_controller.rb +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -1,32 +1,5 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController def show - @metrics = { - issue: issue - } - end - - private - - def issue - query = <<-HEREDOC - WITH ordered_data AS ( - SELECT extract(milliseconds FROM (COALESCE(first_associated_with_milestone_at, first_added_to_board_at) - issues.created_at)) AS data_point, - row_number() over (order by (COALESCE(first_associated_with_milestone_at, first_added_to_board_at) - issues.created_at)) as row_id - FROM issues - INNER JOIN issue_metrics ON issue_metrics.issue_id = issues.id - WHERE COALESCE(first_associated_with_milestone_at, first_added_to_board_at) IS NOT NULL - ), - - ct AS ( - SELECT count(1) AS ct - FROM ordered_data - ) - - SELECT avg(data_point) AS median - FROM ordered_data - WHERE row_id between (select ct from ct)/2.0 and (select ct from ct)/2.0 + 1; - HEREDOC - - ActiveRecord::Base.connection.execute(query).to_a.first['median'] + @cycle_analytics = CycleAnalytics.new end end |