Class: CycletimeScatterplot

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

Instance Attribute Summary collapse

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 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_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(block = nil) ⇒ CycletimeScatterplot

Returns a new instance of CycletimeScatterplot.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 10

def initialize block = nil
  super()

  header_text 'Cycletime Scatterplot'
  description_text <<-HTML
    <p>
      This chart shows only completed work and indicates both what day it completed as well as
      how many days it took to get done. Hovering over a dot will show you the ID of the work item.
    </p>
    <p>
      The gray line indicates the 85th percentile (<%= overall_percent_line %> days). 85% of all
      items on this chart fall on or below the line and the remaining 15% are above the line. 85%
      is a reasonable proxy for "most" so that we can say that based on this data set, we can
      predict that most work of this type will complete in <%= overall_percent_line %> days or
      less. The other lines reflect the 85% line for that respective type of work.
    </p>
    <p>
      The gray vertical bars indicate weekends, when theoretically we aren't working.
    </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

  @percentage_lines = []
  @highest_cycletime = 0
end

Instance Attribute Details

#possible_statusesObject

Returns the value of attribute possible_statuses.



8
9
10
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 8

def possible_statuses
  @possible_statuses
end

Instance Method Details

#calculate_percent_line(completed_issues) ⇒ Object



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

def calculate_percent_line completed_issues
  times = completed_issues.collect { |issue| issue.board.cycletime.cycletime(issue) }
  index = times.size * 85 / 100
  times.sort[index]
end

#create_datasets(completed_issues) ⇒ Object



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
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 54

def create_datasets completed_issues
  data_sets = []

  groups = group_issues completed_issues

  groups.each_key do |rules|
    completed_issues_by_type = groups[rules]
    label = rules.label
    color = rules.color
    percent_line = calculate_percent_line completed_issues_by_type
    data = completed_issues_by_type.collect { |issue| data_for_issue(issue) }.compact
    data_sets << {
      label: "#{label} (85% at #{label_days(percent_line)})",
      data: data,
      fill: false,
      showLine: false,
      backgroundColor: color
    }

    data_sets << trend_line_data_set(label: label, data: data, color: color)

    @percentage_lines << [percent_line, color]
  end
  data_sets
end

#data_for_issue(issue) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 110

def data_for_issue issue
  cycle_time = issue.board.cycletime.cycletime(issue)
  return nil if cycle_time < 1 # These will get called out on the quality report

  @highest_cycletime = cycle_time if @highest_cycletime < cycle_time

  {
    y: cycle_time,
    x: chart_format(issue.board.cycletime.stopped_time(issue)),
    title: ["#{issue.key} : #{issue.summary} (#{label_days(cycle_time)})"]
  }
end

#runObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 42

def run
  completed_issues = completed_issues_in_range include_unstarted: false

  data_sets = create_datasets completed_issues
  overall_percent_line = calculate_percent_line(completed_issues)
  @percentage_lines << [overall_percent_line, 'gray']

  return "<h1>#{@header_text}</h1>No data matched the selected criteria. Nothing to show." if data_sets.empty?

  wrap_and_render(binding, __FILE__)
end

#show_trend_linesObject



80
81
82
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 80

def show_trend_lines
  @show_trend_lines = true
end

#trend_line_data_set(label:, data:, color:) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 84

def trend_line_data_set label:, data:, color:
  points = data.collect do |hash|
    [Time.parse(hash[:x]).to_i, hash[:y]]
  end

  # The trend calculation works with numbers only so convert Time to an int and back
  calculator = TrendLineCalculator.new(points)
  data_points = calculator.chart_datapoints range: time_range.begin.to_i..time_range.end.to_i, max_y: @highest_cycletime
  data_points.each do |point_hash|
    point_hash[:x] = chart_format Time.at(point_hash[:x])
  end

  {
    type: 'line',
    label: "#{label} Trendline",
    data: data_points,
    fill: false,
    borderWidth: 1,
    markerType: 'none',
    borderColor: color,
    borderDash: [6, 3],
    pointStyle: 'dash',
    hidden: !@show_trend_lines
  }
end