Skip to content

Instantly share code, notes, and snippets.

@dchapman1988
Created January 17, 2012 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dchapman1988/1626940 to your computer and use it in GitHub Desktop.
Save dchapman1988/1626940 to your computer and use it in GitHub Desktop.
def project_completion_metric(project)
work_unit_hours_array = Array.new # Empty array to work with
# Take the summation of estimated_hours on a ticket from the project
estimated_hours = Ticket.sum(:estimated_hours, :conditions => ['project_id => ?', project.id])
# Push the work unit hours in if the ticket on the project has estimated hours
WorkUnit.for_project(project).each { |w|
work_unit_hours_array << w.hours if (w.ticket.estimated_hours != nil)
}
# Store the summation of the work unit hours in a proper variable
work_unit_hours = work_unit_hours_array.sum
# Calculatre the projects completion as a percent
percent = (((work_unit_hours / estimated_hours)).to_f * 100.00).round(2) rescue 0
[percent, 100].min # Make sure you don't go over 100 percent and confuse the graphs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment