Skip to content

Commit

Permalink
rethink device location fuzzing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Jun 27, 2024
1 parent d08e953 commit d1eaeed
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ def forwarding_token

def truncate_and_fuzz_location!
if latitude && longitude
decimal_places = self.precise_location ? 5 : 2
lat_fuzz = self.precise_location ? 0.0 : (Random.rand * 1/10.0**decimal_places).truncate(5)
long_fuzz = self.precise_location ? 0.0 : (Random.rand * 1/10.0**decimal_places).truncate(5)
self.latitude = self.latitude.truncate(decimal_places) + lat_fuzz
self.longitude = self.longitude.truncate(decimal_places) + long_fuzz
fuzz_decimal_places = 2
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)
self.latitude = (self.latitude + lat_fuzz).truncate(total_decimal_places)
self.longitude = (self.longitude + long_fuzz).truncate(total_decimal_places)
end
end

Expand Down

0 comments on commit d1eaeed

Please sign in to comment.