2022-04-06 14:46:10 -04:00
|
|
|
class User < ApplicationRecord
|
|
|
|
|
# Include default devise modules. Others available are:
|
|
|
|
|
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
|
|
|
|
devise :database_authenticatable, :registerable,
|
|
|
|
|
:recoverable, :rememberable, :validatable
|
2024-03-15 18:27:31 -04:00
|
|
|
|
|
|
|
|
has_many :imports, dependent: :destroy
|
|
|
|
|
has_many :points, through: :imports
|
2024-03-23 15:29:55 -04:00
|
|
|
has_many :stats
|
2024-03-23 16:16:11 -04:00
|
|
|
|
2024-03-23 16:46:18 -04:00
|
|
|
def export_data
|
|
|
|
|
excepted_attributes = %w[raw_data id created_at updated_at country city import_id]
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
email => {
|
|
|
|
|
'dawarich-export' => self.points.map { _1.attributes.except(*excepted_attributes) }
|
|
|
|
|
}
|
|
|
|
|
}.to_json
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-23 16:16:11 -04:00
|
|
|
def total_km
|
|
|
|
|
Stat.where(user: self).sum(:distance)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def total_countries
|
2024-03-28 10:11:59 -04:00
|
|
|
Stat.where(user: self).pluck(:toponyms).flatten.map { _1['country'] }.uniq.size
|
2024-03-23 16:16:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def total_cities
|
|
|
|
|
Stat.where(user: self).pluck(:toponyms).flatten.size
|
|
|
|
|
end
|
2024-03-24 13:55:35 -04:00
|
|
|
|
|
|
|
|
def total_reverse_geocoded
|
|
|
|
|
points.where.not(country: nil, city: nil).count
|
|
|
|
|
end
|
2022-04-06 14:46:10 -04:00
|
|
|
end
|