Merge pull request #297 from Freika/fix/google-phone-location-history-timestamp

Fix incorrect timestamps for Google Location History (mobile device)
This commit is contained in:
Evgenii Burmakin 2024-10-01 00:38:54 +03:00 committed by GitHub
commit c5b6f872d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 40 additions and 13 deletions

View file

@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# [0.14.6] - 2024-29-30
### Fixed
- Points imported from Google Location History (mobile devise) now have correct timestamps
### Changed
- `GET /api/v1/points?slim=true` now returns `id` attribute for each point
# [0.14.5] - 2024-09-28
### Fixed

File diff suppressed because one or more lines are too long

View file

@ -11,7 +11,7 @@ class Api::V1::PointsController < ApiController
.order(:timestamp)
.page(params[:page])
.per(params[:per_page] || 100)
serialized_points = points.map { |point| point_serializer.new(point).call }
response.set_header('X-Current-Page', points.current_page.to_s)
@ -30,6 +30,6 @@ class Api::V1::PointsController < ApiController
private
def point_serializer
params[:slim] ? SlimPointSerializer : PointSerializer
params[:slim] == 'true' ? SlimPointSerializer : PointSerializer
end
end

View file

@ -354,10 +354,12 @@ console.log(selectedLayerName);
const timeBetweenPrev = Math.round((startPoint[4] - prevPoint[4]) / 60);
const timeBetweenNext = Math.round((endPoint[4] - nextPoint[4]) / 60);
const pointsNumber = polylineCoordinates.length;
popupContent += `
<b>Prev Route:</b> ${Math.round(distanceToPrev)}m and ${minutesToDaysHoursMinutes(timeBetweenPrev)} away<br>
<b>Next Route:</b> ${Math.round(distanceToNext)}m and ${minutesToDaysHoursMinutes(timeBetweenNext)} away<br>
<b>Points:</b> ${pointsNumber}<br>
`;
}

View file

@ -7,7 +7,8 @@ class SlimPointSerializer
def call
{
latitude: point.latitude,
id: point.id,
latitude: point.latitude,
longitude: point.longitude,
timestamp: point.timestamp
}

View file

@ -74,7 +74,7 @@ class GoogleMaps::PhoneTakeoutParser
raw_data:,
accuracy: raw_data['accuracyMeters'],
altitude: raw_data['altitudeMeters'],
velocitu: raw_data['speedMetersPerSecond']
velocity: raw_data['speedMetersPerSecond']
}
end
@ -103,7 +103,9 @@ class GoogleMaps::PhoneTakeoutParser
lat, lon = parse_coordinates(point['point'])
start_time = DateTime.parse(data_point['startTime'])
offset = point['durationMinutesOffsetFromStartTime']
timestamp = offset.nil? ? start_time.to_i : start_time + point['durationMinutesOffsetFromStartTime'].to_i
timestamp = start_time
timestamp += offset.to_i.minutes if offset.present?
point_hash(lat, lon, timestamp, data_point)
end

View file

@ -9,7 +9,7 @@
<li><%= link_to 'Points', points_url, class: "#{active_class?(points_url)}" %></li>
<li><%= link_to 'Stats', stats_url, class: "#{active_class?(stats_url)}" %></li>
<li><%= link_to 'Visits<sup>β</sup>'.html_safe, visits_url(status: :confirmed), class: "#{active_class?(visits_url)}" %></li>
<li><%= link_to 'Places<sup>β</sup>', places_url, class: "#{active_class?(places_url)}" %></li>
<li><%= link_to 'Places<sup>β</sup>'.html_safe, places_url, class: "#{active_class?(places_url)}" %></li>
<li><%= link_to 'Imports', imports_url, class: "#{active_class?(imports_url)}" %></li>
<li><%= link_to 'Exports', exports_url, class: "#{active_class?(exports_url)}" %></li>
</ul>
@ -44,7 +44,7 @@
<li><%= link_to 'Points', points_url, class: "#{active_class?(points_url)}" %></li>
<li><%= link_to 'Stats', stats_url, class: "#{active_class?(stats_url)}" %></li>
<li><%= link_to 'Visits<sup>β</sup>'.html_safe, visits_url(status: :confirmed), class: "#{active_class?(visits_url)}" %></li>
<li><%= link_to 'Places<sup>β</sup>', places_url, class: "#{active_class?(places_url)}" %></li>
<li><%= link_to 'Places<sup>β</sup>'.html_safe, places_url, class: "#{active_class?(places_url)}" %></li>
<li><%= link_to 'Imports', imports_url, class: "#{active_class?(imports_url)}" %></li>
<li><%= link_to 'Exports', exports_url, class: "#{active_class?(exports_url)}" %></li>
</ul>

View file

@ -46,13 +46,13 @@ RSpec.describe 'Api::V1::Points', type: :request do
context 'when slim version of points is requested' do
it 'renders a successful response' do
get api_v1_points_url(api_key: user.api_key, slim: true)
get api_v1_points_url(api_key: user.api_key, slim: 'true')
expect(response).to be_successful
end
it 'returns a list of points' do
get api_v1_points_url(api_key: user.api_key, slim: true)
get api_v1_points_url(api_key: user.api_key, slim: 'true')
expect(response).to have_http_status(:ok)
@ -62,7 +62,7 @@ RSpec.describe 'Api::V1::Points', type: :request do
end
it 'returns a list of points with pagination' do
get api_v1_points_url(api_key: user.api_key, slim: true, page: 2, per_page: 10)
get api_v1_points_url(api_key: user.api_key, slim: 'true', page: 2, per_page: 10)
expect(response).to have_http_status(:ok)
@ -72,7 +72,7 @@ RSpec.describe 'Api::V1::Points', type: :request do
end
it 'returns a list of points with pagination headers' do
get api_v1_points_url(api_key: user.api_key, slim: true, page: 2, per_page: 10)
get api_v1_points_url(api_key: user.api_key, slim: 'true', page: 2, per_page: 10)
expect(response).to have_http_status(:ok)
@ -81,7 +81,7 @@ RSpec.describe 'Api::V1::Points', type: :request do
end
it 'returns a list of points with slim attributes' do
get api_v1_points_url(api_key: user.api_key, slim: true)
get api_v1_points_url(api_key: user.api_key, slim: 'true')
expect(response).to have_http_status(:ok)

View file

@ -29,6 +29,18 @@ RSpec.describe GoogleMaps::PhoneTakeoutParser do
it 'creates points' do
expect { parser }.to change { Point.count }.by(8)
end
it 'creates points with correct data' do
parser
expect(Point.all[6].latitude).to eq(27.696576.to_d)
expect(Point.all[6].longitude).to eq(-97.376949.to_d)
expect(Point.all[6].timestamp).to eq(1_693_180_140)
expect(Point.last.latitude).to eq(27.709617.to_d)
expect(Point.last.longitude).to eq(-97.375988.to_d)
expect(Point.last.timestamp).to eq(1_693_180_320)
end
end
end
end