Class: Backlogs::Statistics

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Statistics) initialize(project)

A new instance of Statistics



5
6
7
8
9
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
# File 'lib/backlogs_project_patch.rb', line 5

def initialize(project)
  @project = project
  @statistics = {:succeeded => [], :failed => [], :values => {}}

  @active_sprint = RbSprint.find(:first, :conditions => ["project_id = ? and status = 'open' and ? between sprint_start_date and effective_date", @project.id, Date.today])
  @past_sprints = RbSprint.find(:all,
    :conditions => ["project_id = ? and not(effective_date is null or sprint_start_date is null) and effective_date < ?", @project.id, Date.today],
    :order => "effective_date desc",
    :limit => 5)

  @points_per_day = @past_sprints.collect{|s| s.burndown('up')[:points_committed][0]}.compact.sum / @past_sprints.collect{|s| s.days(:all).size}.compact.sum if @past_sprints.size > 0

  @all_sprints = (@past_sprints + [@active_sprint]).compact

  if @all_sprints.size != 0
    @velocity = @past_sprints.collect{|sprint| sprint.burndown('up')[:points_accepted][-1]}
    @velocity_stddev = stddev(@velocity)
  end

  @product_backlog = RbStory.product_backlog(@project, 10)

  hours_per_point = []
  @all_sprints.each {|sprint|
    sprint.stories.each {|story|
      bd = story.burndown
      h = bd[:hours][0]
      p = bd[:points][0]
      next unless h && p && p != 0
      hours_per_point << (h / p.to_f)
    }
  }
  @hours_per_point_stddev = stddev(hours_per_point)
  @hours_per_point = hours_per_point.sum.to_f / hours_per_point.size unless hours_per_point.size == 0

  Statistics.active_tests.sort.each{|m|
    r = send(m.intern)
    next if r.nil? # this test deems itself irrelevant
    m.gsub!(/^test_/, '')
    @statistics[r ? :succeeded : :failed] << (m.gsub(/^test_/, '') + (r ? '' : '_failed'))
  }
  Statistics.stats.sort.each{|m|
    v = send(m.intern)
    @statistics[:values][m.gsub(/^stat_/, '')] = v unless v.nil? || (v.respond_to?(:nan?") && v.nan?) || (v.respond_to?(:infinite?") && v.infinite?)
  }

  if @statistics[:succeeded].size == 0 && @statistics[:failed].size == 0
    @score = 100 # ?
  else
    @score = (@statistics[:succeeded].size * 100) / (@statistics[:succeeded].size + @statistics[:failed].size)
  end
end

Instance Attribute Details

- (Object) active_sprint (readonly)

Returns the value of attribute active_sprint



58
59
60
# File 'lib/backlogs_project_patch.rb', line 58

def active_sprint
  @active_sprint
end

- (Object) hours_per_point (readonly)

Returns the value of attribute hours_per_point



59
60
61
# File 'lib/backlogs_project_patch.rb', line 59

def hours_per_point
  @hours_per_point
end

- (Object) past_sprints (readonly)

Returns the value of attribute past_sprints



58
59
60
# File 'lib/backlogs_project_patch.rb', line 58

def past_sprints
  @past_sprints
end

- (Object) score (readonly)

Returns the value of attribute score



57
58
59
# File 'lib/backlogs_project_patch.rb', line 57

def score
  @score
end

- (Object) statistics (readonly)

Returns the value of attribute statistics



57
58
59
# File 'lib/backlogs_project_patch.rb', line 57

def statistics
  @statistics
end

Class Method Details

+ (Object) active



76
77
78
# File 'lib/backlogs_project_patch.rb', line 76

def self.active
  return Statistics.active_tests.collect{|m| m.split('_', 2).collect{|s| s.intern}}
end

+ (Object) active_tests



71
72
73
74
# File 'lib/backlogs_project_patch.rb', line 71

def self.active_tests
  # test this!
  return Statistics.instance_methods.select{|m| m =~ /^test_/}.reject{|m| Backlogs.setting["disable_stats_#{m}".intern] }
end

+ (Object) available



67
68
69
# File 'lib/backlogs_project_patch.rb', line 67

def self.available
  return Statistics.instance_methods.select{|m| m =~ /^test_/}.collect{|m| m.split('_', 2).collect{|s| s.intern}}
end

+ (Object) stats



80
81
82
# File 'lib/backlogs_project_patch.rb', line 80

def self.stats
  return Statistics.instance_methods.select{|m| m =~ /^stat_/}
end

Instance Method Details

- (Object) info_no_active_sprint



84
85
86
# File 'lib/backlogs_project_patch.rb', line 84

def info_no_active_sprint
  return !@active_sprint
end

- (Object) stat_hours_per_point



151
152
153
# File 'lib/backlogs_project_patch.rb', line 151

def stat_hours_per_point
  return @hours_per_point
end

- (Object) stat_sizing_stddev



147
148
149
# File 'lib/backlogs_project_patch.rb', line 147

def stat_sizing_stddev
  return @hours_per_point_stddev
end

- (Object) stat_sprints



134
135
136
# File 'lib/backlogs_project_patch.rb', line 134

def stat_sprints
  return @past_sprints.size
end

- (Object) stat_velocity



138
139
140
141
# File 'lib/backlogs_project_patch.rb', line 138

def stat_velocity
  return nil unless @velocity && @velocity.size > 0
  return @velocity.sum / @velocity.size
end

- (Object) stat_velocity_stddev



143
144
145
# File 'lib/backlogs_project_patch.rb', line 143

def stat_velocity_stddev
  return @velocity_stddev
end

- (Object) stddev(values)



61
62
63
64
65
# File 'lib/backlogs_project_patch.rb', line 61

def stddev(values)
  median = values.sum / values.size.to_f
  variance = 1.0 / (values.size * values.inject(0){|acc, v| acc + (v-median)**2})
  return Math.sqrt(variance)
end

- (Object) test_active



108
109
110
# File 'lib/backlogs_project_patch.rb', line 108

def test_active
  return (@project.status != Project::STATUS_ACTIVE || (@active_sprint && @active_sprint.activity))
end

- (Object) test_committed_velocity_stable



126
127
128
# File 'lib/backlogs_project_patch.rb', line 126

def test_committed_velocity_stable
  return (@velocity_stddev && @velocity_stddev < 4) # magic number!
end

- (Object) test_product_backlog_filled



88
89
90
# File 'lib/backlogs_project_patch.rb', line 88

def test_product_backlog_filled
  return (@project.status != Project::STATUS_ACTIVE || @product_backlog.length != 0)
end

- (Object) test_product_backlog_sized



92
93
94
# File 'lib/backlogs_project_patch.rb', line 92

def test_product_backlog_sized
  return !@product_backlog.detect{|s| s.story_points.blank? }
end

- (Object) test_sizing_consistent



130
131
132
# File 'lib/backlogs_project_patch.rb', line 130

def test_sizing_consistent
  return (@hours_per_point_stddev < 4) # magic number
end

- (Object) test_sprint_notes_available



104
105
106
# File 'lib/backlogs_project_patch.rb', line 104

def test_sprint_notes_available
  return !@past_sprints.detect{|s| !s.has_wiki_page}
end

- (Object) test_sprints_estimated



100
101
102
# File 'lib/backlogs_project_patch.rb', line 100

def test_sprints_estimated
  return !Issue.exists?(["estimated_hours is null and fixed_version_id in (?) and tracker_id = ?", @all_sprints.collect{|s| s.id}, RbTask.tracker])
end

- (Object) test_sprints_sized



96
97
98
# File 'lib/backlogs_project_patch.rb', line 96

def test_sprints_sized
  return !Issue.exists?(["story_points is null and fixed_version_id in (?) and tracker_id in (?)", @all_sprints.collect{|s| s.id}, RbStory.trackers])
end

- (Object) test_yield



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/backlogs_project_patch.rb', line 112

def test_yield
  accepted = []
  @past_sprints.each {|sprint|
    bd = sprint.burndown('up')
    c = bd[:points_committed][-1]
    a = bd[:points_accepted][-1]
    next unless c && a && c != 0

    accepted << [(a * 100.0) / c, 100.0].min
  }
  return false if accepted == []
  return (stddev(accepted) < 10) # magic number
end