Class: StoryPointAccuracyChart

Inherits:
ChartBase show all
Defined in:
lib/jirametrics/story_point_accuracy_chart.rb

Instance Attribute Summary

Attributes inherited from ChartBase

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

Instance Method Summary collapse

Methods inherited from ChartBase

#aggregated_project?, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_for, #completed_issues_in_range, #current_board, #daily_chart_dataset, #description_text, #filter_issues, #format_integer, #format_status, #header_text, #holidays, #label_days, #label_issues, #link_to_issue, #next_id, #random_color, #render, #sprints_in_time_range, #status_category_color, #wrap_and_render

Constructor Details

#initialize(configuration_block = nil) ⇒ StoryPointAccuracyChart

Returns a new instance of StoryPointAccuracyChart.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 4

def initialize configuration_block = nil
  super()

  header_text 'Estimate Accuracy'
  description_text <<-HTML
    <p>
      This chart graphs estimates against actual recorded cycle times. Since
      estimates can change over time, we're graphing the estimate at the time that the story started.
    </p>
    <p>
      The completed dots indicate cycletimes. The aging dots (if you turn them on) show the current
      age of items, which will give you a hint as to where they might end up. If they're already
      far to the right then you know you have a problem.
    </p>
  HTML

  @y_axis_label = 'Story Point Estimates'
  @y_axis_type = 'linear'
  @y_axis_block = ->(issue, start_time) { story_points_at(issue: issue, start_time: start_time)&.to_f }
  @y_axis_sort_order = nil

  instance_eval(&configuration_block) if configuration_block
end

Instance Method Details

#grouping(range:, color:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



124
125
126
127
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 124

def grouping range:, color: # rubocop:disable Lint/UnusedMethodArgument
  deprecated message: 'The grouping declaration is no longer supported on the StoryPointEstimateChart ' \
    'as we now use a bubble chart rather than colors'
end

#hash_sorterObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 89

def hash_sorter
  lambda do |arg1, arg2|
    estimate1 = arg1[0][0]
    estimate2 = arg2[0][0]
    sample_count1 = arg1.size
    sample_count2 = arg2.size

    if @y_axis_sort_order
      index1 = @y_axis_sort_order.index estimate1
      index2 = @y_axis_sort_order.index estimate2

      if index1.nil?
        comparison = 1
      elsif index2.nil?
        comparison = -1
      else
        comparison = index1 <=> index2
      end
      return comparison unless comparison.zero?
    end

    sample_count2 <=> sample_count1
  end
end

#runObject



28
29
30
31
32
33
34
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 28

def run
  data_sets = scan_issues

  return '' if data_sets.empty?

  wrap_and_render(binding, __FILE__)
end

#scan_issuesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 36

def scan_issues
  aging_hash = {}
  completed_hash = {}

  issues.each do |issue|
    cycletime = issue.board.cycletime
    start_time = cycletime.started_time(issue)
    stop_time = cycletime.stopped_time(issue)

    next unless start_time

    hash = stop_time ? completed_hash : aging_hash

    estimate = @y_axis_block.call issue, start_time
    cycle_time = ((stop_time&.to_date || date_range.end) - start_time.to_date).to_i + 1

    next if estimate.nil?

    key = [estimate, cycle_time]
    (hash[key] ||= []) << issue
  end

  [
    [completed_hash, 'Completed', '#66FF99', 'green', false],
    [aging_hash, 'Still in progress', '#FFCCCB', 'red', true]
  ].collect do |hash, label, fill_color, border_color, starts_hidden|
    # We sort so that the smaller circles are in front of the bigger circles.
    data = hash.sort(&hash_sorter).collect do |key, values|
      estimate, cycle_time = *key
      estimate_label = "#{estimate}#{'pts' if @y_axis_type == 'linear'}"
      title = ["Estimate: #{estimate_label}, Cycletime: #{label_days(cycle_time)}, #{values.size} issues"] +
        values.collect { |issue| "#{issue.key}: #{issue.summary}" }
      {
        'x' => cycle_time,
        'y' => estimate,
        'r' => values.size * 2,
        'title' => title
      }
    end.compact
    next if data.empty?

    {
      'label' => label,
      'data' => data,
      'fill' => false,
      'showLine' => false,
      'backgroundColor' => fill_color,
      'borderColor' => border_color,
      'hidden' => starts_hidden
    }
  end.compact
end

#story_points_at(issue:, start_time:) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 114

def story_points_at issue:, start_time:
  story_points = nil
  issue.changes.each do |change|
    return story_points if change.time >= start_time

    story_points = change.value if change.story_points?
  end
  story_points
end

#y_axis(label:, sort_order: nil, &block) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# File 'lib/jirametrics/story_point_accuracy_chart.rb', line 129

def y_axis label:, sort_order: nil, &block
  @y_axis_sort_order = sort_order
  @y_axis_label = label
  if sort_order
    @y_axis_type = 'category'
  else
    @y_axis_type = 'linear'
  end
  @y_axis_block = block
end