From 56c967f7ab70f3675f79db722754c917c914ee8d Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Thu, 27 Jun 2024 18:48:48 +0200 Subject: [PATCH] update fuzz location accuracy --- app/models/device.rb | 2 +- spec/models/device_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/device.rb b/app/models/device.rb index 0cccd9b6..bcfdb98b 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -291,7 +291,7 @@ def forwarding_token def truncate_and_fuzz_location! if latitude && longitude - fuzz_decimal_places = 2 + fuzz_decimal_places = 3 total_decimal_places = 5 lat_fuzz = self.precise_location ? 0.0 : (Random.rand * 1/10.0**fuzz_decimal_places) long_fuzz = self.precise_location ? 0.0 : (Random.rand * 1/10.0**fuzz_decimal_places) diff --git a/spec/models/device_spec.rb b/spec/models/device_spec.rb index 602fa726..7e865a50 100644 --- a/spec/models/device_spec.rb +++ b/spec/models/device_spec.rb @@ -226,13 +226,13 @@ } - it "truncates the location to 2 decimal places and adds 3 extra dp of randomness" do + it "truncates the location to 3 decimal places and adds 2 extra dp of randomness" do device.update(latitude: 0.12345, longitude: 10.12345) device.save expect(device.latitude).not_to eq(0.12345) expect(device.longitude).not_to eq(10.12345) - expect((device.latitude - 0.12345).abs.truncate(5)).to be <= 0.01 - expect((device.longitude - 10.12345).abs.truncate(5)).to be <= 0.01 + expect((device.latitude - 0.12345).abs.truncate(5)).to be <= 0.001 + expect((device.longitude - 10.12345).abs.truncate(5)).to be <= 0.001 end end end