<commit_before>class Poi < ActiveRecord::Base
  
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::AssetTagHelper
  
  include PopupHelper
  
  WHEELCHAIR_STATUS_VALUES = {:yes => 1, :limited => 2, :no => 4, :unknown => 8}

    # Tags sollen fuer die Datenbank serialisiert werden

    serialize :tags
    
    # osm_id ist der Primaerschluessel

    set_primary_key :osm_id
    
    validate :relevant?
    
    before_save :set_status
    
    # Spezielle Find-Methode fuer den Zugriff auf alle POIs in einer 
    # Bounding-Box. Fruehere Versionen von GeoRuby hatten dazu etwas
    # im MySQL-Adapter, aber das wird inzwischen nicht mehr supported,
    # daher bauen wir hier einen Standard-Contains-Query. Dieser Query
    # benutzt den raeumlichen Index und geht daher schnell (wenn man 
    # nicht gerade eine Bounding-Box fuer die ganze Welt uebergibt).
    
    scope :fully_accessible, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:yes]}
    scope :not_accessible, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:no]}
    scope :limited_accessible, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:limited]}
    scope :unknown_accessibility, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:unknown]}
    
    scope :within_bbox, lambda {|left, bottom, right, top|{
      :conditions => "MBRContains(GeomFromText('POLYGON(( \
                      #{left} #{bottom}, #{right} #{bottom}, \
                      #{right} #{top}, #{left} #{top}, \
                      #{left} #{bottom}))'), pois.geom)" } }
    
    def lat
      self.geom.lat if self.geom
    end
    
    def lon
      self.geom.lng if self.geom
    end
    
    def attributes
      super.reverse_merge!(
      :lat => lat,
      :lon => lon,
      :name => name,
      :type => type,
      :category => category,
      :wheelchair => wheelchair,
      :wheelchair_description => wheelchair_description
      )
    end
    
    def id
      osm_id
    end
      
    
    def type
      tags['amenity']   ||
      tags['shop']      ||
      tags['tourism']   ||
      tags['natural']   ||
      tags['sport']     ||
      tags['leisure']   ||
      tags['historic']  ||
      tags['highway']   ||
      tags['station']   ||
      tags['railway']
    end
    
    def category
      Amenities.each do |cat, amenities|
        return cat.to_s if amenities.include?(self.type)<commit_msg>fixed rendering of poi json<commit_after>class Poi < ActiveRecord::Base
  
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::AssetTagHelper
  
  self.include_root_in_json = false
  
  include PopupHelper
  
  WHEELCHAIR_STATUS_VALUES = {:yes => 1, :limited => 2, :no => 4, :unknown => 8}

    # Tags sollen fuer die Datenbank serialisiert werden

    serialize :tags
    
    # osm_id ist der Primaerschluessel

    set_primary_key :osm_id
    
    validate :relevant?
    
    before_save :set_status
    
    # Spezielle Find-Methode fuer den Zugriff auf alle POIs in einer 
    # Bounding-Box. Fruehere Versionen von GeoRuby hatten dazu etwas
    # im MySQL-Adapter, aber das wird inzwischen nicht mehr supported,
    # daher bauen wir hier einen Standard-Contains-Query. Dieser Query
    # benutzt den raeumlichen Index und geht daher schnell (wenn man 
    # nicht gerade eine Bounding-Box fuer die ganze Welt uebergibt).
    
    scope :fully_accessible, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:yes]}
    scope :not_accessible, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:no]}
    scope :limited_accessible, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:limited]}
    scope :unknown_accessibility, :conditions => {:status => WHEELCHAIR_STATUS_VALUES[:unknown]}
    
    scope :within_bbox, lambda {|left, bottom, right, top|{
      :conditions => "MBRContains(GeomFromText('POLYGON(( \
                      #{left} #{bottom}, #{right} #{bottom}, \
                      #{right} #{top}, #{left} #{top}, \
                      #{left} #{bottom}))'), pois.geom)" } }
    
    def lat
      self.geom.lat if self.geom
    end
    
    def lon
      self.geom.lng if self.geom
    end
    
    def attributes
      super.reverse_merge!(
      'lat' => lat,
      'lon' => lon,
      'name' => name,
      'type' => type,
      'category' => category,
      'wheelchair' => wheelchair,
      'wheelchair_description' => wheelchair_description
      )
    end
    
    def id
      osm_id
    end
      
    
    def type
      tags['amenity']   ||
      tags['shop']      ||
      tags['tourism']   ||
      tags['natural']   ||
      tags['sport']     ||
      tags['leisure']   ||
      tags['historic']  ||
      tags['highway']   ||
      tags['station']   ||
      tags['railway']
    end
    
    def category
      Amenities.each do |cat, amenities|
        return cat.to_s if amenities.include?(self.type)
{'fraction_non_alphanumeric': 0.11642453591606133, 'fraction_numerical': 0.0016142050040355124, 'mean_word_length': 2.5007062146892656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '1255580', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1548, 'n_words': 385}