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, #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) ⇒ 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_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



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

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



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

def create_datasets completed_issues
  data_sets = []

  group_issues(completed_issues).each do |rules, completed_issues_by_type|
    label = rules.label
    color = rules.color
    percent_line = calculate_percent_line completed_issues_by_type
    data = completed_issues_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(issue) ⇒ Object



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

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.started_stopped_times(issue).last),
    title: ["#{issue.key} : #{issue.summary} (#{label_days(cycle_time)})"]
  }
end

#runObject



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

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, 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



76
77
78
# File 'lib/jirametrics/cycletime_scatterplot.rb', line 76

def show_trend_lines
  @show_trend_lines = true
end

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



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

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