diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..ed885729fbba0953e4d253601a98b5f23d01e01c --- /dev/null +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -0,0 +1,32 @@ +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'] + end +end diff --git a/app/views/projects/cycle_analytics/show.html.haml b/app/views/projects/cycle_analytics/show.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..e9bdd71b30aca896400fd9d7b4fdd77d8e5bba7e --- /dev/null +++ b/app/views/projects/cycle_analytics/show.html.haml @@ -0,0 +1 @@ +%pre= @metrics diff --git a/config/routes.rb b/config/routes.rb index 24f9b44a53a4e59fb8c31daf4d3524b43ec84776..270c71f1a00f6468ef3f07f5aff2ae55efd1ecc2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -779,6 +779,8 @@ Rails.application.routes.draw do resources :environments + resource :cycle_analytics + resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do collection do post :cancel_all