Skip to content

Instantly share code, notes, and snippets.

@squeejee
Created May 18, 2009 02:58
Show Gist options
  • Save squeejee/113287 to your computer and use it in GitHub Desktop.
Save squeejee/113287 to your computer and use it in GitHub Desktop.
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