Class: FlowEfficiencyScatterplot

Inherits:
ChartBase show all
Includes:
GroupableIssueChart
Defined in:
lib/jirametrics/flow_efficiency_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?, #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, #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
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 10

def initialize block
  super()

  header_text 'Flow Efficiency'
  description_text "    <div class=\"p\">\n      This chart shows the active time against the the total time spent on a ticket.\n      <a href=\"https://improvingflow.com/2024/07/06/flow-efficiency.html\">Flow  efficiency</a> is the ratio\n      between these two numbers.\n    </div>\n    <div class=\"p\">\n      <math>\n        <mn>Flow efficiency (%)</mn>\n        <mo>=</mo>\n        <mfrac>\n          <mrow><mn>Time adding value</mn></mrow>\n          <mrow><mn>Total time</mn></mrow>\n        </mfrac>\n      </math>\n    </div>\n    <div style=\"background: var(--warning-banner)\">Note that for this calculation to be accurate, we must be moving items into a\n      blocked or stalled state the moment we stop working on it, and most teams don't do that.\n      So be aware that your team may have to change their behaviours if you want this chart to be useful.\n    </div>\n  HTML\n\n  init_configuration_block block do\n    grouping_rules do |issue, rule|\n      active_time, total_time = issue.flow_efficiency_numbers end_time: time_range.end\n      flow_efficiency = active_time * 100.0 / total_time\n\n      if flow_efficiency > 99.0\n        rule.label = '~100%'\n        rule.color = 'green'\n      elsif flow_efficiency < 30.0\n        rule.label = '< 30%'\n        rule.color = 'orange'\n      else\n        rule.label = 'The rest'\n        rule.color = 'black'\n      end\n    end\n  end\n\n  @percentage_lines = []\n  @highest_cycletime = 0\nend\n"

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



72
73
74
75
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
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 72

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



58
59
60
61
62
63
64
65
66
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 58

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

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

  wrap_and_render(binding, __FILE__)
end

#to_days(seconds) ⇒ Object



68
69
70
# File 'lib/jirametrics/flow_efficiency_scatterplot.rb', line 68

def to_days seconds
  seconds / 60 / 60 / 24
end