Skip to content

Instantly share code, notes, and snippets.

@knewter
Forked from dchapman1988/application_helper.rb
Created January 17, 2012 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knewter/1626953 to your computer and use it in GitHub Desktop.
Save knewter/1626953 to your computer and use it in GitHub Desktop.
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