2024-03-15 18:27:31 -04:00
|
|
|
class PointsController < ApplicationController
|
2024-03-15 18:45:48 -04:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
def index
|
2024-03-16 18:15:44 -04:00
|
|
|
@points = Point.where('timestamp >= ? AND timestamp <= ?', start_at, end_at).order(timestamp: :asc)
|
2024-03-15 18:27:31 -04:00
|
|
|
|
2024-03-16 17:39:03 -04:00
|
|
|
@countries_and_cities = @points.group_by(&:country).transform_values { _1.pluck(:city).uniq.compact }
|
2024-03-15 20:07:20 -04:00
|
|
|
@coordinates = @points.pluck(:latitude, :longitude).map { [_1.to_f, _2.to_f] }
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|
2024-03-16 18:15:44 -04:00
|
|
|
|
|
|
|
|
def start_at
|
|
|
|
|
return 1.month.ago.beginning_of_day.to_i if params[:start_at].nil?
|
|
|
|
|
|
|
|
|
|
params[:start_at].to_datetime.to_i
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def end_at
|
|
|
|
|
return Date.today.end_of_day.to_i if params[:end_at].nil?
|
|
|
|
|
|
|
|
|
|
params[:end_at].to_datetime.to_i
|
|
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|