-
-
Save knewter/1626953 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
class WorkUnit | |
scope :on_estimated_ticket, lambda{ include(:ticket).where("tickets.estimated_hours IS NOT NULL AND tickets.estimated_hours > 0") } | |
end | |
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.for_project(project).sum(:estimated_hours) | |
# Push the work unit hours in if the ticket on the project has estimated hours | |
work_unit_hours = WorkUnit.for_project(project).on_estimated_ticket.sum(:hours) | |
# 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