Class: CycletimeHistogram

Inherits:
ChartBase show all
Includes:
GroupableIssueChart
Defined in:
lib/jirametrics/cycletime_histogram.rb

Instance Attribute Summary collapse

Attributes inherited from ChartBase

#aggregated_project, #all_boards, #board_id, #canvas_height, #canvas_width, #data_quality, #date_range, #file_system, #holiday_dates, #issues, #settings, #time_range, #timezone_offset

Instance Method Summary collapse

Methods included from GroupableIssueChart

#group_issues, #grouping_rules, #init_configuration_block

Methods inherited from ChartBase

#aggregated_project?, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_block, #color_for, #completed_issues_in_range, #current_board, #daily_chart_dataset, #describe_non_working_days, #description_text, #format_integer, #format_status, #header_text, #holidays, #html_directory, #icon_span, #label_days, #label_issues, #link_to_issue, #next_id, #random_color, #render, #render_top_text, #status_category_color, #wrap_and_render

Constructor Details

#initialize(block) ⇒ CycletimeHistogram

Returns a new instance of CycletimeHistogram.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jirametrics/cycletime_histogram.rb', line 9

def initialize block
  super()

  header_text 'Cycletime Histogram'
  description_text <<-HTML
    <p>
      The Cycletime Histogram shows how many items completed in a certain timeframe. This can be
      useful for determining how many different types of work are flowing through, based on the
      lengths of time they take.
    </p>
  HTML

  init_configuration_block(block) do
    grouping_rules do |issue, rule|
      rule.label = issue.type
      rule.color = color_for type: issue.type
    end
  end
end

Instance Attribute Details

#possible_statusesObject

Returns the value of attribute possible_statuses.



7
8
9
# File 'lib/jirametrics/cycletime_histogram.rb', line 7

def possible_statuses
  @possible_statuses
end

Instance Method Details

#data_set_for(histogram_data:, label:, color:) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jirametrics/cycletime_histogram.rb', line 56

def data_set_for histogram_data:, label:, color:
  keys = histogram_data.keys.sort
  {
    type: 'bar',
    label: label,
    data: keys.sort.filter_map do |key|
      next if histogram_data[key].zero?

      {
        x: key,
        y: histogram_data[key],
        title: "#{histogram_data[key]} items completed in #{label_days key}"
      }
    end,
    backgroundColor: color,
    borderRadius: 0
  }
end

#histogram_data_for(issues:) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/jirametrics/cycletime_histogram.rb', line 47

def histogram_data_for issues:
  count_hash = {}
  issues.each do |issue|
    days = issue.board.cycletime.cycletime(issue)
    count_hash[days] = (count_hash[days] || 0) + 1 if days.positive?
  end
  count_hash
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jirametrics/cycletime_histogram.rb', line 29

def run
  stopped_issues = completed_issues_in_range include_unstarted: true

  # For the histogram, we only want to consider items that have both a start and a stop time.
  histogram_issues = stopped_issues.select { |issue| issue.board.cycletime.started_stopped_times(issue).first }
  rules_to_issues = group_issues histogram_issues

  data_sets = rules_to_issues.keys.collect do |rules|
    data_set_for(
      histogram_data: histogram_data_for(issues: rules_to_issues[rules]),
      label: rules.label,
      color: rules.color
    )
  end

  wrap_and_render(binding, __FILE__)
end