<commit_before># == Schema Information
#
# Table name: places
#
#  id          :integer          not null, primary key
#  name        :string(255)
#  latitude    :decimal(15, 10)
#  longitude   :decimal(15, 10)
#  information :text(65535)
#  country_id  :integer
#  msl         :integer
#

class Place < ActiveRecord::Base
  belongs_to :country

  has_many :tracks, -> { order('created_at DESC') }
  has_many :pilots, -> { distinct }, through: :tracks
  has_many :events

  validates :name, presence: true
  validates :country, presence: true
  validates :latitude, presence: true
  validates :longitude, presence: true
  # validates :msl, presence: true

  def pilots_accessible_by(user)
    UserProfile.where(
      id: tracks.accessible_by(user).select(:user_profile_id).distinct
    )
  end

  class << self
    def search(query)
      joins(:country).where(
        'LOWER(places.name) LIKE :query OR LOWER(countries.name) LIKE :query',
        query: "%#{query.downcase}%"
      )
    end

    def nearby(point, radius)
      select('id,
              latitude,
              longitude,
              msl,
              SQRT(
                POW(111 * (latitude - ' + point.latitude.to_s + '), 2) +
                POW(111 * (' + point.longitude.to_s + ' - longitude) * COS(latitude / (180/PI()) ), 2)
              ) AS distance')
        .having('distance < :radius', radius: radius)
        .order('distance DESC')
    end
  end
end<commit_msg>Fix error in finding nearby place<commit_after># == Schema Information
#
# Table name: places
#
#  id          :integer          not null, primary key
#  name        :string(255)
#  latitude    :decimal(15, 10)
#  longitude   :decimal(15, 10)
#  information :text(65535)
#  country_id  :integer
#  msl         :integer
#

class Place < ActiveRecord::Base
  belongs_to :country

  has_many :tracks, -> { order('created_at DESC') }
  has_many :pilots, -> { distinct }, through: :tracks
  has_many :events

  validates :name, presence: true
  validates :country, presence: true
  validates :latitude, presence: true
  validates :longitude, presence: true
  # validates :msl, presence: true

  def pilots_accessible_by(user)
    UserProfile.where(
      id: tracks.accessible_by(user).select(:user_profile_id).distinct
    )
  end

  class << self
    def search(query)
      joins(:country).where(
        'LOWER(places.name) LIKE :query OR LOWER(countries.name) LIKE :query',
        query: "%#{query.downcase}%"
      )
    end

    def nearby(point, radius)
      select('id,
              latitude,
              longitude,
              msl,
              SQRT(
                POW(111 * (latitude - ' + point.latitude.to_s + '), 2) +
                POW(111 * (' + point.longitude.to_s + ' - longitude) * COS(latitude / (180/PI()) ), 2)
              ) AS distance')
        .having('distance < :radius', radius: radius)
        .order('distance')
    end
  end
end
{'fraction_non_alphanumeric': 0.12529955494693598, 'fraction_numerical': 0.018486819582334817, 'mean_word_length': 2.3624856156501726, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '2181072', 'n_tokens_mistral': 1004, 'n_tokens_neox': 931, 'n_words': 227}