2024-03-15 18:27:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class OwnTracks::ExportParser
|
2024-10-15 16:17:51 -04:00
|
|
|
attr_reader :import, :data, :user_id
|
2024-03-15 18:27:31 -04:00
|
|
|
|
2024-05-25 07:36:15 -04:00
|
|
|
def initialize(import, user_id)
|
2024-03-24 13:05:39 -04:00
|
|
|
@import = import
|
2024-10-15 16:17:51 -04:00
|
|
|
@data = import.raw_data
|
2024-05-25 07:36:15 -04:00
|
|
|
@user_id = user_id
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def call
|
2024-10-19 13:29:43 -04:00
|
|
|
points_data = data.map { |point| OwnTracks::Params.new(point).call }
|
2024-03-15 18:27:31 -04:00
|
|
|
|
|
|
|
|
points_data.each do |point_data|
|
2024-06-30 11:47:36 -04:00
|
|
|
next if Point.exists?(
|
|
|
|
|
timestamp: point_data[:timestamp],
|
|
|
|
|
latitude: point_data[:latitude],
|
|
|
|
|
longitude: point_data[:longitude],
|
|
|
|
|
user_id:
|
|
|
|
|
)
|
2024-03-21 17:56:55 -04:00
|
|
|
|
2024-08-15 13:47:59 -04:00
|
|
|
point = Point.new(point_data).tap do |p|
|
|
|
|
|
p.user_id = user_id
|
|
|
|
|
p.import_id = import.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
point.save
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|