Class: ExpeditedChart
- Defined in:
- lib/jirametrics/expedited_chart.rb
Constant Summary collapse
- EXPEDITED_SEGMENT =
ChartBase.new.tap do |segment| def segment.to_json *_args expedited = CssVariable.new('--expedited-color').to_json not_expedited = CssVariable.new('--expedited-chart-no-longer-expedited').to_json <<~SNIPPET { borderColor: ctx => expedited(ctx, #{expedited}) || notExpedited(ctx, #{not_expedited}), borderDash: ctx => notExpedited(ctx, [6, 6]) } SNIPPET end end
Constants inherited from ChartBase
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, #atlassian_document_format, #board_id, #canvas_height, #canvas_width, #data_quality, #file_system, #fix_versions, #holiday_dates, #settings, #time_range, #timezone_offset, #x_axis_title, #y_axis_title
Instance Method Summary collapse
- #find_expedited_issues ⇒ Object
-
#initialize(block) ⇒ 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?, #before_run, #call_before_run, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_block, #color_for, #completed_issues_in_range, #current_board, #cycletime_for_issue, #daily_chart_dataset, #date_annotation, #describe_non_working_days, #description_text, #format_integer, #format_status, #header_text, #holidays, #html_directory, #icon_span, #label_days, #label_hours, #label_issues, #label_minutes, #link_to_issue, #next_id, #normalize_annotation_datetime, #not_visible_text, #random_color, #render, #render_axis_title, #render_top_text, #seam_end, #seam_start, #stagger_label_positions, #status_category_color, #to_human_readable, #working_days_annotation, #wrap_and_render
Constructor Details
#initialize(block) ⇒ ExpeditedChart
Returns a new instance of ExpeditedChart.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jirametrics/expedited_chart.rb', line 23 def initialize block super() header_text 'Expedited work' description_text <<-HTML <div class="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. </div> <div class="p"> The colour of the line indicates time that this issue was #{color_block '--expedited-color'} expedited or #{color_block '--expedited-chart-no-longer-expedited'} not expedited. </div> #{describe_non_working_days} HTML @x_axis_title = 'Date' @y_axis_title = 'Age in days' instance_eval(&block) end |
Instance Attribute Details
#cycletime ⇒ Object
Returns the value of attribute cycletime.
20 21 22 |
# File 'lib/jirametrics/expedited_chart.rb', line 20 def cycletime @cycletime end |
#date_range ⇒ Object
Returns the value of attribute date_range.
20 21 22 |
# File 'lib/jirametrics/expedited_chart.rb', line 20 def date_range @date_range end |
#expedited_label ⇒ Object (readonly)
Returns the value of attribute expedited_label.
21 22 23 |
# File 'lib/jirametrics/expedited_chart.rb', line 21 def expedited_label @expedited_label end |
#issues ⇒ Object
Returns the value of attribute issues.
20 21 22 |
# File 'lib/jirametrics/expedited_chart.rb', line 20 def issues @issues end |
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
20 21 22 |
# File 'lib/jirametrics/expedited_chart.rb', line 20 def possible_statuses @possible_statuses end |
Instance Method Details
#find_expedited_issues ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/jirametrics/expedited_chart.rb', line 88 def find_expedited_issues expedited_issues = @issues.reject do |issue| prepare_expedite_data(issue).empty? end expedited_issues.sort_by(&:key_as_i) end |
#later_date(date1, date2) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/jirametrics/expedited_chart.rb', line 96 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
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 169 170 171 172 173 |
# File 'lib/jirametrics/expedited_chart.rb', line 112 def make_expedite_lines_data_set issue:, expedite_data: cycletime = issue.board.cycletime started_date, stopped_date = cycletime.started_stopped_dates(issue) expedite_data << [started_date, :issue_started] if started_date expedite_data << [stopped_date, :issue_stopped] if stopped_date expedite_data.sort_by!(&:first) # 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 << CssVariable['--expedited-chart-dot-issue-started-color'] point_styles << 'rect' when :issue_stopped data << make_point(issue: issue, time: time, label: 'Completed', expedited: expedited) dot_colors << CssVariable['--expedited-chart-dot-issue-stopped-color'] point_styles << 'rect' when :expedite_start data << make_point(issue: issue, time: time, label: 'Expedited', expedited: true) dot_colors << CssVariable['--expedited-chart-dot-expedite-started-color'] point_styles << 'circle' expedited = true when :expedite_stop data << make_point(issue: issue, time: time, label: 'Not expedited', expedited: false) dot_colors << CssVariable['--expedited-chart-dot-expedite-stopped-color'] 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_date.nil? data << make_point(issue: issue, time: date_range.end, label: 'Still ongoing', expedited: expedited) dot_colors << '' # 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
103 104 105 106 107 108 109 110 |
# File 'lib/jirametrics/expedited_chart.rb', line 103 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
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 |
# File 'lib/jirametrics/expedited_chart.rb', line 59 def prepare_expedite_data issue expedite_start = nil result = [] expedited_priority_names = issue.board.project_config.settings['expedited_priority_names'] issue.changes.each do |change| next unless change.priority? if expedited_priority_names.include? change.value expedite_start = change.time.to_date 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.to_date, :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
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jirametrics/expedited_chart.rb', line 47 def run data_sets = find_expedited_issues.filter_map do |issue| make_expedite_lines_data_set(issue: issue, expedite_data: prepare_expedite_data(issue)) end if data_sets.empty? '<h1 class="foldable">Expedited work</h1><div>There is no expedited work in this time period.</div>' else wrap_and_render(binding, __FILE__) end end |