From 50798b5bb1d58049ed1bb58d49417e5303ff0d3e Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 8 Jul 2024 23:56:08 +0200 Subject: [PATCH] Fix overland batch payload processing --- CHANGELOG.md | 4 ++++ app/services/overland/params.rb | 4 +++- spec/fixtures/files/overland/geodata.json | 11 +++++++++++ spec/services/overland/params_spec.rb | 8 +++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ff8fbb..977fd815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `MAP_CENTER` env var from the `docker-compose.yml` file. This variable was used to set the default center of the map, but it is not needed anymore, as the map center is now hardcoded in the application. ⚠️ Feel free to remove this variable from your `docker-compose.yml` file. ⚠️ +### Fixed + +- Fixed a bug where Overland batch payload was not being processed due to missing coordinates in the payload. Now, if the coordinates are missing, the single point is skipped and the rest are being processed. + --- ## [0.8.5] — 2024-07-08 diff --git a/app/services/overland/params.rb b/app/services/overland/params.rb index f003278b..b712ffce 100644 --- a/app/services/overland/params.rb +++ b/app/services/overland/params.rb @@ -10,6 +10,8 @@ class Overland::Params def call points.map do |point| + next if point[:geometry].nil? || point.dig(:properties, :timestamp).nil? + { latitude: point[:geometry][:coordinates][1], longitude: point[:geometry][:coordinates][0], @@ -24,7 +26,7 @@ class Overland::Params vertical_accuracy: point[:properties][:vertical_accuracy], raw_data: point } - end + end.compact end private diff --git a/spec/fixtures/files/overland/geodata.json b/spec/fixtures/files/overland/geodata.json index 4d81f298..0767c6ad 100644 --- a/spec/fixtures/files/overland/geodata.json +++ b/spec/fixtures/files/overland/geodata.json @@ -26,6 +26,17 @@ "battery_state": "charging", "battery_level": 0.89 } + }, + { + "type": "Feature", + "properties": { + "wifi": "", + "timestamp": "2024-07-07T17:46:39Z", + "device_id": "iphone", + "battery_state": "unplugged", + "battery_level": 0.55, + "action": "will_terminate" + } } ] } diff --git a/spec/services/overland/params_spec.rb b/spec/services/overland/params_spec.rb index f0390ad6..8ba3fd86 100644 --- a/spec/services/overland/params_spec.rb +++ b/spec/services/overland/params_spec.rb @@ -1,7 +1,10 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Overland::Params do describe '#call' do + # This file contains one valid point and one invalid point w/out coordinates let(:file_path) { 'spec/fixtures/files/overland/geodata.json' } let(:file) { File.open(file_path) } let(:json) { JSON.parse(file.read) } @@ -47,6 +50,9 @@ RSpec.describe Overland::Params do it 'returns a hash with the correct values' do expect(params[0]).to eq(expected_json) end + + it 'returns the correct number of points' do + expect(params.size).to eq(1) + end end end -