<commit_before>class Competitor < ActiveRecord::Base
    has_many :members
    has_many :registrants, :through => :members, :order => "bib_number"
    belongs_to :competition, :touch => true
    acts_as_list :scope => :competition

    has_many :scores, :dependent => :destroy
    has_many :boundary_scores, :dependent => :destroy
    has_many :street_scores, :dependent => :destroy
    has_many :standard_execution_scores, :dependent => :destroy
    has_many :standard_difficulty_scores, :dependent => :destroy
    has_many :distance_attempts, :dependent => :destroy, :order => "distance DESC, id DESC"
    has_many :time_results, :dependent => :destroy
    has_many :external_results, :dependent => :destroy

    attr_accessible :competition_id, :position, :registrant_ids, :custom_external_id, :custom_name
    accepts_nested_attributes_for :registrants

    validates :competition_id, :presence => true
    validates_associated :members
    # not all competitor types require a position
    #validates :position, :presence => true,
                         #:numericality => {:only_integer => true, :greater_than => 0}

    def to_s
        name
    end

    def bib_number
      members.first.registrant.bib_number
    end

    def place=(place)
      Rails.cache.write(place_key, place)
    end

    def place
      Rails.cache.fetch(place_key) || "Unknown"
    end

    def overall_place=(place)
      Rails.cache.write(overall_place_key, place)
    end

    def overall_place
      Rails.cache.fetch(overall_place_key) || "Unknown"
    end

    def age_group_entry_description # XXX combine with the other age_group function
      registrant = members.first.registrant
      ag_entry_description = competition.determine_age_group_type.try(:age_group_entry_description, registrant.age, registrant.gender, registrant.default_wheel_size.id)
      if ag_entry_description.nil?
        "No Age Group for #{registrant.age}-#{registrant.gender}"
      else
        ag_entry_description
      end
    end

    private
    def place_key
      "/competition/#{competition.id}-#{competition.updated_at}/competitor/#{id}-#{updated_at}/place"
    end

    def overall_place_key<commit_msg>fix a transient test failure due to race condition.<commit_after>class Competitor < ActiveRecord::Base
    has_many :members
    has_many :registrants, :through => :members, :order => "bib_number"
    belongs_to :competition, :touch => true
    acts_as_list :scope => :competition

    has_many :scores, :dependent => :destroy
    has_many :boundary_scores, :dependent => :destroy
    has_many :street_scores, :dependent => :destroy
    has_many :standard_execution_scores, :dependent => :destroy
    has_many :standard_difficulty_scores, :dependent => :destroy
    has_many :distance_attempts, :dependent => :destroy, :order => "distance DESC, id DESC"
    has_many :time_results, :dependent => :destroy
    has_many :external_results, :dependent => :destroy

    attr_accessible :competition_id, :position, :registrant_ids, :custom_external_id, :custom_name
    accepts_nested_attributes_for :registrants

    validates :competition_id, :presence => true
    validates_associated :members
    # not all competitor types require a position
    #validates :position, :presence => true,
                         #:numericality => {:only_integer => true, :greater_than => 0}

    def to_s
        name
    end

    def bib_number
      members.first.registrant.bib_number
    end

    def place=(place)
      Rails.cache.write(place_key, place)
    end

    def place
      Rails.cache.fetch(place_key) || "Unknown"
    end

    def overall_place=(place)
      Rails.cache.write(overall_place_key, place)
    end

    def overall_place
      Rails.cache.fetch(overall_place_key) || "Unknown"
    end

    def age_group_entry_description # XXX combine with the other age_group function
      registrant = members.first.registrant
      ag_entry_description = competition.determine_age_group_type.try(:age_group_entry_description, registrant.age, registrant.gender, registrant.default_wheel_size.id)
      if ag_entry_description.nil?
        "No Age Group for #{registrant.age}-#{registrant.gender}"
      else
        ag_entry_description
      end
    end

    private
    def place_key
      competition.reload
      "/competition/#{competition.id}-#{competition.updated_at}/competitor/#{id}-#{updated_at}/place"
    end

    def overall_place_key
{'fraction_non_alphanumeric': 0.09433536447754458, 'fraction_numerical': 0.0004513653802753329, 'mean_word_length': 3.587991718426501, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '1324909', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1328, 'n_words': 302}