Skip to content

Commit

Permalink
update fuzz location accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Jun 27, 2024
1 parent 78a96f8 commit 56c967f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/models/device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56c967f

Please sign in to comment.