The controller threw an error when a start date was not defined because it was

trying to format the string.  In the generate method, we already have logic to
return nil if the start date is not defined, so I added a check in the fetch
method to return nil if the generate method exited with a nil status.
pull/6827/head
Nate Lowrie 15 years ago
parent c320300823
commit 9f971841a7
  1. 32
      app/models/backlog_chart_data.rb

@ -2,7 +2,7 @@ class BacklogChartData < ActiveRecord::Base
unloadable
set_table_name 'backlog_chart_data'
belongs_to :backlog
def self.generate(backlog)
# do not generate if end_date or start_date are not defined
# or if the start date is still in the future
@ -14,7 +14,7 @@ class BacklogChartData < ActiveRecord::Base
scope = Item.sum('points', :conditions => ["items.backlog_id=? AND items.parent_id=0", backlog.id])
done = Item.sum('points', :include => {:issue => :status}, :conditions => ["items.parent_id=0 AND items.backlog_id=? AND issue_statuses.is_closed=?", backlog.id, true])
wip = 0
wip = 0
if data_today.nil?
create :scope => scope, :done => done, :backlog_id => backlog.id, :created_at => Date.today.to_formatted_s(:db)
else
@ -25,49 +25,51 @@ class BacklogChartData < ActiveRecord::Base
end
data_today
end
def self.fetch(options = {})
backlog = Backlog.find(options[:backlog_id])
generate backlog
end_date = backlog.end_date || 30.days.from_now.to_date
if generate(backlog).nil?
return nil
end
end_date = backlog.end_date
data = find_all_by_backlog_id backlog.id, :conditions => ["created_at>=? AND created_at<=?", backlog.start_date.to_formatted_s(:db), end_date.to_formatted_s(:db)], :order => "created_at ASC"
return nil if data.nil? || data.length==0
data_points = (end_date - data.first.created_at.to_date).to_i + 1
scope = []
done = []
done = []
days = []
data.each do |d|
scope << d.scope
done << d.done
days << d.created_at
end
(1..(data_points-days.length)).to_a.each do |i|
days << days.last + 1.day
end
scope = scope.fill(scope.last, scope.length, data_points - scope.length)
speed = (done.last - done.first).to_f / done.length
best = [done.last]
worst = [done.last]
if done.length > 1
while best.last < scope.last && best.last > 0 && (best.length+done.length <= scope.length)
best << (best.last + speed*1.5).round(2)
end
best[best.length-1] = best.last > scope.last ? scope.last : best.last
while worst.last < scope.last && worst.last > 0 && (worst.length+done.length <= scope.length)
worst << (worst.last + speed*0.5).round(2)
end
worst[worst.length-1] = worst.last > scope.last ? scope.last : worst.last
end
{
:days => days,
:scope => scope,

Loading…
Cancel
Save