<commit_before>class Recommendation < ActiveRecord::Base
  belongs_to :user
  belongs_to :book

  validates_presence_of :user_id, :book_id, :comment, :valoration
  validate :correct_valoration

  after_create :create_events
  before_destroy :destroy_events

  private

  def create_events
    user.followers.each do |follower|
      Event.create(
        user_id: follower.id,
        item_urn: "recommendation:#{id}"
      )
    end
  end

  def destroy_events
    events = Event.where(item_urn: "ownership:#{id}")
    events.destroy_all
  end

  def correct_valoration
    unless valoration >= 0 && valoration <= 100
      errors.add(:valoration, "valoration should be between 0 and 100")
    end
  end
end
<commit_msg>update book index in elasticsearch when new recommendation, for valoration average<commit_after>class Recommendation < ActiveRecord::Base
  belongs_to :user
  belongs_to :book, touch: true

  validates_presence_of :user_id, :book_id, :comment, :valoration
  validate :correct_valoration

  after_create :create_events
  before_destroy :destroy_events

  private

  def create_events
    user.followers.each do |follower|
      Event.create(
        user_id: follower.id,
        item_urn: "recommendation:#{id}"
      )
    end
  end

  def destroy_events
    events = Event.where(item_urn: "ownership:#{id}")
    events.destroy_all
  end

  def correct_valoration
    unless valoration >= 0 && valoration <= 100
      errors.add(:valoration, "valoration should be between 0 and 100")
    end
  end
end

{'fraction_non_alphanumeric': 0.08070866141732283, 'fraction_numerical': 0.010498687664041995, 'mean_word_length': 3.607250755287009, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4093687', 'n_tokens_mistral': 506, 'n_tokens_neox': 471, 'n_words': 124}