<commit_before>module BookingbugYellowfin
  class PersonCapacityUsage < ActiveRecord::Base

    attr_accessible :person_id, :date, :total_time_hrs, :time_booked_hrs, :time_blocked_hrs, :yf_format_date

    def self.populate_all_capacity_usage
      failed_imports = []
      p 'populate all historic capacity usage'
      $stdout.sync = true
      for company in Company.where("cancelled != ? and template is null or template = ?", true, false)
        print '.'
        (::Date.today - 4.weeks).to_date.upto(::Date.today) do |date|
          begin
            add_person_capacity_for_company company.id, date
          rescue
            failed_imports << [date, company.id]
          end
        end
      end
      p 'failed_imports **********'
      p failed_imports
      return true
    end

    def self.amend_yesterdays_capacity_usage
      failed_imports = []
      p 'amend_yesterdays_capacity_usage'
      $stdout.sync = true
      Company.find_each() do |company|
        print '.'
        begin
          add_person_capacity_for_company company.id, 1.day.ago.to_date
        rescue
          failed_imports << company.id
        end
      end
      p 'failed_imports **********'
      p failed_imports
      return true
    end

    # BookingbugYellowfin::PersonCapacityUsage.add_person_capacity_for_company c, date
    def self.add_person_capacity_for_company company_id, date = ::Date.yesterday
      for person in Person.where(company_id: company_id, deleted: false, disabled: false)
        booked_time = 0
        blocked_time = 0
        next if person.schedule.blank?
        p 'person'
        p person
        total_time = person.schedule.total_time_available_for_date(date)
        total_time = total_time/60.0 #Convert to hours
        booked_slots = Slot.where(person_id: person.id, date: date, status: Slot::BOOKING_BOOKED)
        for slot in booked_slots
          booked_time += slot.ilen*5
        end
        blocked_slots = Slot.where(person_id: person.id, date: date, status: Slot::BOOKING_BLOCKED)
        for slot in blocked_slots
          if slot.slot_type == Schedule::DAY && slot.ilen == 1
            blocked_time += (total_time * 60)
          else
            blocked_time += slot.ilen*5
          end
        end<commit_msg>BOOK-509 remove comments<commit_after>module BookingbugYellowfin
  class PersonCapacityUsage < ActiveRecord::Base

    attr_accessible :person_id, :date, :total_time_hrs, :time_booked_hrs, :time_blocked_hrs, :yf_format_date

    def self.populate_all_capacity_usage
      failed_imports = []
      p 'populate all historic capacity usage'
      $stdout.sync = true
      for company in Company.where("cancelled != ? and template is null or template = ?", true, false)
        print '.'
        (::Date.today - 4.weeks).to_date.upto(::Date.today) do |date|
          begin
            add_person_capacity_for_company company.id, date
          rescue
            failed_imports << [date, company.id]
          end
        end
      end
      p 'failed_imports **********'
      p failed_imports
      return true
    end

    def self.amend_yesterdays_capacity_usage
      failed_imports = []
      p 'amend_yesterdays_capacity_usage'
      $stdout.sync = true
      Company.find_each() do |company|
        print '.'
        begin
          add_person_capacity_for_company company.id, 1.day.ago.to_date
        rescue
          failed_imports << company.id
        end
      end
      p 'failed_imports **********'
      p failed_imports
      return true
    end

    # BookingbugYellowfin::PersonCapacityUsage.add_person_capacity_for_company c, date
    def self.add_person_capacity_for_company company_id, date = ::Date.yesterday
      for person in Person.where(company_id: company_id, deleted: false, disabled: false)
        booked_time = 0
        blocked_time = 0
        next if person.schedule.blank?
        total_time = person.schedule.total_time_available_for_date(date)
        total_time = total_time/60.0 #Convert to hours
        booked_slots = Slot.where(person_id: person.id, date: date, status: Slot::BOOKING_BOOKED)
        for slot in booked_slots
          booked_time += slot.ilen*5
        end
        blocked_slots = Slot.where(person_id: person.id, date: date, status: Slot::BOOKING_BLOCKED)
        for slot in blocked_slots
          if slot.slot_type == Schedule::DAY && slot.ilen == 1
            blocked_time += (total_time * 60)
          else
            blocked_time += slot.ilen*5
          end
        end
{'fraction_non_alphanumeric': 0.086715457972943, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 2.4427480916030535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '933074', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1381, 'n_words': 313}