summaryrefslogtreecommitdiff
path: root/app/helpers/cycle_analytics_helper.rb
blob: c49c51642ede8118ac89d80778a8d9464ea31ba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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