2024-08-21 12:40:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-12-03 09:59:34 -05:00
|
|
|
class Photos::ImportParser
|
2024-11-04 07:14:06 -05:00
|
|
|
include Imports::Broadcaster
|
2025-03-23 14:13:59 -04:00
|
|
|
include PointValidation
|
2024-08-21 12:40:54 -04:00
|
|
|
attr_reader :import, :json, :user_id
|
|
|
|
|
|
|
|
|
|
def initialize(import, user_id)
|
|
|
|
|
@import = import
|
|
|
|
|
@json = import.raw_data
|
|
|
|
|
@user_id = user_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def call
|
2024-11-04 07:14:26 -05:00
|
|
|
json.each.with_index(1) { |point, index| create_point(point, index) }
|
2024-08-21 12:40:54 -04:00
|
|
|
end
|
|
|
|
|
|
2024-11-07 07:07:54 -05:00
|
|
|
def create_point(point, index)
|
2024-08-21 12:40:54 -04:00
|
|
|
return 0 if point['latitude'].blank? || point['longitude'].blank? || point['timestamp'].blank?
|
|
|
|
|
return 0 if point_exists?(point, point['timestamp'])
|
|
|
|
|
|
|
|
|
|
Point.create(
|
2025-02-21 17:45:36 -05:00
|
|
|
lonlat: "POINT(#{point['longitude']} #{point['latitude']})",
|
2024-08-21 12:40:54 -04:00
|
|
|
timestamp: point['timestamp'],
|
|
|
|
|
raw_data: point,
|
|
|
|
|
import_id: import.id,
|
|
|
|
|
user_id:
|
|
|
|
|
)
|
|
|
|
|
|
2024-11-04 07:14:26 -05:00
|
|
|
broadcast_import_progress(import, index)
|
2024-08-21 12:40:54 -04:00
|
|
|
end
|
|
|
|
|
end
|