<commit_before>module BestBoy
  class DayReport < ActiveRecord::Base

    # associations
    #
    #

    belongs_to :eventable, polymorphic: true
    belongs_to :month_report

    # validations
    #
    #

    validates :month_report_id, :eventable_type, :event_type, presence: true

    # scopes
    #
    #

    scope :created_on, ->(date) { where(created_at: date.beginning_of_day..date.end_of_day) }
    scope :week,       ->       { where(created_at: Time.zone.now.beginning_of_week..Time.zone.now)   }

    # class methods
    #
    #

    def self.current_for(date, eventable, type, source = nil)
      self.for(eventable, type, source).created_on(date)
    end

    def self.current_or_create_for(eventable, type, source = nil)
      day_report = self.current_for(Time.now, eventable, type, source).last
      day_report.present? ? day_report : self.create_for(eventable, type, source)
    end

    def self.create_for(eventable, type, source = nil)
      month_report = BestBoy::MonthReport.current_or_create_for(eventable, type, source)
      BestBoy::DayReport.create(
        eventable_type:  eventable,
        event_type:      type,
        month_report_id: month_report.to_param,
        event_source:    source
      )
    end

    def self.for(eventable, type, source = nil)
      self.where(eventable_type: eventable, event_type: type, event_source: source)
    end

    def self.daily_occurences_for(eventable, type, source = nil)
      self.created_on(Date.today).for(eventable, type, source).sum(:occurences)
    end

    def self.weekly_occurences_for(eventable, type, source = nil)
      self.week.for(eventable, type, source).sum(:occurences)
    end
  end
end<commit_msg>add date variable for daily occurrences method<commit_after>module BestBoy
  class DayReport < ActiveRecord::Base

    # associations
    #
    #

    belongs_to :eventable, polymorphic: true
    belongs_to :month_report

    # validations
    #
    #

    validates :month_report_id, :eventable_type, :event_type, presence: true

    # scopes
    #
    #

    scope :created_on, ->(date) { where(created_at: date.beginning_of_day..date.end_of_day) }
    scope :week,       ->       { where(created_at: Time.zone.now.beginning_of_week..Time.zone.now)   }

    # class methods
    #
    #

    def self.current_for(date, eventable, type, source = nil)
      self.for(eventable, type, source).created_on(date)
    end

    def self.current_or_create_for(eventable, type, source = nil)
      day_report = self.current_for(Time.now, eventable, type, source).last
      day_report.present? ? day_report : self.create_for(eventable, type, source)
    end

    def self.create_for(eventable, type, source = nil)
      month_report = BestBoy::MonthReport.current_or_create_for(eventable, type, source)
      BestBoy::DayReport.create(
        eventable_type:  eventable,
        event_type:      type,
        month_report_id: month_report.to_param,
        event_source:    source
      )
    end

    def self.for(eventable, type, source = nil)
      self.where(eventable_type: eventable, event_type: type, event_source: source)
    end

    def self.daily_occurences_for(eventable, type, source = nil, date)
      self.created_on(date).for(eventable, type, source).sum(:occurences)
    end

    def self.weekly_occurences_for(eventable, type, source = nil)
      self.week.for(eventable, type, source).sum(:occurences)
    end
  end
end
{'fraction_non_alphanumeric': 0.1020705745115194, 'fraction_numerical': 0.0, 'mean_word_length': 3.097968936678614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1083908', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1120, 'n_words': 222}