From 5f18a3051d3d9c257049eedb4fba4474ffc5c39d Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 25 May 2024 13:36:15 +0200 Subject: [PATCH] Fix interface inconsistencies --- app/helpers/application_helper.rb | 4 ++-- app/jobs/import_job.rb | 2 +- app/services/create_stats.rb | 7 ++++--- app/services/google_maps/semantic_history_parser.rb | 8 +++++--- app/services/own_tracks/export_parser.rb | 8 +++++--- app/views/shared/_right_sidebar.html.erb | 4 ++-- spec/services/create_stats_spec.rb | 13 +++++++------ spec/services/own_tracks/export_parser_spec.rb | 2 +- swagger/v1/swagger.yaml | 2 +- 9 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 52256b5f..a32fb095 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -53,8 +53,8 @@ module ApplicationHelper DateTime.new(year, month).past? end - def points_exist?(year, month) - Point.where( + def points_exist?(year, month, user) + user.tracked_points.where( timestamp: DateTime.new(year, month).beginning_of_month..DateTime.new(year, month).end_of_month ).exists? end diff --git a/app/jobs/import_job.rb b/app/jobs/import_job.rb index 49e7492a..7c1a9282 100644 --- a/app/jobs/import_job.rb +++ b/app/jobs/import_job.rb @@ -7,7 +7,7 @@ class ImportJob < ApplicationJob user = User.find(user_id) import = user.imports.find(import_id) - result = parser(import.source).new(import).call + result = parser(import.source).new(import, user_id).call import.update( raw_points: result[:raw_points], doubles: result[:doubles], processed: result[:processed] diff --git a/app/services/create_stats.rb b/app/services/create_stats.rb index 4d9c2e8a..24ecb3f2 100644 --- a/app/services/create_stats.rb +++ b/app/services/create_stats.rb @@ -16,7 +16,7 @@ class CreateStats beginning_of_month_timestamp = DateTime.new(year, month).beginning_of_month.to_i end_of_month_timestamp = DateTime.new(year, month).end_of_month.to_i - points = points(beginning_of_month_timestamp, end_of_month_timestamp) + points = points(user, beginning_of_month_timestamp, end_of_month_timestamp) next if points.empty? stat = Stat.find_or_initialize_by(year:, month:, user:) @@ -31,8 +31,9 @@ class CreateStats private - def points(beginning_of_month_timestamp, end_of_month_timestamp) - Point + def points(user, beginning_of_month_timestamp, end_of_month_timestamp) + user + .tracked_points .without_raw_data .where(timestamp: beginning_of_month_timestamp..end_of_month_timestamp) .order(:timestamp) diff --git a/app/services/google_maps/semantic_history_parser.rb b/app/services/google_maps/semantic_history_parser.rb index eb4ecb58..6129cd4a 100644 --- a/app/services/google_maps/semantic_history_parser.rb +++ b/app/services/google_maps/semantic_history_parser.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true class GoogleMaps::SemanticHistoryParser - attr_reader :import + attr_reader :import, :user_id - def initialize(import) + def initialize(import, user_id) @import = import + @user_id = user_id end def call @@ -22,7 +23,8 @@ class GoogleMaps::SemanticHistoryParser raw_data: point_data[:raw_data], topic: 'Google Maps Timeline Export', tracker_id: 'google-maps-timeline-export', - import_id: import.id + import_id: import.id, + user_id: ) points += 1 diff --git a/app/services/own_tracks/export_parser.rb b/app/services/own_tracks/export_parser.rb index 9e03bb74..c9b64029 100644 --- a/app/services/own_tracks/export_parser.rb +++ b/app/services/own_tracks/export_parser.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true class OwnTracks::ExportParser - attr_reader :import, :json + attr_reader :import, :json, :user_id - def initialize(import) + def initialize(import, user_id) @import = import @json = import.raw_data + @user_id = user_id end def call @@ -23,7 +24,8 @@ class OwnTracks::ExportParser raw_data: point_data[:raw_data], topic: point_data[:topic], tracker_id: point_data[:tracker_id], - import_id: import.id + import_id: import.id, + user_id: ) points += 1 diff --git a/app/views/shared/_right_sidebar.html.erb b/app/views/shared/_right_sidebar.html.erb index 9c599d00..e5d27f07 100644 --- a/app/views/shared/_right_sidebar.html.erb +++ b/app/views/shared/_right_sidebar.html.erb @@ -4,7 +4,7 @@