1
2
3
4
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
def backlog_graph

  @project = Project.find(params[:id], :include => {:assignments => :employee})
  @assignments = @project.assignments.collect
        #cool, so right now we have the project and all of its assignments.  Let's create an array that holds each day's value (initialized to 0)

  backlog = Array.new(((@project.end_date - @project.start_date).to_i), 0)  

        #the first value in the array will be the full value of the project
  burn_carry = @project.mswa_value
  backlog[0] = burn_carry
  i = 1

        #now we'll iterate through each day and collect every assignment's data, if the assignment is active during that day

  backlog.each do |day|
    day_burn = 0  #day's total burn
    current_day = @project.start_date.advance(:days => i) 

    @assignments.each do |assignment| 
      if (assignment.start_date..assignment.end_date).to_a.include?(current_day){
      day_burn += assignment.daily_burn # we're adding the cost of that assignment (which is returned by the daily_burn method in the assignment model)
      }

      backlog[i] = burn_carry-day_burn
                       burn_carry = backlog[i] #this value will be used by the next iteration to decrease the total backlog

      i = i + 1
    end
    end
  end

backlog is then used to feed the graphing utility