<commit_before>class Video < ActiveRecord::Base
  include SeedFuSerializeable

  belongs_to :applied_technique, inverse_of: :videos
  belongs_to :sensei, inverse_of: :videos

  validates :youtube_code, presence: true

  after_save :update_applied_technique_keywords

  after_initialize do |video|
    video.youtube_code = 'n/a' unless video.youtube_code.present?
  end

  scope :for_aikido,
   -> { joins(:applied_technique).merge(AppliedTechnique.aikido_techniques) }

  scope :for_iaido,
   -> { joins(:applied_technique).merge(AppliedTechnique.iaido_techniques) }

  scope :primary, -> { where(primary: true) }
  scope :secondary, -> { where(primary: false) }

  scope :visible, ->(state=true) { where(visible: state) }
  scope :demo, ->(state=true) { where(for_demo: state) }

  def name
    vid_name = ''
    if !applied_technique.nil? && applied_technique.name.present?
      vid_name = applied_technique.name
    end

    vid_name += "#{primary? ? ' (primary)' : ''}"

    if description.present?
      vid_name += " (#{description})"
    end
    vid_name
  end

  def valid_youtube_code?
    youtube_code.present? && youtube_code != 'n/a'
  end

  def self.show_video?(video=nil)
    VIDEOS_ONLINE && !video.nil? && video.valid_youtube_code? && App.connected_to_youtube?
  end

  def self.keywords(videos)
    videos.map{|v| [v.sensei, v.description] }.flatten.uniq.select{|k| k.present? }.map(&:downcase)
  end

  private

  def update_applied_technique_keywords
    applied_technique.set_keywords
  end

end<commit_msg>sensei now an object not a string<commit_after>class Video < ActiveRecord::Base
  include SeedFuSerializeable

  belongs_to :applied_technique, inverse_of: :videos
  belongs_to :sensei, inverse_of: :videos

  validates :youtube_code, presence: true

  after_save :update_applied_technique_keywords

  after_initialize do |video|
    video.youtube_code = 'n/a' unless video.youtube_code.present?
  end

  scope :for_aikido,
   -> { joins(:applied_technique).merge(AppliedTechnique.aikido_techniques) }

  scope :for_iaido,
   -> { joins(:applied_technique).merge(AppliedTechnique.iaido_techniques) }

  scope :primary, -> { where(primary: true) }
  scope :secondary, -> { where(primary: false) }

  scope :visible, ->(state=true) { where(visible: state) }
  scope :demo, ->(state=true) { where(for_demo: state) }

  def name
    vid_name = ''
    if !applied_technique.nil? && applied_technique.name.present?
      vid_name = applied_technique.name
    end

    vid_name += "#{primary? ? ' (primary)' : ''}"

    if description.present?
      vid_name += " (#{description})"
    end
    vid_name
  end

  def valid_youtube_code?
    youtube_code.present? && youtube_code != 'n/a'
  end

  def self.show_video?(video=nil)
    VIDEOS_ONLINE && !video.nil? && video.valid_youtube_code? && App.connected_to_youtube?
  end

  def self.keywords(videos)
    videos.map{|v| [v.sensei.name, v.description] }.flatten.uniq.select{|k| k.present? }.map(&:downcase)
  end

  private

  def update_applied_technique_keywords
    applied_technique.set_keywords
  end

end
{'fraction_non_alphanumeric': 0.12487836522867338, 'fraction_numerical': 0.0, 'mean_word_length': 4.122923588039867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1413678', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1047, 'n_words': 201}