Project

General

Profile

Defect #4682 » wrong_completed_percent_computation_with_0_time_issues.patch

Etienne Massip, 2011-04-13 20:59

View differences:

app/models/version.rb (working copy)
196 196
  end
197 197
  
198 198
  # Returns the average estimated time of assigned issues
199
  # or 1 if no issue has an estimated time
199
  # or 1 hour if no issue has an estimated time
200 200
  # Used to weigth unestimated issues in progress calculation
201 201
  def estimated_average
202 202
    if @estimated_average.nil?
203
      average = fixed_issues.average(:estimated_hours).to_f
203
      average = fixed_issues.average(:estimated_hours,
204
                        :conditions => 'estimated_hours > 0').to_f
204 205
      if average == 0
205 206
        average = 1
206 207
      end
......
208 209
    end
209 210
    @estimated_average
210 211
  end
211
  
212

  
212 213
  # Returns the total progress of open or closed issues.  The returned percentage takes into account
213 214
  # the amount of estimated time set for this version.
214 215
  #
......
218 219
  def issues_progress(open)
219 220
    @issues_progress ||= {}
220 221
    @issues_progress[open] ||= begin
222

  
223
      todo = estimated_hours + estimated_average * fixed_issues.count(:conditions => { :estimated_hours => nil })
224

  
221 225
      progress = 0
222
      if issues_count > 0
226
      if todo > 0
223 227
        ratio = open ? 'done_ratio' : 100
224
        
228

  
225 229
        done = fixed_issues.sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}",
226 230
                                  :include => :status,
227
                                  :conditions => ["is_closed = ?", !open]).to_f
228
        progress = done / (estimated_average * issues_count)
231
                                  :conditions => ['is_closed = ?', !open]).to_f
232
        progress = done / todo
229 233
      end
230 234
      progress
231 235
    end
test/unit/version_test.rb (working copy)
72 72
    assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_pourcent
73 73
    assert_progress_equal 0, v.closed_pourcent
74 74
  end
75
  
75

  
76
  def test_progress_should_consider_100pct_done_0h_issues_as_completed
77
    project = Project.find(1)
78
    closed = IssueStatus.find(:first, :conditions => {:is_closed => true})
79
    v = Version.create!(:project => project, :name => 'Progress')
80
    add_issue(v, :done_ratio => 100, :estimated_hours => 0, :status => closed)
81
    add_issue(v, :status => closed)
82
    assert_progress_equal 100, v.completed_pourcent
83
    assert_progress_equal 100, v.closed_pourcent
84
  end
85

  
76 86
  def test_progress_should_consider_closed_issues_as_completed
77 87
    project = Project.find(1)
78 88
    v = Version.create!(:project => project, :name => 'Progress')
......
82 92
    assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_pourcent
83 93
    assert_progress_equal (100.0)/3, v.closed_pourcent
84 94
  end
85
  
95

  
86 96
  def test_progress_should_consider_estimated_hours_to_weigth_issues
87 97
    project = Project.find(1)
88 98
    v = Version.create!(:project => project, :name => 'Progress')
99
    add_issue(v, :estimated_hours => 0, :done_ratio => 100)
89 100
    add_issue(v, :estimated_hours => 10)
90 101
    add_issue(v, :estimated_hours => 20, :done_ratio => 30)
91 102
    add_issue(v, :estimated_hours => 40, :done_ratio => 10)
92 103
    add_issue(v, :estimated_hours => 25, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
93
    assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent
104
    assert_progress_equal (0*100.0 + 10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent
94 105
    assert_progress_equal 25.0/95.0*100, v.closed_pourcent
95 106
  end
96
  
107

  
97 108
  def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues
98 109
    project = Project.find(1)
99 110
    v = Version.create!(:project => project, :name => 'Progress')
......
229 240
  end
230 241
  
231 242
  def assert_progress_equal(expected_float, actual_float, message="")
232
    assert_in_delta(expected_float, actual_float, 0.000001, message="")
243
    assert_in_delta(expected_float, actual_float, 0.000001, message)
233 244
  end
234 245
end
(2-2/3)