<commit_before># == Schema Information
#
# Table name: districts
#
#  id         :integer          not null, primary key
#  district   :string
#  state_id   :integer
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class District < ActiveRecord::Base
  belongs_to :state, required: true
  has_many :senators, through: :state
  has_and_belongs_to_many :zip_codes
  has_one :representative, class_name: "Legislator", dependent: :destroy
  has_one :target_rep, -> { targeted }, class_name: "Legislator"
  has_many :campaigns, through: :representative

  validates :district, presence: true, uniqueness: { scope: :state }

  delegate :abbrev, to: :state

  def self.find_by_state_and_district(state:, district:)
    joins(:state).where(states: { abbrev: state }).find_by(district: district)
  end

  def self.find_by_address(address:, zip:, city: nil, state: nil, includes: nil)
    results = Integration::Here.geocode_address( address: address,
                                                 city:    city,
                                                 state:   state,
                                                 zip:     zip )
    if coords = results[:coordinates]
      if district_hash = Integration::MobileCommons.district_from_coords(coords)
        District.includes(includes).find_by_state_and_district(district_hash)
      end
    end
  end<commit_msg>Donations: fix for including state abbreviation<commit_after># == Schema Information
#
# Table name: districts
#
#  id         :integer          not null, primary key
#  district   :string
#  state_id   :integer
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class District < ActiveRecord::Base
  belongs_to :state, required: true
  has_many :senators, through: :state
  has_and_belongs_to_many :zip_codes
  has_one :representative, class_name: "Legislator", dependent: :destroy
  has_one :target_rep, -> { targeted }, class_name: "Legislator"
  has_many :campaigns, through: :representative

  validates :district, presence: true, uniqueness: { scope: :state }

  delegate :abbrev, to: :state

  def self.find_by_state_and_district(state:, district:)
    joins(:state).where(states: { abbrev: state }).find_by(district: district)
  end

  def self.find_by_address(address:, zip:, city: nil, state_abbrev: nil, includes: nil)
    results = Integration::Here.geocode_address( address: address,
                                                 city:    city,
                                                 state:   state_abbrev,
                                                 zip:     zip )
    if coords = results[:coordinates]
      if district_hash = Integration::MobileCommons.district_from_coords(coords)
        District.includes(includes).find_by_state_and_district(district_hash)
      end
    end
  end
{'fraction_non_alphanumeric': 0.09074982480728802, 'fraction_numerical': 0.0, 'mean_word_length': 2.6047979797979797, 'pattern_counts': {'":': 0, '<': 5, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7282311', 'n_tokens_mistral': 839, 'n_tokens_neox': 796, 'n_words': 206}