<commit_before># = Informations
#
# == License
#
# Ekylibre - Simple agricultural ERP
# Copyright (C) 2008-2009 <NAME>, <NAME>
# Copyright (C) 2010-2012 <NAME>
# Copyright (C) 2012-2016 <NAME>, <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see http://www.gnu.org/licenses.
#
# == Table: product_populations
#
#  created_at   :datetime
#  creator_id   :integer
#  id           :integer
#  lock_version :integer
#  product_id   :integer
#  started_at   :datetime
#  updated_at   :datetime
#  updater_id   :integer
#  value        :decimal(, )
#

# Sum of all the deltas in product movements up to and including a date.
class ProductPopulation < Ekylibre::Record::Base
  belongs_to :product
  # [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
  validates :id, numericality: { only_integer: true, greater_than: -2_147_483_649, less_than: 2_147_483_648 }, allow_blank: true
  validates :started_at, timeliness: { on_or_after: -> { Time.new(1, 1, 1).in_time_zone }, on_or_before: -> { Time.zone.now + 50.years } }, allow_blank: true
  validates :value, numericality: true, allow_blank: true
  # ]VALIDATORS]

  scope :chain,                   ->(product) { where(product: product).order(started_at: :asc) }
  scope :initial_population_for,  ->(product) { chain(product).first }
  scope :at,                      ->(time)    { where(started_at: time) }
  scope :before,                  ->(time)    { where(arel_table[:started_at].lt(time)) }
  scope :after,                   ->(time)    { where(arel_table[:started_at].gt(time)) }
  scope :last_before,             ->(time)    { before(time).reorder(started_at: :desc).limit(1) }
  scope :first_after,             ->(time)    { after(time).reorder(started_at: :asc).limit(1) }
  scope :before_with,             ->(time)    { where(arel_table[:started_at].lteq(time)) }
  scope :after_with,              ->(time)    { where(arel_table[:started_at].gteq(time)) }

  def chain
    self.class.chain(product)
  end

  def siblings
    chain.where.not(id: id)
  end

  def previous_population<commit_msg>Specifiec primary key since we're on a view.<commit_after># = Informations
#
# == License
#
# Ekylibre - Simple agricultural ERP
# Copyright (C) 2008-2009 <NAME>, <NAME>
# Copyright (C) 2010-2012 <NAME>
# Copyright (C) 2012-2016 <NAME>, <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see http://www.gnu.org/licenses.
#
# == Table: product_populations
#
#  created_at   :datetime
#  creator_id   :integer
#  id           :integer
#  lock_version :integer
#  product_id   :integer
#  started_at   :datetime
#  updated_at   :datetime
#  updater_id   :integer
#  value        :decimal(, )
#

# Sum of all the deltas in product movements up to and including a date.
class ProductPopulation < Ekylibre::Record::Base
  self.primary_key = 'id'

  belongs_to :product
  # [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
  validates :id, numericality: { only_integer: true, greater_than: -2_147_483_649, less_than: 2_147_483_648 }, allow_blank: true
  validates :started_at, timeliness: { on_or_after: -> { Time.new(1, 1, 1).in_time_zone }, on_or_before: -> { Time.zone.now + 50.years } }, allow_blank: true
  validates :value, numericality: true, allow_blank: true
  # ]VALIDATORS]

  scope :chain,                   ->(product) { where(product: product).order(started_at: :asc) }
  scope :initial_population_for,  ->(product) { chain(product).first }
  scope :at,                      ->(time)    { where(started_at: time) }
  scope :before,                  ->(time)    { where(arel_table[:started_at].lt(time)) }
  scope :after,                   ->(time)    { where(arel_table[:started_at].gt(time)) }
  scope :last_before,             ->(time)    { before(time).reorder(started_at: :desc).limit(1) }
  scope :first_after,             ->(time)    { after(time).reorder(started_at: :asc).limit(1) }
  scope :before_with,             ->(time)    { where(arel_table[:started_at].lteq(time)) }
  scope :after_with,              ->(time)    { where(arel_table[:started_at].gteq(time)) }

  def chain
    self.class.chain(product)
  end

  def siblings
    chain.where.not(id: id)
  end

  def previous_population
{'fraction_non_alphanumeric': 0.11627906976744186, 'fraction_numerical': 0.019504876219054765, 'mean_word_length': 3.3287337662337664, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6517508', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1664, 'n_words': 510}