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 17:48:26 -04:00
|
|
|
start_at = params[:start_at]&.to_datetime.to_i
|
|
|
|
|
end_at = params[:end_at]&.to_datetime.to_i
|
2024-03-16 16:31:07 -04:00
|
|
|
|
2024-03-16 17:39:03 -04:00
|
|
|
@points =
|
2024-03-16 17:51:46 -04:00
|
|
|
if start_at.positive? && end_at.positive?
|
|
|
|
|
Point.where('timestamp >= ? AND timestamp <= ?', start_at, end_at)
|
2024-03-16 17:39:03 -04:00
|
|
|
else
|
2024-03-16 17:51:46 -04:00
|
|
|
Point.all
|
|
|
|
|
end.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
|
|
|
|
|
end
|