<commit_before>class Development < ActiveRecord::Base
  # TODO: basic geocoding
  # geocoded_by :full_street_address   # Implement this method
  # after_validation :geocode          # Auto-fetch coordinates
  has_one :walkscore # TODO

  extend Enumerize

  # include Development::Validations
  # include Development::Scopes

  # Callbacks
  before_save :update_tagline
  before_save :clean_zip_code
  before_save :cache_street_view

  # Relationships
  belongs_to :creator, class_name: :User
  belongs_to :place

  has_many :edits, dependent: :nullify
  has_many :flags, dependent: :nullify
  has_many :crosswalks, dependent: :nullify
  has_many :team_memberships, class_name: :DevelopmentTeamMembership,
    counter_cache: :team_membership_count, dependent: :destroy
  has_many :team_members, through: :team_memberships, source: :organization
  has_many :moderators, through: :team_members, source: :members
  has_many :subscriptions, as: :subscribable,
    dependent: :nullify
  has_many :subscribers, through: :subscriptions, source: :user,
    dependent: :nullify

  has_and_belongs_to_many :programs

  default_scope { includes(:place) }

  # Validations
  validates :creator,    presence: true
  validates :year_compl, presence: true

  lat_range = { less_than_or_equal_to:  90, greater_than_or_equal_to:  -90 }
  lon_range = { less_than_or_equal_to: 180, greater_than_or_equal_to: -180 }

  validates :latitude,  presence: true, numericality: lat_range
  validates :longitude, presence: true, numericality: lon_range

  validates :street_view_latitude,  allow_blank: true, numericality: lat_range
  validates :street_view_longitude, allow_blank: true, numericality: lon_range

  STATUSES = [:projected, :planning, :in_construction, :completed].freeze
  enumerize :status, in: STATUSES, predicates: true

  alias_attribute :description, :desc
  alias_attribute :website,     :project_url
  alias_attribute :zip,         :zip_code
  alias_attribute :hidden,      :private

  # Scopes
  ranged_scopes :created_at, :updated_at, :height, :stories,
    :year_compl, :affordable, :prjarea, :singfamhu, :twnhsmmult,
    :lgmultifam, :tothu, :gqpop, :rptdemp, :emploss, :estemp, :commsf,
    :hotelrms, :onsitepark, :total_cost, :fa_ret, :fa_ofcmd,
    :fa_indmf, :fa_whs, :fa_rnd, :fa_edinst, :fa_other, :fa_hotel

  boolean_scopes :rdv, :asofright, :ovr55, :clusteros, :phased,
    :stalled, :cancelled, :hidden

  scope :close_to, CloseToQuery.new(self).scope

  def location
    [latitude, longitude].map(&:to_f)
  end

  def rlocation
    location.reverse
  end

  def zip_code
    code = read_attribute(:zip_code).to_s
    code.length == 9 ? nine_digit_formatted_zip(code) : code<commit_msg>Make Development code more readable.<commit_after>class Development < ActiveRecord::Base
  # TODO: basic geocoding
  # geocoded_by :full_street_address   # Implement this method
  # after_validation :geocode          # Auto-fetch coordinates
  has_one :walkscore # TODO

  extend Enumerize

  # include Development::Callbacks
  # include Development::Relationships
  # include Development::Validations
  # include Development::Scopes

  # Callbacks
  before_save :update_tagline
  before_save :clean_zip_code
  before_save :cache_street_view

  # Relationships
  belongs_to :creator, class_name: :User
  belongs_to :place

  has_many :edits
  has_many :flags
  has_many :crosswalks

  has_many :team_memberships,
    class_name:    :DevelopmentTeamMembership,
    counter_cache: :team_membership_count,
    dependent:     :destroy

  has_many :team_members, through: :team_memberships, source: :organization
  has_many :moderators,   through: :team_members,     source: :members

  has_many :subscriptions, as: :subscribable
  has_many :subscribers,   through: :subscriptions, source: :user

  has_and_belongs_to_many :programs

  # Validations
  validates :creator,    presence: true
  validates :year_compl, presence: true

  lat_range = { less_than_or_equal_to:  90, greater_than_or_equal_to:  -90 }
  lon_range = { less_than_or_equal_to: 180, greater_than_or_equal_to: -180 }

  validates :latitude,  presence: true, numericality: lat_range
  validates :longitude, presence: true, numericality: lon_range

  validates :street_view_latitude,  allow_blank: true, numericality: lat_range
  validates :street_view_longitude, allow_blank: true, numericality: lon_range

  STATUSES = [:projected, :planning, :in_construction, :completed].freeze
  enumerize :status, in: STATUSES, predicates: true

  alias_attribute :description, :desc
  alias_attribute :website,     :project_url
  alias_attribute :zip,         :zip_code
  alias_attribute :hidden,      :private

  # Scopes
  default_scope { includes(:place) }

  ranged_scopes :created_at, :updated_at, :height, :stories,
    :year_compl, :affordable, :prjarea, :singfamhu, :twnhsmmult,
    :lgmultifam, :tothu, :gqpop, :rptdemp, :emploss, :estemp, :commsf,
    :hotelrms, :onsitepark, :total_cost, :fa_ret, :fa_ofcmd,
    :fa_indmf, :fa_whs, :fa_rnd, :fa_edinst, :fa_other, :fa_hotel

  boolean_scopes :rdv, :asofright, :ovr55, :clusteros, :phased,
    :stalled, :cancelled, :hidden

  scope :close_to, CloseToQuery.new(self).scope

  def location
    [latitude, longitude].map(&:to_f)
  end

  def rlocation
    location.reverse
  end

  def zip_code
    code = read_attribute(:zip_code).to_s
    code.length == 9 ? nine_digit_formatted_zip(code) : code
{'fraction_non_alphanumeric': 0.09366901147723065, 'fraction_numerical': 0.004813032210292484, 'mean_word_length': 4.911378555798687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2454672', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1847, 'n_words': 421}