<commit_before>class Restaurant < ActiveRecord::Base
  has_secure_password
  has_many :promotions

  validates :yelp_id, uniqueness: true
  validates :name, presence: true
  validates :display_phone, presence: true
  validates :address, presence: true
  validates :zipcode, presence: true
  validates :cuisine, presence: true

  geocoded_by :geocoder_address
  after_validation :geocode

  def geocoder_address
    "#{address} #{zipcode}"
  end

  def to_geoJSON
    {
      features: [{
        type: 'Feature',
        geometry: {
          type: 'Point',
          coordinates: [self.longitude, self.latitude]
        },
        properties: {
          id: self.id,
          name: self.name,
          address: self.address,
          yelp_id: self.yelp_id,
          active_promotions: self.promotions.where(active: true).count
          # max_discount: (self.promotions.max(:max_discount) * 100).to_i
        }
      }]
    }
  end

end<commit_msg>add active_unexpired_promotions scope to restaurant, add max_discount to geojson<commit_after>class Restaurant < ActiveRecord::Base
  has_secure_password
  has_many :active_unexpired_promotions, -> { where(active: true).where("valid_on >= '#{Date.today}'") }, class_name: "Promotion"
  has_many :promotions

  validates :yelp_id, uniqueness: true
  validates :name, presence: true
  validates :display_phone, presence: true
  validates :address, presence: true
  validates :zipcode, presence: true
  validates :cuisine, presence: true

  geocoded_by :geocoder_address
  after_validation :geocode

  def geocoder_address
    "#{address} #{zipcode}"
  end

  def to_geoJSON
    {
      features: [{
        type: 'Feature',
        geometry: {
          type: 'Point',
          coordinates: [self.longitude, self.latitude]
        },
        properties: {
          id: self.id,
          name: self.name,
          address: self.address,
          yelp_id: self.yelp_id,
          active_promotions: self.active_unexpired_promotions.count,
          max_discount: ((self.active_unexpired_promotions.max_by(&:max_discount).try(:max_discount) || 0) * 100).to_i
        }
      }]
    }
  end

end
{'fraction_non_alphanumeric': 0.10148975791433892, 'fraction_numerical': 0.0032588454376163874, 'mean_word_length': 2.858168761220826, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2815761', 'n_tokens_mistral': 716, 'n_tokens_neox': 680, 'n_words': 148}