From 3ba70e906f4d4a87591ad6af9847bad980951914 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 4 Nov 2024 13:14:06 +0100 Subject: [PATCH] Add Imports::Broadcaster to some more parsers --- app/services/google_maps/phone_takeout_parser.rb | 6 +++++- .../google_maps/semantic_history_parser.rb | 14 +++++++++----- app/services/immich/import_parser.rb | 2 ++ app/services/own_tracks/export_parser.rb | 6 +++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/services/google_maps/phone_takeout_parser.rb b/app/services/google_maps/phone_takeout_parser.rb index bd58af81..27b65885 100644 --- a/app/services/google_maps/phone_takeout_parser.rb +++ b/app/services/google_maps/phone_takeout_parser.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class GoogleMaps::PhoneTakeoutParser + include Imports::Broadcaster + attr_reader :import, :user_id def initialize(import, user_id) @@ -11,7 +13,7 @@ class GoogleMaps::PhoneTakeoutParser def call points_data = parse_json - points_data.compact.each do |point_data| + points_data.compact.each.with_index(1) do |point_data, index| next if Point.exists?( timestamp: point_data[:timestamp], latitude: point_data[:latitude], @@ -32,6 +34,8 @@ class GoogleMaps::PhoneTakeoutParser tracker_id: 'google-maps-phone-timeline-export', user_id: ) + + broadcast_import_progress(import, index) end end diff --git a/app/services/google_maps/semantic_history_parser.rb b/app/services/google_maps/semantic_history_parser.rb index a5d9002f..83d2486b 100644 --- a/app/services/google_maps/semantic_history_parser.rb +++ b/app/services/google_maps/semantic_history_parser.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class GoogleMaps::SemanticHistoryParser + include Imports::Broadcaster + attr_reader :import, :user_id def initialize(import, user_id) @@ -11,7 +13,7 @@ class GoogleMaps::SemanticHistoryParser def call points_data = parse_json - points_data.each do |point_data| + points_data.each.with_index(1) do |point_data, index| next if Point.exists?( timestamp: point_data[:timestamp], latitude: point_data[:latitude], @@ -29,6 +31,8 @@ class GoogleMaps::SemanticHistoryParser import_id: import.id, user_id: ) + + broadcast_import_progress(import, index) end end @@ -44,7 +48,7 @@ class GoogleMaps::SemanticHistoryParser { latitude: waypoint['latE7'].to_f / 10**7, longitude: waypoint['lngE7'].to_f / 10**7, - timestamp: Timestamps::parse_timestamp(timeline_object['activitySegment']['duration']['startTimestamp'] || timeline_object['activitySegment']['duration']['startTimestampMs']), + timestamp: Timestamps.parse_timestamp(timeline_object['activitySegment']['duration']['startTimestamp'] || timeline_object['activitySegment']['duration']['startTimestampMs']), raw_data: timeline_object } end @@ -52,7 +56,7 @@ class GoogleMaps::SemanticHistoryParser { latitude: timeline_object['activitySegment']['startLocation']['latitudeE7'].to_f / 10**7, longitude: timeline_object['activitySegment']['startLocation']['longitudeE7'].to_f / 10**7, - timestamp: Timestamps::parse_timestamp(timeline_object['activitySegment']['duration']['startTimestamp'] || timeline_object['activitySegment']['duration']['startTimestampMs']), + timestamp: Timestamps.parse_timestamp(timeline_object['activitySegment']['duration']['startTimestamp'] || timeline_object['activitySegment']['duration']['startTimestampMs']), raw_data: timeline_object } end @@ -62,7 +66,7 @@ class GoogleMaps::SemanticHistoryParser { latitude: timeline_object['placeVisit']['location']['latitudeE7'].to_f / 10**7, longitude: timeline_object['placeVisit']['location']['longitudeE7'].to_f / 10**7, - timestamp: Timestamps::parse_timestamp(timeline_object['placeVisit']['duration']['startTimestamp'] || timeline_object['placeVisit']['duration']['startTimestampMs']), + timestamp: Timestamps.parse_timestamp(timeline_object['placeVisit']['duration']['startTimestamp'] || timeline_object['placeVisit']['duration']['startTimestampMs']), raw_data: timeline_object } elsif timeline_object.dig('placeVisit', 'otherCandidateLocations')&.any? @@ -73,7 +77,7 @@ class GoogleMaps::SemanticHistoryParser { latitude: point['latitudeE7'].to_f / 10**7, longitude: point['longitudeE7'].to_f / 10**7, - timestamp: Timestamps::parse_timestamp(timeline_object['placeVisit']['duration']['startTimestamp'] || timeline_object['placeVisit']['duration']['startTimestampMs']), + timestamp: Timestamps.parse_timestamp(timeline_object['placeVisit']['duration']['startTimestamp'] || timeline_object['placeVisit']['duration']['startTimestampMs']), raw_data: timeline_object } else diff --git a/app/services/immich/import_parser.rb b/app/services/immich/import_parser.rb index 8037d7a4..7e0eee87 100644 --- a/app/services/immich/import_parser.rb +++ b/app/services/immich/import_parser.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Immich::ImportParser + include Imports::Broadcaster + attr_reader :import, :json, :user_id def initialize(import, user_id) diff --git a/app/services/own_tracks/export_parser.rb b/app/services/own_tracks/export_parser.rb index 068711c2..5f4d9613 100644 --- a/app/services/own_tracks/export_parser.rb +++ b/app/services/own_tracks/export_parser.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class OwnTracks::ExportParser + include Imports::Broadcaster + attr_reader :import, :data, :user_id def initialize(import, user_id) @@ -12,7 +14,7 @@ class OwnTracks::ExportParser def call points_data = data.map { |point| OwnTracks::Params.new(point).call } - points_data.each do |point_data| + points_data.each.with_index(1) do |point_data, index| next if Point.exists?( timestamp: point_data[:timestamp], latitude: point_data[:latitude], @@ -26,6 +28,8 @@ class OwnTracks::ExportParser end point.save + + broadcast_import_progress(import, index) end end end