<commit_before>class Supply < ApplicationRecord
  resourcify
  has_paper_trail

  has_many :device_supplies
  has_many :devices, through: :device_supplies

  belongs_to :site

  validates :name, presence: true
  validates :vendor, presence: true
  validates :quantity, :threshold, :used, presence: true,
            numericality: { greater_than_or_equal_to: 0, less_than: 2147483648 }

  before_save :add_used_supplies, if: :quantity_changed?, on: :update

  scope :ending_soon, -> { where("quantity <= threshold AND threshold != 0")
                           .order("quantity") }
  scope :all_used, -> { where("used > 0").order("used DESC") }
  scope :most_used, -> { all_used.limit(30) }

  searchkick word_middle: [:name], callbacks: :async

  def search_data
    {
      name: name
    }
  end

  def get_yearly_usage_data(year)
    @supply = self
    @year = year
    @results = {}
    (1..12).each do |month|
      @date = Date.new(@year, month, 1)
      @version = @supply.versions.where(created_at: @date.beginning_of_day .. @date.end_of_day).first
      @results.store(@date.prev_month.strftime("%B"), @version.reify.used) unless @version.nil?
    end
    return @results
  end<commit_msg>Fix a bug where December usage statistics were not available in the yearly report<commit_after>class Supply < ApplicationRecord
  resourcify
  has_paper_trail

  has_many :device_supplies
  has_many :devices, through: :device_supplies

  belongs_to :site

  validates :name, presence: true
  validates :vendor, presence: true
  validates :quantity, :threshold, :used, presence: true,
            numericality: { greater_than_or_equal_to: 0, less_than: 2147483648 }

  before_save :add_used_supplies, if: :quantity_changed?, on: :update

  scope :ending_soon, -> { where("quantity <= threshold AND threshold != 0")
                           .order("quantity") }
  scope :all_used, -> { where("used > 0").order("used DESC") }
  scope :most_used, -> { all_used.limit(30) }

  searchkick word_middle: [:name], callbacks: :async

  def search_data
    {
      name: name
    }
  end

  def get_yearly_usage_data(year)
    @supply = self
    @year = year
    @results = {}
    (1..12).each do |month|
      @date = Date.new(@year, month, 1).next_month
      @version = @supply.versions.where(created_at: @date.beginning_of_day .. @date.end_of_day).first
      @results.store(@date.prev_month.strftime("%B"), @version.reify.used) unless @version.nil?
    end
    return @results
  end
{'fraction_non_alphanumeric': 0.12313282196205087, 'fraction_numerical': 0.015341138473960436, 'mean_word_length': 3.4171122994652405, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6159366', 'n_tokens_mistral': 866, 'n_tokens_neox': 812, 'n_words': 192}