Class: FlowEfficiencyCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/jirametrics/flow_efficiency_calculator.rb

Overview

Walks a stream of BlockedStalledChange entries and totals up the value-add (active) time between issue_start and end_time. It's handed the already-computed stream and the resolved start/end so it never reaches back through the issue's collaborators.

Returns [value_add_seconds, total_seconds].

Instance Method Summary collapse

Constructor Details

#initialize(blocked_stalled_changes:, issue_start:, end_time:) ⇒ FlowEfficiencyCalculator

Returns a new instance of FlowEfficiencyCalculator.



9
10
11
12
13
# File 'lib/jirametrics/flow_efficiency_calculator.rb', line 9

def initialize blocked_stalled_changes:, issue_start:, end_time:
  @blocked_stalled_changes = blocked_stalled_changes
  @issue_start = issue_start
  @end_time = end_time
end

Instance Method Details

#calculateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jirametrics/flow_efficiency_calculator.rb', line 15

def calculate
  @active_start = nil
  @value_add_time = 0.0

  @blocked_stalled_changes.each_with_index do |change, index|
    break if change.time > @end_time

    process change, index
  end

  close_final_active_period

  [@value_add_time, @end_time - @issue_start]
end

#close_final_active_periodObject



56
57
58
59
60
61
# File 'lib/jirametrics/flow_efficiency_calculator.rb', line 56

def close_final_active_period
  return unless @active_start

  change_delta = @end_time - [@issue_start, @active_start].max
  @value_add_time += change_delta if change_delta.positive?
end

#process(change, index) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/jirametrics/flow_efficiency_calculator.rb', line 30

def process change, index
  if index.zero?
    @active_start = change.time if change.active?
    return
  end

  process_transition change
end

#process_transition(change) ⇒ Object



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

def process_transition change
  # Already active and we just got another active.
  return if @active_start && change.active?

  if change.active?
    @active_start = change.time
  elsif @active_start && change.time >= @issue_start
    # Not active now but we have been. Record the active time.
    record_active_period ending_at: change.time
    @active_start = nil
  end
end

#record_active_period(ending_at:) ⇒ Object



52
53
54
# File 'lib/jirametrics/flow_efficiency_calculator.rb', line 52

def record_active_period ending_at:
  @value_add_time += ending_at - [@issue_start, @active_start].max
end