mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Add Imports::Broadcaster to some more parsers
This commit is contained in:
parent
4a3f7d5e65
commit
3ba70e906f
4 changed files with 21 additions and 7 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class GoogleMaps::PhoneTakeoutParser
|
class GoogleMaps::PhoneTakeoutParser
|
||||||
|
include Imports::Broadcaster
|
||||||
|
|
||||||
attr_reader :import, :user_id
|
attr_reader :import, :user_id
|
||||||
|
|
||||||
def initialize(import, user_id)
|
def initialize(import, user_id)
|
||||||
|
|
@ -11,7 +13,7 @@ class GoogleMaps::PhoneTakeoutParser
|
||||||
def call
|
def call
|
||||||
points_data = parse_json
|
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?(
|
next if Point.exists?(
|
||||||
timestamp: point_data[:timestamp],
|
timestamp: point_data[:timestamp],
|
||||||
latitude: point_data[:latitude],
|
latitude: point_data[:latitude],
|
||||||
|
|
@ -32,6 +34,8 @@ class GoogleMaps::PhoneTakeoutParser
|
||||||
tracker_id: 'google-maps-phone-timeline-export',
|
tracker_id: 'google-maps-phone-timeline-export',
|
||||||
user_id:
|
user_id:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
broadcast_import_progress(import, index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class GoogleMaps::SemanticHistoryParser
|
class GoogleMaps::SemanticHistoryParser
|
||||||
|
include Imports::Broadcaster
|
||||||
|
|
||||||
attr_reader :import, :user_id
|
attr_reader :import, :user_id
|
||||||
|
|
||||||
def initialize(import, user_id)
|
def initialize(import, user_id)
|
||||||
|
|
@ -11,7 +13,7 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
def call
|
def call
|
||||||
points_data = parse_json
|
points_data = parse_json
|
||||||
|
|
||||||
points_data.each do |point_data|
|
points_data.each.with_index(1) do |point_data, index|
|
||||||
next if Point.exists?(
|
next if Point.exists?(
|
||||||
timestamp: point_data[:timestamp],
|
timestamp: point_data[:timestamp],
|
||||||
latitude: point_data[:latitude],
|
latitude: point_data[:latitude],
|
||||||
|
|
@ -29,6 +31,8 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
import_id: import.id,
|
import_id: import.id,
|
||||||
user_id:
|
user_id:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
broadcast_import_progress(import, index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -44,7 +48,7 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
{
|
{
|
||||||
latitude: waypoint['latE7'].to_f / 10**7,
|
latitude: waypoint['latE7'].to_f / 10**7,
|
||||||
longitude: waypoint['lngE7'].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
|
raw_data: timeline_object
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -52,7 +56,7 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
{
|
{
|
||||||
latitude: timeline_object['activitySegment']['startLocation']['latitudeE7'].to_f / 10**7,
|
latitude: timeline_object['activitySegment']['startLocation']['latitudeE7'].to_f / 10**7,
|
||||||
longitude: timeline_object['activitySegment']['startLocation']['longitudeE7'].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
|
raw_data: timeline_object
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -62,7 +66,7 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
{
|
{
|
||||||
latitude: timeline_object['placeVisit']['location']['latitudeE7'].to_f / 10**7,
|
latitude: timeline_object['placeVisit']['location']['latitudeE7'].to_f / 10**7,
|
||||||
longitude: timeline_object['placeVisit']['location']['longitudeE7'].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
|
raw_data: timeline_object
|
||||||
}
|
}
|
||||||
elsif timeline_object.dig('placeVisit', 'otherCandidateLocations')&.any?
|
elsif timeline_object.dig('placeVisit', 'otherCandidateLocations')&.any?
|
||||||
|
|
@ -73,7 +77,7 @@ class GoogleMaps::SemanticHistoryParser
|
||||||
{
|
{
|
||||||
latitude: point['latitudeE7'].to_f / 10**7,
|
latitude: point['latitudeE7'].to_f / 10**7,
|
||||||
longitude: point['longitudeE7'].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
|
raw_data: timeline_object
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Immich::ImportParser
|
class Immich::ImportParser
|
||||||
|
include Imports::Broadcaster
|
||||||
|
|
||||||
attr_reader :import, :json, :user_id
|
attr_reader :import, :json, :user_id
|
||||||
|
|
||||||
def initialize(import, user_id)
|
def initialize(import, user_id)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class OwnTracks::ExportParser
|
class OwnTracks::ExportParser
|
||||||
|
include Imports::Broadcaster
|
||||||
|
|
||||||
attr_reader :import, :data, :user_id
|
attr_reader :import, :data, :user_id
|
||||||
|
|
||||||
def initialize(import, user_id)
|
def initialize(import, user_id)
|
||||||
|
|
@ -12,7 +14,7 @@ class OwnTracks::ExportParser
|
||||||
def call
|
def call
|
||||||
points_data = data.map { |point| OwnTracks::Params.new(point).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?(
|
next if Point.exists?(
|
||||||
timestamp: point_data[:timestamp],
|
timestamp: point_data[:timestamp],
|
||||||
latitude: point_data[:latitude],
|
latitude: point_data[:latitude],
|
||||||
|
|
@ -26,6 +28,8 @@ class OwnTracks::ExportParser
|
||||||
end
|
end
|
||||||
|
|
||||||
point.save
|
point.save
|
||||||
|
|
||||||
|
broadcast_import_progress(import, index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue