Class: ExpeditedChart
- Defined in:
- lib/jirametrics/expedited_chart.rb
Constant Summary collapse
- EXPEDITED_SEGMENT =
Object.new.tap do |segment| def segment.to_json *_args <<~SNIPPET { borderColor: ctx => expedited(ctx, 'red') || notExpedited(ctx, 'gray'), borderDash: ctx => notExpedited(ctx, [6, 6]) } SNIPPET end end
Instance Attribute Summary collapse
-
#cycletime ⇒ Object
Returns the value of attribute cycletime.
-
#date_range ⇒ Object
Returns the value of attribute date_range.
-
#expedited_label ⇒ Object
readonly
Returns the value of attribute expedited_label.
-
#issues ⇒ Object
Returns the value of attribute issues.
-
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
Attributes inherited from ChartBase
#aggregated_project, #all_boards, #board_id, #canvas_height, #canvas_width, #data_quality, #holiday_dates, #settings, #time_range, #timezone_offset
Instance Method Summary collapse
- #find_expedited_issues ⇒ Object
-
#initialize ⇒ ExpeditedChart
constructor
A new instance of ExpeditedChart.
- #later_date(date1, date2) ⇒ Object
- #make_expedite_lines_data_set(issue:, expedite_data:) ⇒ Object
- #make_point(issue:, time:, label:, expedited:) ⇒ Object
- #prepare_expedite_data(issue) ⇒ Object
- #run ⇒ Object
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 ⇒ ExpeditedChart
Returns a new instance of ExpeditedChart.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jirametrics/expedited_chart.rb', line 20 def initialize super() header_text 'Expedited work' description_text <<-HTML <p> This chart only shows issues that have been expedited at some point. We care about these as any form of expedited work will affect the entire system and will slow down non-expedited work. Refer to this article on <a href="https://improvingflow.com/2021/06/16/classes-of-service.html">classes of service</a> for a longer explanation on why we want to avoid expedited work. </p> <p> The lines indicate time that this issue was expedited. When the line is red then the issue was expedited at that time. When it's gray then it wasn't. Orange dots indicate the date the work was started and green dots represent the completion date. Lastly, the vertical height of the lines/dots indicates how long it's been since this issue was created. </p> HTML end |
Instance Attribute Details
#cycletime ⇒ Object
Returns the value of attribute cycletime.
17 18 19 |
# File 'lib/jirametrics/expedited_chart.rb', line 17 def cycletime @cycletime end |
#date_range ⇒ Object
Returns the value of attribute date_range.
17 18 19 |
# File 'lib/jirametrics/expedited_chart.rb', line 17 def date_range @date_range end |
#expedited_label ⇒ Object (readonly)
Returns the value of attribute expedited_label.
18 19 20 |
# File 'lib/jirametrics/expedited_chart.rb', line 18 def expedited_label @expedited_label end |
#issues ⇒ Object
Returns the value of attribute issues.
17 18 19 |
# File 'lib/jirametrics/expedited_chart.rb', line 17 def issues @issues end |
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
17 18 19 |
# File 'lib/jirametrics/expedited_chart.rb', line 17 def possible_statuses @possible_statuses end |
Instance Method Details
#find_expedited_issues ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/jirametrics/expedited_chart.rb', line 82 def find_expedited_issues expedited_issues = @issues.reject do |issue| prepare_expedite_data(issue).empty? end expedited_issues.sort { |a, b| a.key_as_i <=> b.key_as_i } end |
#later_date(date1, date2) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/jirametrics/expedited_chart.rb', line 90 def later_date date1, date2 return date1 if date2.nil? return date2 if date1.nil? [date1, date2].max end |
#make_expedite_lines_data_set(issue:, expedite_data:) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/jirametrics/expedited_chart.rb', line 106 def make_expedite_lines_data_set issue:, expedite_data: cycletime = issue.board.cycletime started_time = cycletime.started_time(issue) stopped_time = cycletime.stopped_time(issue) expedite_data << [started_time, :issue_started] if started_time expedite_data << [stopped_time, :issue_stopped] if stopped_time expedite_data.sort! { |a, b| a[0] <=> b[0] } # If none of the data would be visible on the chart then skip it. return nil unless expedite_data.any? { |time, _action| time.to_date >= date_range.begin } data = [] dot_colors = [] point_styles = [] expedited = false expedite_data.each do |time, action| case action when :issue_started data << make_point(issue: issue, time: time, label: 'Started', expedited: expedited) dot_colors << 'orange' point_styles << 'rect' when :issue_stopped data << make_point(issue: issue, time: time, label: 'Completed', expedited: expedited) dot_colors << 'green' point_styles << 'rect' when :expedite_start data << make_point(issue: issue, time: time, label: 'Expedited', expedited: true) dot_colors << 'red' point_styles << 'circle' expedited = true when :expedite_stop data << make_point(issue: issue, time: time, label: 'Not expedited', expedited: false) dot_colors << 'gray' point_styles << 'circle' expedited = false else raise "Unexpected action: #{action}" end end unless expedite_data.empty? last_change_time = expedite_data[-1][0].to_date if last_change_time && last_change_time <= date_range.end && stopped_time.nil? data << make_point(issue: issue, time: date_range.end, label: 'Still ongoing', expedited: expedited) dot_colors << 'blue' # It won't be visible so it doesn't matter point_styles << 'dash' end end { type: 'line', label: issue.key, data: data, fill: false, showLine: true, backgroundColor: dot_colors, pointBorderColor: 'black', pointStyle: point_styles, segment: EXPEDITED_SEGMENT } end |
#make_point(issue:, time:, label:, expedited:) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/jirametrics/expedited_chart.rb', line 97 def make_point issue:, time:, label:, expedited: { y: (time.to_date - issue.created.to_date).to_i + 1, x: time.to_date.to_s, title: ["#{issue.key} #{label} : #{issue.summary}"], expedited: (expedited ? 1 : 0) } end |
#prepare_expedite_data(issue) ⇒ Object
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 |
# File 'lib/jirametrics/expedited_chart.rb', line 53 def prepare_expedite_data issue expedite_start = nil result = [] expedited_priority_names = issue.board.expedited_priority_names issue.changes.each do |change| next unless change.priority? if expedited_priority_names.include? change.value expedite_start = change.time elsif expedite_start start_date = expedite_start.to_date stop_date = change.time.to_date if date_range.include?(start_date) || date_range.include?(stop_date) || (start_date < date_range.begin && stop_date > date_range.end) result << [expedite_start, :expedite_start] result << [change.time, :expedite_stop] end expedite_start = nil end end # If expedite_start is still set then we never ended. result << [expedite_start, :expedite_start] if expedite_start result end |
#run ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jirametrics/expedited_chart.rb', line 41 def run data_sets = find_expedited_issues.collect do |issue| make_expedite_lines_data_set(issue: issue, expedite_data: prepare_expedite_data(issue)) end.compact if data_sets.empty? '<h1>Expedited work</h1>There is no expedited work in this time period.' else wrap_and_render(binding, __FILE__) end end |