mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
33 lines
659 B
Ruby
33 lines
659 B
Ruby
# frozen_string_literal: true
|
|
|
|
class StatsQuery
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def points_stats
|
|
sql = ActiveRecord::Base.sanitize_sql_array([
|
|
<<~SQL.squish,
|
|
SELECT
|
|
COUNT(id) as total,
|
|
COUNT(reverse_geocoded_at) as geocoded,
|
|
COUNT(CASE WHEN geodata = '{}'::jsonb THEN 1 END) as without_data
|
|
FROM points
|
|
WHERE user_id = ?
|
|
SQL
|
|
user.id
|
|
])
|
|
|
|
result = Point.connection.select_one(sql)
|
|
|
|
{
|
|
total: result['total'].to_i,
|
|
geocoded: result['geocoded'].to_i,
|
|
without_data: result['without_data'].to_i
|
|
}
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :user
|
|
end
|