<commit_before># == Schema Information
#
# Table name: admin_users
#
#  id                     :integer          not null, primary key
#  osm_id                 :integer
#  oauth_token            :string(255)
#  oauth_secret           :string(255)
#  email                  :string(255)      default(""), not null
#  encrypted_password     :string(255)      default(""), not null
#  reset_password_token   :string(255)
#  reset_password_sent_at :datetime
#  remember_created_at    :datetime
#  sign_in_count          :integer          default(0), not null
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :string(255)
#  last_sign_in_ip        :string(255)
#  created_at             :datetime
#  updated_at             :datetime
#  osm_username           :string(255)
#  changeset_id           :integer
#  role_id                :integer
#  location               :spatial          point, 0
#

class AdminUser < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :omniauthable,
         :recoverable, :rememberable, :trackable

 validates :email, uniqueness: { allow_nil: true, allow_blank: true }
 validates :osm_id, presence: true

 has_many :matched_places, class_name: Place, foreign_key: :matcher_id

 belongs_to :role
 before_create :set_default_role

  def self.find_for_osm_oauth(access_token, signed_in_resource=nil)
    data = access_token.info
    if admin_user = AdminUser.where(:osm_id => data.id).first
      # found
    else
      admin_user = AdminUser.create!(:osm_id => data.id, :password => Devise.friendly_token[0, 20])
    end
    admin_user.update_attributes( oauth_token: access_token.credentials.token,
                                  oauth_secret: access_token.credentials.secret,
                                  osm_username: data.display_name,
                                  location: RGeo::Cartesian.factory.point(data.lon, data.lat)
                                )
    admin_user
  end

  def display_name
    (osm_username || email || osm_id.to_s) +
    " (#{matched_places.count})"
  end

  def oauth_authorized?
    !!(oauth_token && oauth_secret)
  end

  def client<commit_msg>Fix indentation<commit_after># == Schema Information
#
# Table name: admin_users
#
#  id                     :integer          not null, primary key
#  osm_id                 :integer
#  oauth_token            :string(255)
#  oauth_secret           :string(255)
#  email                  :string(255)      default(""), not null
#  encrypted_password     :string(255)      default(""), not null
#  reset_password_token   :string(255)
#  reset_password_sent_at :datetime
#  remember_created_at    :datetime
#  sign_in_count          :integer          default(0), not null
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :string(255)
#  last_sign_in_ip        :string(255)
#  created_at             :datetime
#  updated_at             :datetime
#  osm_username           :string(255)
#  changeset_id           :integer
#  role_id                :integer
#  location               :spatial          point, 0
#

class AdminUser < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :omniauthable,
         :recoverable, :rememberable, :trackable

  validates :email, uniqueness: { allow_nil: true, allow_blank: true }
  validates :osm_id, presence: true

  has_many :matched_places, class_name: Place, foreign_key: :matcher_id

  belongs_to :role
  before_create :set_default_role

  def self.find_for_osm_oauth(access_token, signed_in_resource=nil)
    data = access_token.info
    if admin_user = AdminUser.where(:osm_id => data.id).first
      # found
    else
      admin_user = AdminUser.create!(:osm_id => data.id, :password => <PASSWORD>.friendly_token[0, 20])
    end
    admin_user.update_attributes( oauth_token: access_token.credentials.token,
                                  oauth_secret: access_token.credentials.secret,
                                  osm_username: data.display_name,
                                  location: RGeo::Cartesian.factory.point(data.lon, data.lat)
                                )
    admin_user
  end

  def display_name
    (osm_username || email || osm_id.to_s) +
    " (#{matched_places.count})"
  end

  def oauth_authorized?
    !!(oauth_token && oauth_secret)
  end

  def client
{'fraction_non_alphanumeric': 0.08926627476594819, 'fraction_numerical': 0.012627912040060963, 'mean_word_length': 2.3705062362435805, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2192495', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1391, 'n_words': 294}