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, #atlassian_document_format, #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?, #before_run, #call_before_run, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_block, #color_for, #completed_issues_in_range, #current_board, #cycletime, #cycletime_for_issue, #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, #seam_end, #seam_start, #status_category_color, #working_days_annotation, #wrap_and_render

Constructor Details

#initialize(block) ⇒ 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
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 10

def initialize block
  super()

  header_text 'Cycletime Scatterplot'
  description_text <<-HTML
    <div class="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.
    </div>
    <div class="p">
      The #{color_block '--cycletime-scatterplot-overall-trendline-color'} 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.
    </div>
    #{describe_non_working_days}
  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_y_value = 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

#all_itemsObject



41
42
43
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 41

def all_items
  completed_issues_in_range include_unstarted: false
end

#calculate_percent_line(items) ⇒ Object



141
142
143
144
145
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 141

def calculate_percent_line items
  times = items.collect { |item| y_value(item) }
  index = times.size * 85 / 100
  times.sort[index]
end

#create_datasets(items) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 72

def create_datasets items
  data_sets = []

  group_issues(items).each do |rules, completed_items_by_type|
    label = rules.label
    color = rules.color
    percent_line = calculate_percent_line completed_items_by_type
    data = completed_items_by_type.filter_map { |issue| data_for_issue(issue) }
    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(item) ⇒ Object



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

def data_for_issue item
  cycle_time = y_value(item)
  return nil if cycle_time < 1 # These will get called out on the quality report

  @highest_y_value = cycle_time if @highest_y_value < cycle_time

  {
    y: cycle_time,
    x: chart_format(x_value(item)),
    title: [title_value(item)]
  }
end

#runObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 61

def run
  items = all_items
  data_sets = create_datasets items
  overall_percent_line = calculate_percent_line(items)
  @percentage_lines << [overall_percent_line, CssVariable['--cycletime-scatterplot-overall-trendline-color']]

  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



95
96
97
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 95

def show_trend_lines
  @show_trend_lines = true
end

#title_value(item) ⇒ Object



53
54
55
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 53

def title_value item
  "#{item.key} : #{item.summary} (#{label_days(y_value(item))})"
end

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 99

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_y_value
  )
  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

#x_value(item) ⇒ Object



45
46
47
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 45

def x_value item
  item.board.cycletime.started_stopped_times(item).last
end

#y_axis_headingObject



57
58
59
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 57

def y_axis_heading
  'Cycle time in days'
end

#y_value(item) ⇒ Object



49
50
51
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 49

def y_value item
  item.board.cycletime.cycletime(item)
end