Extract timestamp range calculation to separate methods

This commit is contained in:
Eugene Burmakin 2025-07-23 20:27:55 +02:00
parent 51dd2e0a4b
commit 94f6dbe18e

View file

@ -184,30 +184,35 @@ class Tracks::Generator
def get_timestamp_range def get_timestamp_range
case mode case mode
when :bulk when :bulk then bulk_timestamp_range
if start_at && end_at when :daily then daily_timestamp_range
[start_at.to_i, end_at.to_i] when :incremental then incremental_timestamp_range
else
first_point = user.tracked_points.order(:timestamp).first
last_point = user.tracked_points.order(:timestamp).last
[first_point&.timestamp || 0, last_point&.timestamp || Time.current.to_i]
end
when :daily
day = start_at&.to_date || Date.current
[day.beginning_of_day.to_i, day.end_of_day.to_i]
when :incremental
# For incremental, we need all untracked points up to end_at
first_point = user.tracked_points.where(track_id: nil).order(:timestamp).first
end_timestamp = end_at ? end_at.to_i : Time.current.to_i
[first_point&.timestamp || 0, end_timestamp]
else else
raise ArgumentError, "Unknown mode: #{mode}" raise ArgumentError, "Unknown mode: #{mode}"
end end
end end
def bulk_timestamp_range
return [start_at.to_i, end_at.to_i] if start_at && end_at
first_point = user.tracked_points.order(:timestamp).first
last_point = user.tracked_points.order(:timestamp).last
[first_point&.timestamp || 0, last_point&.timestamp || Time.current.to_i]
end
def daily_timestamp_range
day = start_at&.to_date || Date.current
[day.beginning_of_day.to_i, day.end_of_day.to_i]
end
def incremental_timestamp_range
first_point = user.tracked_points.where(track_id: nil).order(:timestamp).first
end_timestamp = end_at ? end_at.to_i : Time.current.to_i
[first_point&.timestamp || 0, end_timestamp]
end
def distance_threshold_meters def distance_threshold_meters
@distance_threshold_meters ||= user.safe_settings.meters_between_routes.to_i @distance_threshold_meters ||= user.safe_settings.meters_between_routes.to_i
end end