Commit edb38d69 authored by Timothy Andrew's avatar Timothy Andrew

Move cycle analytics JSON generation to a helper.

1. Use a new format, with each stage having a `title`, `description`,
   and `value.
parent 7d69ff3d
class Projects::CycleAnalyticsController < Projects::ApplicationController class Projects::CycleAnalyticsController < Projects::ApplicationController
include CycleAnalyticsHelper
before_action :authorize_read_cycle_analytics! before_action :authorize_read_cycle_analytics!
def show def show
...@@ -6,7 +8,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController ...@@ -6,7 +8,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: @cycle_analytics } format.json { render json: cycle_analytics_json(@cycle_analytics) }
end end
end end
......
module CycleAnalyticsHelper
include ActionView::Helpers::DateHelper
def cycle_analytics_json(cycle_analytics)
cycle_analytics_view_data = [[:issue, "Issue", "Time before an issue gets scheduled"],
[:plan, "Plan", "Time before an issue starts implementation"],
[:code, "Code", "Time until first merge request"],
[:test, "Test", "Total test time for all commits/merges"],
[:review, "Review", "Time between MR creation and merge/close"],
[:staging, "Staging", "From MR merge until deploy to production"],
[:production, "Production", "From issue creation until deploy to production"]]
stats = cycle_analytics_view_data.reduce({}) do |hash, (stage_method, stage_text, stage_description)|
hash[stage_method] = {
title: stage_text,
description: stage_description,
value: distance_of_time_in_words(cycle_analytics.send(stage_method))
}
hash
end
{ stats: stats }
end
end
...@@ -6,13 +6,6 @@ class CycleAnalytics ...@@ -6,13 +6,6 @@ class CycleAnalytics
@from = from @from = from
end end
def as_json(options = {})
{
issue: issue, plan: plan, code: code, test: test,
review: review, staging: staging, production: production
}
end
def issue def issue
calculate_metric!(:issue, calculate_metric!(:issue,
TableReferences.issues[:created_at], TableReferences.issues[:created_at],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment