Created
January 17, 2012 14:57
-
-
Save dchapman1988/1626940 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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