<commit_before>class Clothing < ActiveRecord::Base
  belongs_to :user
  acts_as_taggable_on :tags
  has_many :clothing_logs, :dependent => :destroy
  has_many :clothing_matches, :foreign_key => :clothing_a_id, :dependent => :destroy
  has_attached_file :image, :styles => { :large => "400x400", :medium => "x90", :small => "x40" }, :default_url => '/images/clothing/:style/missing.jpg', :path => ':rails_root/public/f/clothing/:user_id/:hashed_path/:id/:style/:basename.:extension', :url => '/f/clothing/:user_id/:hashed_path/:id/:style/:basename.:extension'
  before_save :update_hsl

  def autocomplete_view
    "#{self.id} - #{self.name}"
  end
  def update_hsl
    c = self.get_color
    unless c.nil? then
      hsl = c.to_hsl
      self.hue = hsl.h
      self.saturation = hsl.s
      self.brightness = hsl.l
    end
  end

  def get_color
    if self.color.blank? and self.image.file?
      self.color = Clothing.guess_color(self.image)
    end
    return unless self.color
    base = self.color.to_s.split(',')[0]
    unless base.nil? then
      Color::RGB.from_html(base)
    end
  end

  def update_stats!
    last = self.clothing_logs.order('date DESC').first
    if last then
      self.last_worn = last.date
      self.last_clothing_log_id = last.id
    else
      self.last_worn = self.last_clothing_log_id = nil
    end
    self
  end

  def previous_by_id
    self.class.first(:conditions => ['id < ?', self.id], :order => 'id desc')<commit_msg>Guard against color problems<commit_after>class Clothing < ActiveRecord::Base
  belongs_to :user
  acts_as_taggable_on :tags
  has_many :clothing_logs, :dependent => :destroy
  has_many :clothing_matches, :foreign_key => :clothing_a_id, :dependent => :destroy
  has_attached_file :image, :styles => { :large => "400x400", :medium => "x90", :small => "x40" }, :default_url => '/images/clothing/:style/missing.jpg', :path => ':rails_root/public/f/clothing/:user_id/:hashed_path/:id/:style/:basename.:extension', :url => '/f/clothing/:user_id/:hashed_path/:id/:style/:basename.:extension'
  before_save :update_hsl

  def autocomplete_view
    "#{self.id} - #{self.name}"
  end
  def update_hsl
    c = self.get_color
    unless c.nil? then
      hsl = c.to_hsl
      self.hue = hsl.h
      self.saturation = hsl.s
      self.brightness = hsl.l
    end
  end

  def get_color
    if self.color.blank? and self.image.file?
      begin self.color = Clothing.guess_color(self.image) rescue end
    end
    return unless self.color
    base = self.color.to_s.split(',')[0]
    unless base.nil? then
      Color::RGB.from_html(base)
    end
  end

  def update_stats!
    last = self.clothing_logs.order('date DESC').first
    if last then
      self.last_worn = last.date
      self.last_clothing_log_id = last.id
    else
      self.last_worn = self.last_clothing_log_id = nil
    end
    self
  end

  def previous_by_id
    self.class.first(:conditions => ['id < ?', self.id], :order => 'id desc')
{'fraction_non_alphanumeric': 0.13608666215301288, 'fraction_numerical': 0.007447528774542992, 'mean_word_length': 3.264069264069264, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '5486562', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1080, 'n_words': 211}