Class: FlowEfficiencyScatterplot

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

Constant Summary

Constants inherited from ChartBase

ChartBase::LABEL_POSITIONS

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, #fix_versions, #holiday_dates, #issues, #settings, #time_range, #timezone_offset, #x_axis_title, #y_axis_title

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

Returns a new instance of FlowEfficiencyScatterplot.



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 10

def initialize block
  super()

  header_text 'Flow Efficiency'
  description_text <<-HTML
    <div class="p">
      This chart shows the active time against the the total time spent on a ticket.
      <a href="https://improvingflow.com/2024/07/06/flow-efficiency.html">Flow  efficiency</a> is the ratio
      between these two numbers.
    </div>
    <div class="p">
      <math>
        <mn>Flow efficiency (%)</mn>
        <mo>=</mo>
        <mfrac>
          <mrow><mn>Time adding value</mn></mrow>
          <mrow><mn>Total time</mn></mrow>
        </mfrac>
      </math>
    </div>
    <div style="background: var(--warning-banner)">Note that for this calculation to be accurate, we must be moving items into a
      blocked or stalled state the moment we stop working on it, and most teams don't do that.
      So be aware that your team may have to change their behaviours if you want this chart to be useful.
    </div>
  HTML
  @x_axis_title = 'Total time (days)'
  @y_axis_title = 'Time adding value (days)'

  init_configuration_block block do
    grouping_rules do |issue, rule|
      active_time, total_time = issue.flow_efficiency_numbers end_time: time_range.end
      flow_efficiency = active_time * 100.0 / total_time

      if flow_efficiency > 99.0
        rule.label = '~100%'
        rule.color = 'green'
      elsif flow_efficiency < 30.0
        rule.label = '< 30%'
        rule.color = 'orange'
      else
        rule.label = 'The rest'
        rule.color = 'black'
      end
    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/flow_efficiency_scatterplot.rb', line 8

def possible_statuses
  @possible_statuses
end

Instance Method Details

#create_dataset(issues:, label:, color:) ⇒ Object



76
77
78
79
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
108
109
110
111
112
113
114
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 76

def create_dataset issues:, label:, color:
  return nil if issues.empty?

  data = issues.filter_map do |issue|
    active_time, total_time = issue.flow_efficiency_numbers(
      end_time: time_range.end, settings: settings
    )

    active_days = to_days(active_time)
    total_days = to_days(total_time)
    flow_efficiency = active_time * 100.0 / total_time

    if flow_efficiency.nan?
      # If this happens then something is probably misconfigured. We've seen it in production though
      # so we have to handle it.
      file_system.log(
        "Issue(#{issue.key}) flow_efficiency: NaN, active_time: #{active_time}, total_time: #{total_time}"
      )
      flow_efficiency = 0.0
    end

    {
      y: active_days,
      x: total_days,
      title: [
        "#{issue.key} : #{issue.summary}, flow efficiency: #{flow_efficiency.to_i}%," \
        " total: #{total_days.round(1)} days," \
        " active: #{active_days.round(1)} days"
      ]
    }
  end
  {
    label: label,
    data: data,
    fill: false,
    showLine: false,
    backgroundColor: color
  }
end

#runObject



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

def run
  data_sets = group_issues(completed_issues_in_range include_unstarted: false).filter_map do |rules, issues|
    create_dataset(issues: issues, label: rules.label, color: rules.color)
  end

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

  wrap_and_render(binding, __FILE__)
end

#to_days(seconds) ⇒ Object



72
73
74
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 72

def to_days seconds
  seconds / 60 / 60 / 24
end