<commit_before>require 'open-uri'

class Location
  attr_reader :location, :lat, :lon, :city, :state, :zip, :city_obj
  attr_accessor :radius


  def initialize(location)
    if location.is_a? City
      @city_obj = city = location
      @zip = (city.zipcodes.first and city.zipcodes.first.zipcode)
      @city = city.name
      @state = city.admin1_code
      @lat = city.latitude.to_f
      @lon = city.longitude.to_f
    elsif location =~ /^\d{5}$/ and 
      (zip = Zipcode.find(:first, 
                          :include => :city,
                          :conditions => ['zipcode = ? AND city_id IS NOT NULL', location]))
      @zip = location
      @city = zip.city_name.humanize
      @state = zip.state
      @lat = zip.city.latitude.to_f
      @lon = zip.city.longitude.to_f
      @city_obj = zip.city
    elsif location =~ /^([^,]+),\s+(\w{2})$/ and
      (city = City.find(:first,
                        :include => :zipcodes,
                        :conditions => ['asciiname LIKE ? AND admin1_code = ?', $1 + '%', $2]))
      @city_obj = city
      @zip = (city.zipcodes.first and city.zipcodes.first.zipcode)
      @city = city.name
      @state = city.admin1_code
      @lat = city.latitude.to_f
      @lon = city.longitude.to_f
    else
      @location = ::Geocode.geocoder.locate(location)
      @zip = @location.postal_code
      @city = @location.locality
      @state = @location.region
      @lat = @location.coordinates.first
      @lon = @location.coordinates.second
      @city_obj = City.find(:first,
                            :include => :zipcodes,
                            :conditions => ['name LIKE ? AND admin1_code = ?', 
                                            @location.locality + '%', 
                                            @location.region]) or
                  City.create(:name => @location.locality, :asciiname => @location.locality, 
                              :admin1_code => @location.region, :latitude => @location.latitude,
                              :longitude => @location.longitude,
                              :feature_class => 'P', :feature_code => 'PPL', :country_code => 'US')
    end
    if @city_obj and area = @city_obj.stats(find_town).select{|s| s[:label] =~ /^Land Area/}.first
      @radius = Math.sqrt(area[:value].to_f).round
    else
      @radius = 24 
    end
  end

  def population
    if @city_obj
      @city_obj.population
    end
  end

  def cities_nearby
    if @city_obj
      nearest = City.find(:all, :origin => @city_obj.geocode, :within => 150, 
                          :conditions => ['cities.id != ?', @city_obj.id])
      nearest.sort { |a,b| b.population.to_i <=> a.population.to_i }[0..4].sort_by { |c| c.distance.to_f }
    end
  end

  def senators
    legislators.select do |l|
      l["title"] == "Sen" 
    end
  end

  def reps
    legislators.select do |l|
      l["title"] == 'Rep'<commit_msg>tweaking nearby city distance<commit_after>require 'open-uri'

class Location
  attr_reader :location, :lat, :lon, :city, :state, :zip, :city_obj
  attr_accessor :radius


  def initialize(location)
    if location.is_a? City
      @city_obj = city = location
      @zip = (city.zipcodes.first and city.zipcodes.first.zipcode)
      @city = city.name
      @state = city.admin1_code
      @lat = city.latitude.to_f
      @lon = city.longitude.to_f
    elsif location =~ /^\d{5}$/ and 
      (zip = Zipcode.find(:first, 
                          :include => :city,
                          :conditions => ['zipcode = ? AND city_id IS NOT NULL', location]))
      @zip = location
      @city = zip.city_name.humanize
      @state = zip.state
      @lat = zip.city.latitude.to_f
      @lon = zip.city.longitude.to_f
      @city_obj = zip.city
    elsif location =~ /^([^,]+),\s+(\w{2})$/ and
      (city = City.find(:first,
                        :include => :zipcodes,
                        :conditions => ['asciiname LIKE ? AND admin1_code = ?', $1 + '%', $2]))
      @city_obj = city
      @zip = (city.zipcodes.first and city.zipcodes.first.zipcode)
      @city = city.name
      @state = city.admin1_code
      @lat = city.latitude.to_f
      @lon = city.longitude.to_f
    else
      @location = ::Geocode.geocoder.locate(location)
      @zip = @location.postal_code
      @city = @location.locality
      @state = @location.region
      @lat = @location.coordinates.first
      @lon = @location.coordinates.second
      @city_obj = City.find(:first,
                            :include => :zipcodes,
                            :conditions => ['name LIKE ? AND admin1_code = ?', 
                                            @location.locality + '%', 
                                            @location.region]) or
                  City.create(:name => @location.locality, :asciiname => @location.locality, 
                              :admin1_code => @location.region, :latitude => @location.latitude,
                              :longitude => @location.longitude,
                              :feature_class => 'P', :feature_code => 'PPL', :country_code => 'US')
    end
    if @city_obj and area = @city_obj.stats(find_town).select{|s| s[:label] =~ /^Land Area/}.first
      @radius = Math.sqrt(area[:value].to_f).round
    else
      @radius = 24 
    end
  end

  def population
    if @city_obj
      @city_obj.population
    end
  end

  def cities_nearby
    if @city_obj
      nearest = City.find(:all, :origin => @city_obj.geocode, :within => 250, 
                          :conditions => ['cities.id != ?', @city_obj.id])
      nearest.sort { |a,b| b.population.to_i <=> a.population.to_i }[0..4].sort_by { |c| c.distance.to_f }
    end
  end

  def senators
    legislators.select do |l|
      l["title"] == "Sen" 
    end
  end

  def reps
    legislators.select do |l|
      l["title"] == 'Rep'
{'fraction_non_alphanumeric': 0.13874614594039056, 'fraction_numerical': 0.005481329222336417, 'mean_word_length': 1.8317167798254121, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2305778', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1837, 'n_words': 388}