<commit_before>#
# A LifeList is a List of all the taxa a person has observed.
#
class LifeList < List
  belongs_to :place
  before_validation :set_defaults
  before_save :set_place_rule
  after_create :add_taxa_from_observations
  validate :place_has_boundary
  
  MAX_RELOAD_TRIES = 60

  def place_has_boundary
    if place_id && !PlaceGeometry.where(:place_id => place_id).exists?
      errors.add(:place_id, "must have a boundary")
    end
  end
  
  #
  # Adds a taxon to this life list by creating a new blank obs of the taxon
  # and relying on the callbacks in observation.  In theory, this should never
  # bonk on an invalid listed taxon...
  #
  def add_taxon(taxon, options = {})
    taxon_id = taxon.is_a?(Taxon) ? taxon.id : taxon
    
    # Make sure the parent species is added for infraspecies
    taxon = taxon.is_a?(Taxon) ? taxon : Taxon.find(taxon_id)
    if taxon.rank_level < Taxon::SPECIES_LEVEL && taxon.species
      unless listed_taxon = listed_taxa.find_by_taxon_id(taxon.species.id)
        lt = ListedTaxon.create(options.merge(list: self, taxon_id: taxon.species.id))
      end
    end
    
    if listed_taxon = listed_taxa.find_by_taxon_id(taxon_id)
      return listed_taxon
    end
    ListedTaxon.create(options.merge(:list => self, :taxon_id => taxon_id))
  end<commit_msg>minor bugfix<commit_after>#
# A LifeList is a List of all the taxa a person has observed.
#
class LifeList < List
  belongs_to :place
  before_validation :set_defaults
  before_save :set_place_rule
  after_create :add_taxa_from_observations
  validate :place_has_boundary
  
  MAX_RELOAD_TRIES = 60

  def place_has_boundary
    if place_id && !PlaceGeometry.where(:place_id => place_id).exists?
      errors.add(:place_id, "must have a boundary")
    end
  end
  
  #
  # Adds a taxon to this life list by creating a new blank obs of the taxon
  # and relying on the callbacks in observation.  In theory, this should never
  # bonk on an invalid listed taxon...
  #
  def add_taxon(taxon, options = {})
    taxon_id = taxon.is_a?(Taxon) ? taxon.id : taxon
    
    # Make sure the parent species is added for infraspecies
    taxon = taxon.is_a?(Taxon) ? taxon : Taxon.find(taxon_id)
    if !taxon.rank_level.nil? && taxon.rank_level < Taxon::SPECIES_LEVEL && taxon.species
      unless listed_taxon = listed_taxa.find_by_taxon_id(taxon.species.id)
        lt = ListedTaxon.create(options.merge(list: self, taxon_id: taxon.species.id))
      end
    end
    
    if listed_taxon = listed_taxa.find_by_taxon_id(taxon_id)
      return listed_taxon
    end
    ListedTaxon.create(options.merge(:list => self, :taxon_id => taxon_id))
  end
{'fraction_non_alphanumeric': 0.08462410275783906, 'fraction_numerical': 0.001511144692104269, 'mean_word_length': 3.503401360544218, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7424845', 'n_tokens_mistral': 951, 'n_tokens_neox': 935, 'n_words': 243}