Created
May 18, 2009 02:58
-
-
Save squeejee/113287 to your computer and use it in GitHub Desktop.
This file contains 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 Entry < ActiveRecord::Base | |
named_scope :by_date, lambda { |*args| | |
{ | |
:order => "starts_at asc", | |
:conditions => ["starts_at BETWEEN ? AND ?", args[0].beginning_of_day.to_s(:db), (args[1]||Time.now).end_of_day.to_s(:db)] | |
} } do | |
def duration_by_project_per_weekday | |
from_date = DateTime.parse(self.proxy_options[:conditions][1]) | |
to_date = DateTime.parse(self.proxy_options[:conditions][2]) | |
weekday_count = weekday_count(from_date, to_date) | |
totals = self.sum(:duration, :group => :project) | |
totals.map {|a| [a[0].display_name, ( a[1].to_f / weekday_count)]} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment