<commit_before>class Project < ActiveRecord::Base
  include StaffPlan::AuditMethods
  has_paper_trail

  attr_accessible :name, :active

  belongs_to  :client
  belongs_to  :company

  has_many :work_weeks, dependent: :destroy do
    def for_user(user)
      self.select { |ww| ww.user_id == user.id }
    end

    def for_user_and_cweek_and_year(user, cweek, year)
      self.for_user(user).detect { |ww| ww.cweek == cweek && ww.year == year }
    end
  end

  has_many :assignments, :dependent => :destroy
  has_many :users, :through => :assignments


  after_update :update_originator_timestamp

  validates_presence_of :name, :client
  validates_uniqueness_of :name, case_sensitive: false, scope: :client_id

  default_scope(order: "client_id ASC, name ASC")


  def work_week_totals_for_date_range(lower, upper)
    {}.tap do |grouped|
      WorkWeek.for_project_and_date_range(self, lower, upper).group_by(&:year).each do |year, weeks|
        totals = {}.tap do |totals| 
          weeks.group_by(&:cweek).each do |iso_week, weeks| 
            totals.store(iso_week, weeks.inject(0) do |total, week|
              total = total + (week.send((Date.today.cweek >= iso_week) ? :actual_hours : :estimated_hours) || 0)
              total
            end)
          end
        end<commit_msg>Now counting proposed hours aside for bar graph<commit_after>class Project < ActiveRecord::Base
  include StaffPlan::AuditMethods
  has_paper_trail

  attr_accessible :name, :active

  belongs_to  :client
  belongs_to  :company

  has_many :work_weeks, dependent: :destroy do
    def for_user(user)
      self.select { |ww| ww.user_id == user.id }
    end

    def for_user_and_cweek_and_year(user, cweek, year)
      self.for_user(user).detect { |ww| ww.cweek == cweek && ww.year == year }
    end
  end

  has_many :assignments, :dependent => :destroy
  has_many :users, :through => :assignments


  after_update :update_originator_timestamp

  validates_presence_of :name, :client
  validates_uniqueness_of :name, case_sensitive: false, scope: :client_id

  default_scope(order: "client_id ASC, name ASC")


  def work_week_totals_for_date_range(lower, upper)
    {}.tap do |grouped|
      WorkWeek.for_project_and_date_range(self, lower, upper).group_by(&:year).each do |year, weeks|
        totals = {}.tap do |totals| 
          weeks.group_by(&:cweek).each do |iso_week, weeks| 
            totals.store(iso_week, weeks.inject({:proposed => 0, :actuals => 0}) do |total, week|
              total[week.proposed? ? :proposed : :actuals] += (week.send((Date.today.cweek >= iso_week) ? :actual_hours : :estimated_hours) || 0)
              total
            end)
          end
        end
{'fraction_non_alphanumeric': 0.11197916666666667, 'fraction_numerical': 0.0018601190476190475, 'mean_word_length': 3.337096774193548, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1962078', 'n_tokens_mistral': 949, 'n_tokens_neox': 900, 'n_words': 204}